Jelajahi Sumber

流程及节点

wufeng 2 tahun lalu
induk
melakukan
6a897bc79f

+ 79 - 0
app/admin/controller/ActionProcess.php

@@ -0,0 +1,79 @@
+<?php
+
+namespace app\admin\controller;
+
+//流程节点
+use think\facade\Db;
+use think\facade\Validate;
+
+class ActionProcess extends Base
+{
+
+    //获取流程节点列表
+    public function getList()
+    {
+
+        $param = $this->request->filter('trim')->only(['order_type', 'page' => 1, 'size' => 15], 'post');
+
+        $val = Validate::rule([
+            'order_type|所属流程编码' => 'require',
+            'page|页码' => 'require|number|gt:0',
+            'size|每页显示的页码' => 'require|number|gt:0',
+        ]);
+
+        if (!$val->check($param)) return error_show(1005, $val->getError());
+
+        $where = [];
+        if ($param['order_type'] != '') $where[] = ['order_type', '=', $param['order_type']];
+
+        $count = Db::name('action_process')
+            ->where($where)
+            ->count('id');
+
+        $list = Db::name('action_process')
+            ->field('id,status_name,order_process,status,action_type,operation_type,next_action_ids,creater,addtime')
+            ->where($where)
+            ->order('id', 'desc')
+            ->page($param['page'], $param['size'])
+            ->select()
+            ->toArray();
+
+        $all_next_ids = implode(',', array_column($list, 'next_action_ids'));
+
+        //处理下一个节点的名称
+        $child = Db::name('action_process')
+            ->whereIn('id', $all_next_ids)
+            ->column('status_name', 'id');
+
+        foreach ($list as &$item) {
+            if ($item['next_action_ids']) {
+                $next_action_ids = explode(',', $item['next_action_ids']);
+                foreach ($next_action_ids as $next_action_id) {
+                    if (isset($child[$next_action_id])) $item['next_actions'][] = $child[$next_action_id];
+                }
+            } else $item['next_actions'] = [];
+        }
+
+        return app_show(0, '获取成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //新增流程节点
+    public function add(){
+
+        $param = $this->request->filter('trim')->only(['','','',''],'post');
+
+        $val=Validate::rule();
+
+        if(!$val->check([])) return error_show(1005,$val->getError());
+
+        $user = GetUserInfo($param['token']);
+
+        $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
+        $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
+        $date = date('Y-m-d H:i:s');
+
+    }
+
+
+}

+ 142 - 27
app/admin/controller/Process.php

@@ -2,18 +2,21 @@
 
 
 namespace app\admin\controller;
+
 use app\BaseController;
 use think\App;
 use think\facade\Db;
+use think\facade\Validate;
+use app\admin\model\Process as ProcessModel;
 
 //流程单
 class Process extends Base
 {
 
- public function __construct(App $app)
- {
-     parent::__construct($app);
- }
+    public function __construct(App $app)
+    {
+        parent::__construct($app);
+    }
 
     /**
      * @return \think\response\Json|void
@@ -21,16 +24,17 @@ class Process extends Base
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-  public function list(){
-     $page =isset($this->post['page']) &&$this->post['page']!="" ? intval($this->post['page']) : 1;
-     $size =isset($this->post['size']) &&$this->post['size']!="" ? intval($this->post['size']) : 10;
+    public function list()
+    {
+        $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
+        $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
 
-     $count = Db::name("process")->where('is_del',0)->count();
-     $total = ceil($count/$size);
-     $page = $page>$total ? $total:$page;
-      $list = Db::name("process")->where('is_del', 0)->page($page, $size)->select();
-     return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
-  }
+        $count = Db::name("process")->where('is_del', 0)->count();
+        $total = ceil($count / $size);
+        $page = $page > $total ? $total : $page;
+        $list = Db::name("process")->where('is_del', 0)->page($page, $size)->select();
+        return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
+    }
 
     /**
      * @return \think\response\Json|void
@@ -38,19 +42,20 @@ class Process extends Base
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-  public  function info(){
-    $id =isset($this->post['id']) &&$this->post['id']!="" ? intval($this->post['id']) : "";
-    if($id==""){
-        return error_show(1004,"参数id 不能为空");
-    }
-    $info = Db::name("process")->where(['id'=>$id,"is_del"=>0])->find();
-    if(empty($info)){
-        return error_show(1004,"流程信息未找到");
+    public function info()
+    {
+        $id = isset($this->post['id']) && $this->post['id'] != "" ? intval($this->post['id']) : "";
+        if ($id == "") {
+            return error_show(1004, "参数id 不能为空");
+        }
+        $info = Db::name("process")->where(['id' => $id, "is_del" => 0])->find();
+        if (empty($info)) {
+            return error_show(1004, "流程信息未找到");
+        }
+        $list = Db::name("action_process")->where(["pid" => $id, "is_del" => 0])->order("weight,id")->select();
+        $info['item'] = empty($list) ? [] : $list;
+        return app_show(0, "获取成功", $info);
     }
-    $list=Db::name("action_process")->where(["pid"=>$id,"is_del"=>0])->order("weight,id")->select();
-    $info['item'] = empty($list) ? []:$list;
-    return app_show(0,"获取成功",$info);
-  }
 
     /**
      * @return \think\response\Json|void
@@ -80,8 +85,8 @@ class Process extends Base
             ->where(["order_type" => $process_type])
             ->whereIn('action_process', $order_process_s)
             ->field('id,action_uid,action_name,addtime,action_process,order_type');
-        if(is_numeric($orderCode))  $rs->where('order_id',$orderCode);
-        else $rs->where('order_code',$orderCode);
+        if (is_numeric($orderCode)) $rs->where('order_id', $orderCode);
+        else $rs->where('order_code', $orderCode);
 
         $node = $rs
             ->select()
@@ -113,4 +118,114 @@ class Process extends Base
         return app_show(0, "获取成功", $node);
     }
 
+
+    //获取流程列表
+    public function getList()
+    {
+        $param = $this->request->filter('trim')->only(['status' => '', 'process_name' => '', 'creater' => '', 'addtime_start' => '', 'addtime_end' => '', 'page' => 1, 'size' => 15], 'post');
+
+        $where = [['is_del', '=', ProcessModel::$is_del_normal]];
+        if ($param['status'] != '') $where[] = ['status', '=', $param['status']];
+        if ($param['process_name'] != '') $where[] = ['process_name', 'like', '%' . $param['process_name'] . '%'];
+        if ($param['creater'] != '') $where[] = ['creater', 'like', '%' . $param['creater'] . '%'];
+        if ($param['addtime_start'] != '' && $param['addtime_end'] != '') $where[] = ['addtime', 'between', [$param['addtime_start'], $param['addtime_end'] . ' 23:59:59']];
+
+        $count = Db::name('process')
+            ->where($where)
+            ->count('id');
+
+        $list = ProcessModel::field('id,process_name,process_type,status,creater,addtime')
+            ->where($where)
+            ->order('id', 'desc')
+            ->page($param['page'], $param['size'])
+            ->select()
+            ->toArray();
+
+        return app_show(0, '获取成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //增加流程
+    public function add()
+    {
+        $param = $this->request->filter('trim')->only(['token', 'process_name', 'process_type', 'remark' => ''], 'post');
+
+        $val = Validate::rule([
+            'token' => 'require',
+            'process_name|流程名称' => 'require|max:255',
+            'process_type|流程值' => 'require|max:255|checkProcessType:',
+        ]);
+
+        $val->extend('checkProcessType', function ($val) {
+            return ProcessModel::where(['process_type' => $val, 'is_del' => ProcessModel::$is_del_normal])->field('id')->findOrEmpty()->isEmpty() ? true : '该流程值已存在';
+        });
+
+        if (!$val->check($param)) return error_show(1005, $val->getError());
+
+        $user = GetUserInfo($param['token']);
+
+        $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
+        $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
+        $date = date('Y-m-d H:i:s');
+
+        return ProcessModel::create(array_merge($param, [
+            'is_del' => ProcessModel::$is_del_normal,
+            'status' => ProcessModel::$status_normal,
+            'createrid' => $uid,
+            'creater' => $uname,
+            'addtime' => $date,
+            'updaterid' => $uid,
+            'updater' => $uname,
+            'updatetime' => $date,
+        ]))->save() ? app_show(0, '新增流程成功') : error_show(1005, '新增流程失败');
+
+    }
+
+    //读取
+    public function read(){
+        $id=$this->request->filter('trim')->post('id/d',0);
+
+        $res = ProcessModel::field('id,process_name,process_type')
+            ->where(['id'=>$id,'is_del'=>ProcessModel::$is_del_normal])
+            ->findOrEmpty()
+            ->toArray();
+
+        return app_show(0,'获取详情成功',$res);
+    }
+
+    //修改流程
+    public function update()
+    {
+        $param = $this->request->filter('trim')->only(['token', 'id', 'process_name', 'process_type', 'status', 'is_del', 'remark'], 'post');
+
+        $val = Validate::rule([
+            'token' => 'require',
+            'id|ID' => 'require|number|gt:0',
+            'process_name|流程名称' => 'max:255',
+            'process_type|流程值' => 'max:255|checkProcessType:',
+            'status|状态' => 'number|in:'.ProcessModel::$status_normal.','.ProcessModel::$status_disable,
+            'is_del|是否删除' => 'number|eq:'.ProcessModel::$is_deleted,
+        ]);
+
+        $val->extend('checkProcessType', function ($val, $rule, $data) {
+            return ProcessModel::where(['process_type' => $val, 'is_del' => ProcessModel::$is_del_normal])->where('id', '<>', $data['id'])->field('id')->findOrEmpty()->isEmpty() ? true : '该流程值已存在';
+        });
+
+        if (!$val->check($param)) return error_show(1005, $val->getError());
+
+        $user = GetUserInfo($param['token']);
+
+        $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
+        $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
+        $date = date('Y-m-d H:i:s');
+
+        return ProcessModel::where(['id' => $param['id'], 'is_del' => ProcessModel::$is_del_normal])->strict(false)->save(array_merge($param, [
+            'updaterid' => $uid,
+            'updater' => $uname,
+            'updatetime' => $date,
+        ])) ? app_show(0, '修改流程成功') : error_show(1005, '修改流程失败');
+
+    }
+
+
 }

+ 21 - 0
app/admin/model/Process.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+//流程表
+class Process extends Model
+{
+    protected $table='wsm_process';
+    protected $pk='id';
+    protected $autoWriteTimestamp=false;
+
+    public static $is_del_normal=0;//是否删除,正常
+    public static $is_deleted=1;//是否删除,已删除
+
+    public static $status_normal=1;//状态,正常
+    public static $status_disable=2;//状态,禁用
+
+
+}

+ 5 - 0
app/admin/route/app.php

@@ -219,6 +219,11 @@ Route::rule("returnstatus","admin/Purchin/ReturnStatus");
 Route::rule("processlist","admin/Process/list");
 Route::rule("processinfo","admin/Process/info");
 Route::rule("process","admin/Process/process");
+Route::rule('process_get_list','admin/Process/getList');
+Route::rule('process_add','admin/Process/add');
+Route::rule('process_read','admin/Process/read');
+Route::rule('process_update','admin/Process/update');
+Route::rule('action_process_getlist','admin/ActionProcess/getList');
 
 Route::rule("expresslist","admin/Express/list");
 Route::rule("expressuse","admin/Express/SetUse");