Rumah > pembangunan bahagian belakang > masalah PHP > php如何实现流程管理?

php如何实现流程管理?

coldplay.xixi
Lepaskan: 2023-03-02 16:08:02
asal
2789 orang telah melayarinya

php实现流程管理的方法:首先新建流程页面,并建好节点;然后点击选择节点人员可以从数据库调所有人员名单;最后做一个登陆用户,提交请假流程的所有步骤即可。

php如何实现流程管理?

php实现流程管理的方法:

我们首先做一个新建流程页面,先把节点做好

xinjian.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="../dist/js/jquery-1.11.2.min.js"></script>
</head>
<body>
<h1>新建流程</h1>
<div>
请选择节点人员:
<select id="user">
    <?php
    session_start();
    include("../fengzhuang/DBDA.class.php");
    $db = new DBDA();
    
    $sql = "select * from lc_users";
    $arr = $db->Query($sql);
    foreach($arr as $v)
    {
        echo "<option value=&#39;{$v[0]}&#39;>{$v[2]}</option>";
    }
    ?>
</select>
<input type="button" value="添加节点" id="add" />
</div>
<br />
<div>
    <?php
    if(!empty($_SESSION["user"]))
    {
        $attr = $_SESSION["user"];
        foreach($attr as $k=>$v)
        {
            $sname = "select name from lc_users where uid=&#39;{$v}&#39;";
            $name = $db->StrQuery($sname);
            echo "<div>{$k}--{$name}--<input type=&#39;button&#39; value=&#39;删除&#39; key=&#39;{$k}&#39; class=&#39;del&#39; /></div>";
        }
    }
    ?>
</div>
<br />
<div>请输入流程名称:<input type="text" id="name" /></div>
<br />
<input type="button" value="保存" id="btn" />
</body>
<script type="text/javascript">
//添加节点按钮加点击
$("#add").click(function(){
        var uid = $("#user").val();
        $.ajax({
            url:"chuli.php",
            data:{uid:uid,type:0},
            type:"POST",
            dataType:"TEXT",
            success: function(data){
                    window.location.href="xinjian.php";
                }
            });
    })
    
//给删除按钮加点击
$(".del").click(function(){
        var key = $(this).attr("key");
        $.ajax({
            url:"chuli.php",
            data:{key:key,type:1},
            type:"POST",
            dataType:"TEXT",
            success:function(data){
                window.location.href="xinjian.php";
                }
            });
    })
//给保存按钮加点击
$("#btn").click(function(){
        var name = $("#name").val();
        $.ajax({
            url:"chuli.php",
            data:{name:name,type:2},
            type:"POST",
            dataType:"TEXT",
            success:function(data){
                    alert("保存成功!");
                }
            });
    })
</script>
</html>
Salin selepas log masuk

chuli.php

<?php
session_start();
include("../fengzhuang/DBDA.class.php");
$db = new DBDA();
$type = $_POST["type"];
switch($type)
{
    case 0:
        $uid = $_POST["uid"];
        if(empty($_SESSION["user"]))
        {
            $arr = array($uid);
            $_SESSION["user"] = $arr;
        }
        else
        {
            $arr = $_SESSION["user"];
            array_push($arr,$uid);
            $_SESSION["user"] = $arr;
        }
        break;
        
    case 1:
        $key = $_POST["key"];
        $arr = $_SESSION["user"];
        unset($arr[$key]); //删除
        $arr = array_values($arr); //重新索引
        $_SESSION["user"] = $arr;
        break;
        
    case 2:
        $name = $_POST["name"];
        $code = time();
        //添加流程
        $sql = "insert into lc_liucheng values(&#39;{$code}&#39;,&#39;{$name}&#39;)";
        $db->Query($sql,0);
        //添加流程节点
        $arr = $_SESSION["user"];
        foreach($arr as $k=>$v)
        {
            $sql = "insert into lc_flowpath values(&#39;&#39;,&#39;{$code}&#39;,&#39;{$v}&#39;,&#39;{$k}&#39;)";
            $db->Query($sql,0);
        }
        break;
        
    case 3: //用户发起流程
        $code = $_POST["code"];
        $nr = $_POST["content"];
        $uid = $_SESSION["uid"];
        $time = date("Y-m-d H:i:s");
        $sql = "insert into lc_userflow values(&#39;&#39;,&#39;{$code}&#39;,&#39;{$uid}&#39;,&#39;{$nr}&#39;,0,&#39;{$time}&#39;,0)";
        $db->Query($sql,0);
        break;
        
}
Salin selepas log masuk

完成的效果,如图:

8591158a174dcf792a54ea903da2e4e.png

点击选择节点人员可以从数据库调所有人员名单,现在把李四,马七和张三放入流程中,做一个请假流程:

095664fea6aee238473a4e4aef50eab.png

点击保存,存到数据库:

b36fa43c9b2b42df331d951e0489cbb.png

49412b1d9b7e6b1ba8874420537fc0a.png

注意:Code必须用varchar,不能用time,因为在上面用了时间戳

现在我们在做一个登陆用户,提交请假流程的所有步骤:

weilogin.php 一个伪账户

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<?php
session_start();
$_SESSION["uid"] = "zhangsan";
?>
</body>
</html>
Salin selepas log masuk

faqi.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title><br />
<script src="../dist/js/jquery-1.11.2.min.js"></script>
</head>
<body>
<h1>发起流程</h1>
<div>
请选择发起的流程:
    <select id="liucheng">
        <?php
        session_start();
        include("../fengzhuang/DBDA.class.php");
        $db = new DBDA();
        $sql = "select * from lc_liucheng";
        $arr = $db->Query($sql);
        foreach($arr as $v)
        {
            echo "<option value=&#39;{$v[0]}&#39;>{$v[1]}</option>";
        }
        ?>
    </select>
</div>
<br />
<div>
请输入内容:
    <textarea id="nr"></textarea>
</div>
<br />
<input type="button" value="发起" id="btn" />
</body>
<script type="text/javascript">
$("#btn").click(function(){
        var code = $("#liucheng").val();
        var content = $("#nr").val();
        
        $.ajax({
            url:"chuli.php",
            data:{code:code,content:content,type:3},
            type:"POST",
            dataType:"TEXT",
            success: function(data){
                alert("发起成功!");
                }            
            });
    })
</script>
</html>
Salin selepas log masuk

shenhe.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h1>审核页面</h1>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>流程代号</td>
        <td>发起者</td>
        <td>发起内容</td>
        <td>是否结束</td>
        <td>发起时间</td>
        <td>操作</td> 
    </tr>
    <?php
    session_start();
    include("../fengzhuang/DBDA.class.php");
    $db = new DBDA();
    $uid = $_SESSION["uid"];
    echo $uid;
    //查找登录者参与的所有流程
    $sql = "select * from lc_userflow where code in(select code from lc_flowpath where uids=&#39;{$uid}&#39;)";
    $arr = $db->Query($sql);
    
    //显示
    foreach($arr as $v)
    {
        //判断该流程走到登录者
        $lcdh = $v[1]; //流程代号
        $towhere = $v[6];//流程走到哪
        $sql = "select orders from lc_flowpath where code=&#39;{$lcdh}&#39; and uids=&#39;{$uid}&#39;";
        $order = $db->StrQuery($sql);//该人员在流程中的次序
        
        if($towhere>=$order)
        {
            $caozuo = "";
            if($towhere==$order)
            {
                $caozuo="<a href=&#39;tongguo.php?code={$v[0]}&#39;>通过</a>";
            }
            else
            {
                $caozuo="<span style=&#39;background-color:green;color:white&#39;>已通过</span>";
            }
            echo "<tr>
        <td>{$v[1]}</td>
        <td>{$v[2]}</td>
        <td>{$v[3]}</td>
        <td>{$v[4]}</td>
        <td>{$v[5]}</td>
        <td>{$caozuo}</td> 
    </tr>";
        }
        
    }
    
    ?>
</table>
</body>
</html>
Salin selepas log masuk

tongguo.php

<?php
session_start();
include("../fengzhuang/DBDA.class.php");
$db = new DBDA();
//流程往下走
$code = $_GET["code"];
$sql = "update lc_userflow set towhere=towhere+1 where ids=&#39;{$code}&#39;";
$db->Query($sql,0);
//判断流程是否结束
$sql = "select * from lc_userflow where ids=&#39;{$code}&#39;";
$arr = $db->Query($sql);
$lcdh = $arr[0][1]; //流程代号
$tw = $arr[0][6]; //流程走到哪
$sql = "select count(*) from lc_flowpath where code=&#39;{$lcdh}&#39;";
$count = $db->StrQuery($sql); //该流程节点人数
if($tw>=$count)
{
    $sql = "update lc_userflow set isok=1 where ids=&#39;{$code}&#39;";
    $db->Query($sql,0);
}
header("location:shenhe.php");
Salin selepas log masuk

 1aa94c4945dc822fcd98d43a1ae34e3.png

张三发个请假流程,

c32b46ec5914e2a832bf6e59e8fea10.png

李四的页面:

8eb19cfec8765f7679241183d56a664.png

点击通过后

6fcaee84b50456156f66c61d19c3d3e.png

数据库:towhere变成1了

df6e43e581c7485067fbe956bc022cc.png

接着该马七:

5421dec468364c248191173db6f6c99.png

然后是张三:

3d1f0ee96e242e97757ea4eee033ad6.png

数据库:isok变成1了

792d12a46aaf96e780f5b11030f9487.png

相关学习推荐:PHP编程从入门到精通

Atas ialah kandungan terperinci php如何实现流程管理?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan