正文  软件开发 > PHP编程技术 >

PHP实现流程管理功能,php实现流程管理

PHP实现流程管理功能,php实现流程管理核心逻辑:流程管理,在各种系统中扮演很重要的地位,可以把设定好的流程放入系统中,规定好几个节点,只要所有节点都通过,就可以通过。 建立四张数据库表:...

PHP实现流程管理功能,php实现流程管理

核心逻辑:流程管理,在各种系统中扮演很重要的地位,可以把设定好的流程放入系统中,规定好几个节点,只要所有节点都通过,就可以通过。

建立四张数据库表:

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

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>    
        <script src="bootstrap/js/jquery-1.11.2.min.js"></script>    
    </head>
    <body>
        <h2>管理员新建流程</h2>
        <div>请选择人员:
            <select id="users" name="users">
            <?php
                session_start();
                require_once "./DBDA.class.php";
                $db = new DBDA();
                $sql = "select * from users";
                $arr = $db->query($sql,0);
                foreach($arr as $v){
                    echo "<option value=‘{$v[0]}‘>{$v[2]}</option>";
                }
            ?>
            </select>
            <input type="button" value="添加" id="add" />
        </div>        
        <br />
        <div>
            <?php
            if(empty($_SESSION["jd"])){
                echo "还未添加节点人员!";
            }else{
                $arr = $_SESSION["jd"];//数组形式存在
                foreach($arr as $k=>$v){//遍历索引(顺序)和名称
                    $sql = "select name from users where uid=‘{$v}‘";
                    $name = $db->StrQuery($sql,0);//查一个(一维数组)
                    echo "<div>{$k}--{$name}--<input type=‘button‘ value=‘删除‘ class=‘del‘ code=‘{$k}‘ /></div>";     
                                                                                            //根据索引删除相应节点人员
                }
            }    
            ?>
        </div>
        <br />
        <div>请输入流程名称:
        <input type="text" id="name" />
        </div>
        <br />
        <input type="button" value="新建" id="addbtn" />
    </body>
    <script>      
      //添加节点按钮加点击 $("#add").click(function(){ var uid = $("#users").val(); $.ajax({ url:"flowchuli.php", type:"POST", data:{uid:uid,type:0}, dataType:"TEXT", success:function(){ window.location.href = "flow.php"; } }); })
      //给删除按钮加点击 $(".del").click(function(){ var k = $(this).attr("code");//获取索引属性 $.ajax({ url:"flowchuli.php", type:"POST", data:{k:k,type:1}, dataType:"TEXT", success:function(){ window.location.href = "flow.php"; } }); }) //给保存按钮加点击 $("#addbtn").click(function(){ var name = $("#name").val(); $.ajax({ url:"flowchuli.php", type:"POST", data:{name:name,type:2}, dataType:"TEXT", success:function(){ alert("添加成功!"); } }); }) </script> </html>

2.做新建流程页面的处理页面flowchuli.php

<?php
session_start();
require_once "./DBDA.class.php";
$db = new DBDA();
$type = $_POST["type"];
switch($type){
    case 0:
        $uid = $_POST["uid"];
        if(empty($_SESSION["jd"])){//暂存节点
            $arr = array($uid);//新造数组
            $_SESSION["jd"] = $arr;//存入session
        }else{
            $arr = $_SESSION["jd"];//取数组
            $arr[] = $uid;//追加变量到数组
            $_SESSION["jd"] = $arr;
        }
        break;
    case 1:
        $k = $_POST["k"];
        $arr = $_SESSION["jd"];
        unset($arr[$k]);
        $arr = array_values($arr);//重新对数组进行排序,有返回值接收
        $_SESSION["jd"] = $arr;
        break;
    case 2:    
        $name = $_POST["name"];
        $code = time();//自动生成
        $sql = "insert into flow values(‘{$code}‘,‘{$name}‘)";//流程表
        $db->query($sql);
        //流程节点表
        $arr = $_SESSION["jd"];
        foreach($arr as $k=>$v){
            $sql = "insert into flowpath values(0,‘{$code}‘,‘{$v}‘,{$k})";
            $db->query($sql);
        }        
        break;
}

效果如图:

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

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

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

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="bootstrap/js/jquery-1.11.2.min.js"></script>
        <script src="bootstrap/js/bootstrap.min.js"></script>
        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    </head>
    <style>
        .title{
            margin-left: 600px;
            margin-top: 150px;
        }
        .quanju{
            margin-left: 450px;
            margin-top: -180px;
        }
        .name,.pwd{
            max-width: 120px;
        }
        .yangshi1{
            margin-top: 200px;
        }
    </style>
    <body>        
<form class="form-horizontal" role="form">
    <h3 class="title">用户登录</h3>
    <div class="quanju">
            <div class="form-group yangshi1">
                <label for="firstname" class="col-sm-2 control-label">用户名:</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control name" id="uid" placeholder="请输入用户名">
                </div>
            </div>
            <div class="form-group yangshi2">
                <label for="lastname" class="col-sm-2 control-label">密码:</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control pwd" id="pwd" placeholder="请输入密码">
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <div class="checkbox">
                        <label>
                        <input type="checkbox">
                        保存密码 </label>
                        <label>
                        <input type="checkbox">
                        下次自动登录 </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" id="login" class="btn btn-warning" value="登录" >
                    登录
                    </button>
                    
                </div>
            </div>
        </div>    
    </form>        
    </body>
    <script>
      //登录按钮的点击事件 $("#login").click(function(){ var uid = $("#uid").val(); var pwd = $("#pwd").val(); $.ajax({ type:"post", url:"flowloginchuli.php", data:{uid:uid,pwd:pwd}, dataType:"TEXT", success:function(data){ if(data.trim()=="OK"){ window.location.href="flowmain.php"; }else{ alert("用户名或密码有误!"); } } }); }) </script> </html>

4.登录后跳转的主页面flowmain.php

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h2>主页面</h2> <a href="flowfq.php">发起流程</a> <a href="flowsh.php">审核流程</a> </body> </html>

5.发起流程页面flow.php

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="bootstrap/js/jquery-1.11.2.min.js"></script>        
    </head>
    <body>
        <h2>发起流程</h2>
        <form action="flowfqchuli.php" method="post">
            请选择流程:
            <select name="flow">
                <?php
                require_once "./DBDA.class.php";
                $db = new DBDA();
                $sql = "select * from flow";
                $arr = $db->query($sql,0);
                foreach($arr as $v){
                    echo "<option value=‘{$v[0]}‘>{$v[1]}</option>";
                }
                ?>
            </select>
            <br />
            <br />
            请输入内容:
            <textarea name="content"></textarea>
            <br />
            <br />
            <input type="submit" value="确定" />
        </form>        
    </body>
</html>

6.做发起流程的处理页面flowfq.php

<?php
session_start();
require_once "./DBDA.class.php";
$db = new DBDA();

$code = $_POST["flow"];
$uid = $_SESSION["uid"];
$content = $_POST["content"];
$time = date("Y-m-d H:i:s");
$sql = "insert into userflow values(0,‘{$code}‘,‘{$uid}‘,‘{$content}‘,0,‘{$time}‘,0)";
$db->query($sql);
header("location:flowmain.php");

7.审核页面flowsh.php

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>    
        <script src="bootstrap/js/jquery-1.11.2.min.js"></script>
        <script src="bootstrap/js/bootstrap.min.js"></script>
        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>    
    </head>
    <body>
    <div><h2>审核页面</h2>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>流程代号</th>
                    <th>发起人</th>
                    <th>发起内容</th>
                    <th>通过状态</th>
                    <th>发起时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <?php
                session_start();
                $uid = $_SESSION["uid"];
                require_once "./DBDA.class.php";
                $db = new DBDA();
                //相关子查询(用到父查询的数据)(父查询卡在某一位置)
                $sql = "select * from userflow a where towhere>=(select b.order from flowpath b where b.code=a.code and b.uid=‘{$uid}‘)";    
                $arr = $db->query($sql,0);    
                foreach($arr as $v){
                    //$v[6];//流程走到的位置towhere
                    //$v[1];//利用代号和session中存的name查询order
                    $sql = "select order from flowpath where code=‘{$v[1]}‘ and uid=‘{$uid}‘";
                    $order = $db->StrQuery($sql,0);//该人员在流程中的次序
                    $str = "";
                    if($v[6]==$order){                            //传主键值
                        $str = "<a href=‘flowtgchuli.php?ids={$v[0]}‘>通过</a>";
                    }else{
                        $str = "<span style=‘color:green‘>已通过</span>";
                    }
                    echo "<tr>
                    <th>{$v[1]}</th>
                    <th>{$v[2]}</th>
                    <th>{$v[3]}</th>
                    <th>{$v[4]}</th>
                    <th>{$v[5]}</th>
                    <th>{$str}</th>
                </tr>";
                }        
                ?>                                
            </tbody>
        </table>
    </div>    
    </body>
</html>

8.做审核页面的处理页面flowshchuli.php

<?php
session_start();
$uid = $_SESSION["uid"];
require_once "./DBDA.class.php";
$db = new DBDA();

$ids = $_GET["ids"];
$sql = "update userflow set towhere=towhere+1 where ids=‘{$ids}‘";
$db->query($sql);
//判断;流程是否结束(使用相关子查询)
$swc = "update userflow a set isok=1 where ids=‘{$ids}‘ towhere>=(select count(*) from flowpath b where b.code=a.code)";
header("location:flowsh.php");

流程效果如图:

李四的页面:

点击通过后:

数据库:towhere变成1后结束流程

接着该马七:

然后是张三:

数据库:isok变成1后结束流程

http://www.bkjia.com/PHPjc/1227229.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1227229.htmlTechArticlePHP实现流程管理功能,php实现流程管理 核心逻辑:流程管理,在各种系统中扮演很重要的地位,可以把设定好的流程放入系统中,规定好几...