wufeng 2 years ago
parent
commit
7b0a6abd17

+ 36 - 14
app/admin/controller/ActionProcess.php

@@ -2,12 +2,12 @@
 
 namespace app\admin\controller;
 
-//流程节点
 use think\facade\Db;
 use think\facade\Validate;
 use app\admin\model\ActionProcess as APModel;
 use app\admin\model\Process as PModel;
 
+//流程节点
 class ActionProcess extends Base
 {
 
@@ -18,7 +18,7 @@ class ActionProcess extends Base
         $param = $this->request->filter('trim')->only(['order_type', 'page' => 1, 'size' => 15], 'post');
 
         $val = Validate::rule([
-            'order_type|所属流程编码' => 'require',
+            'order_type|流程编码' => 'require',
             'page|页码' => 'require|number|gt:0',
             'size|每页显示的页码' => 'require|number|gt:0',
         ]);
@@ -32,8 +32,7 @@ class ActionProcess extends Base
             ->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')
+        $list = APModel::field('id,status_name,order_process,status,action_type,operation_type,next_action_ids,creater,addtime,remark')
             ->where($where)
             ->order('id', 'desc')
             ->page($param['page'], $param['size'])
@@ -60,7 +59,7 @@ class ActionProcess extends Base
 
     }
 
-    //新增流程节点
+    //新增
     public function add()
     {
 
@@ -74,7 +73,7 @@ class ActionProcess extends Base
             'operation_type|操作类型' => 'require|number|in:' . APModel::$operation_type_approval . ',' . APModel::$operation_type_system,
             'status_name|节点名称' => 'require|max:255',
             'order_process|节点值' => 'require|number|egt:0|checkOrderProcess:',
-            'next_action_ids|下一节点' => 'requireIf:action_type,' . APModel::$action_type_start . '|requireIf:action_type,' . APModel::$action_type_process,
+            'next_action_ids|下一节点' => 'array|requireIf:action_type,' . APModel::$action_type_start . '|requireIf:action_type,' . APModel::$action_type_process,
         ]);
 
         $val->extend('checkProcess', function ($val, $rule, $data) {
@@ -112,7 +111,6 @@ class ActionProcess extends Base
             'updatetime' => $date,
         ]))->save() ? app_show(0, '新增流程节点成功') : error_show(1005, '新增流程节点失败');
 
-
     }
 
     //读取
@@ -123,6 +121,9 @@ class ActionProcess extends Base
 
         $res = APModel::field(true)
             ->where(['id' => $id, 'is_del' => APModel::$is_del_normal])
+            ->withAttr('next_action_ids', function ($val) {
+                return explode(',', $val);
+            })
             ->findOrEmpty()
             ->toArray();
 
@@ -133,7 +134,7 @@ class ActionProcess extends Base
     public function update()
     {
 
-        $param = $this->request->filter('trim')->only(['token', 'id', 'order_type', 'order_name', 'action_type', 'operation_type', 'status_name', 'order_process', 'next_action_ids' => '', 'remark' => ''], 'post');
+        $param = $this->request->filter('trim')->only(['token', 'id', 'order_type', 'order_name', 'action_type', 'operation_type', 'status_name', 'order_process', 'next_action_ids' => '', 'remark' => '', 'status' => '', 'is_del' => ''], 'post');
 
         $val = Validate::rule([
             'token' => 'require',
@@ -144,17 +145,19 @@ class ActionProcess extends Base
             'operation_type|操作类型' => 'number|in:' . APModel::$operation_type_approval . ',' . APModel::$operation_type_system,
             'status_name|节点名称' => 'max:255',
             'order_process|节点值' => 'number|egt:0|checkOrderProcess:',
-            'next_action_ids|下一节点' => 'requireIf:action_type,' . APModel::$action_type_start . '|requireIf:action_type,' . APModel::$action_type_process,
-            'is_del' => 'eq:' . APModel::$is_deleted,
-            'status' => 'in:' . APModel::$status_disable . ',' . APModel::$status_normal,
+            'next_action_ids|下一节点' => 'array|requireIf:action_type,' . APModel::$action_type_start . '|requireIf:action_type,' . APModel::$action_type_process,
+            'is_del|是否删除' => 'eq:' . APModel::$is_deleted,
+            'status|状态' => 'in:' . APModel::$status_disable . ',' . APModel::$status_normal,
         ]);
 
         $val->extend('checkProcess', function ($val, $rule, $data) {
-            return PModel::where(['process_name' => $val, 'process_type' => $data['order_type'], 'is_del' => PModel::$is_del_normal])->field('id')->findOrEmpty()->isEmpty() ? '流程编码和流程名称不存在' : true;
+            if (isset($val) && isset($data['order_type'])) return PModel::where(['process_name' => $val, 'process_type' => $data['order_type'], 'is_del' => PModel::$is_del_normal])->field('id')->findOrEmpty()->isEmpty() ? '流程编码和流程名称不存在' : true;
+            else return true;
         });
 
         $val->extend('checkOrderProcess', function ($val, $rule, $data) {
-            return APModel::where(['order_type' => $data['order_type'], 'order_process' => $val, 'is_del' => APModel::$is_del_normal])->where('id', '<>', $data['id'])->field('id')->findOrEmpty()->isEmpty() ? true : '同一个流程编码下该节点值已存在';
+            if (isset($val) && isset($data['order_type'])) return APModel::where(['order_type' => $data['order_type'], 'order_process' => $val, 'is_del' => APModel::$is_del_normal])->where('id', '<>', $data['id'])->field('id')->findOrEmpty()->isEmpty() ? true : '同一个流程编码下该节点值已存在';
+            else return true;
         });
 
         if (!$val->check($param)) return error_show(1005, $val->getError());
@@ -165,7 +168,26 @@ class ActionProcess extends Base
         $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
         $date = date('Y-m-d H:i:s');
 
-        return APModel::where(['id' => $param['id'], 'is_del' => APModel::$is_del_normal])->strict(false)->save(array_merge($param, ['updaterid' => $uid, 'updater' => $uname, 'updatetime' => $date])) ? app_show(0, '新增流程节点成功') : error_show(1005, '新增流程节点失败');
+        return APModel::where(['id' => $param['id'], 'is_del' => APModel::$is_del_normal])->strict(false)->save(array_merge($param, ['updaterid' => $uid, 'updater' => $uname, 'updatetime' => $date])) ? app_show(0, '修改流程节点成功') : error_show(1005, '修改流程节点失败');
+
+    }
+
+    //获取所有流程的所有节点
+    public function getAll()
+    {
+
+        $data = PModel::where(['is_del' => PModel::$is_del_normal, 'status' => PModel::$status_normal])
+            ->column('id,process_name,process_type', 'process_type');
+
+        $action = APModel::where(['is_del' => APModel::$is_del_normal, 'status' => APModel::$status_normal])
+            ->field('id,order_type,order_process,status_name')
+            ->cursor();
+
+        foreach ($action as $item) {
+            $data[$item->order_type]['child'][] = $item->toArray();
+        }
+
+        return app_show(0, '请求成功', array_column($data,null,null));
 
     }
 

+ 75 - 0
app/admin/controller/Role.php

@@ -6,6 +6,7 @@ use app\BaseController;
 use think\App;
 use think\facade\Db;
 use app\admin\model\ActionLog;
+use think\facade\Validate;
 
 //角色
 class Role extends BaseController
@@ -373,4 +374,78 @@ class Role extends BaseController
         $list =Db::name("role")->select();
         return app_show(0,"获取成功",$list);
     }
+
+
+    //获取角色对应的流程权限详情
+    public function roleProcessInfo()
+    {
+        $roleid = $this->request->filter('trim')->post('roleid/d', 0);
+
+        $res = Db::name("role")
+            ->alias("a")
+            ->leftJoin("role_process b", "a.id=b.role_id AND b.is_del=0")
+            ->field("a.*,b.action_data")
+            ->withAttr('action_data', function ($val) {
+                return explode(',', $val);
+            })
+            ->where("a.id", $roleid)
+            ->findOrEmpty();
+
+        return app_show(0, '请求成功', $res);
+
+    }
+
+    //修改角色对应的流程权限
+    public function roleProcessSave()
+    {
+        $param = $this->request->filter('trim')->only(['token', 'roleid', 'action_data'], 'post');
+
+        $val = Validate::rule([
+            'token' => 'require',
+            'roleid|角色ID' => 'require|number|gt:0',
+            'action_data|所选节点id' => 'require|array',
+        ]);
+
+        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');
+
+        $res = Db::name('role_process')
+            ->where(['is_del' => 0, 'role_id' => $param['roleid']])
+            ->field('id')
+            ->findOrEmpty();
+
+        if (empty($res)) {
+            $rs = Db::name('role_process')
+                ->insert([
+                    'role_id' => $param['roleid'],
+                    'action_data' => implode(',', $param['action_data']),
+                    'is_del' => 0,
+                    'createrid' => $uid,
+                    'creater' => $uname,
+                    'addtime' => $date,
+                    'updaterid' => $uid,
+                    'updater' => $uname,
+                    'updatetime' => $date,
+                ]);
+        } else {
+            $rs = Db::name('role_process')
+                ->where('id', $res['id'])
+                ->update([
+                    'action_data' => implode(',', $param['action_data']),
+                    'updaterid' => $uid,
+                    'updater' => $uname,
+                    'updatetime' => $date
+                ]);
+        }
+
+        return $rs ? app_show(0, '操作成功') : error_show(1005, '操作失败');
+
+    }
+
+
 }

+ 9 - 1
app/admin/model/ActionProcess.php

@@ -13,7 +13,15 @@ class ActionProcess extends Model
     protected $table = 'wsm_action_process';
     protected $pk = 'id';
     protected $autoWriteTimestamp = false;
-    protected $hidden=['pid','roleid','uid','uname','weight'];
+    protected $hidden = ['pid', 'roleid', 'uid', 'uname', 'weight'];
+
+
+    public function setNextActionIdsAttr($val)
+    {
+        return is_array($val) ? implode(',', $val) : $val;
+    }
+
+
 
     public static $action_type_start = 1;//节点类型,1开始节点
     public static $action_type_process = 2;//节点类型,2过程节点

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

@@ -41,6 +41,8 @@ Route::rule('roleinfo', 'admin/Role/RoleInfo');
 Route::rule('roleadd', 'admin/Role/RoleAdd');
 Route::rule('rolesave', 'admin/Role/RoleSave');
 Route::rule('rolestatus', 'admin/Role/RoleStatus');
+Route::rule('role_process_info', 'admin/Role/roleProcessInfo');
+Route::rule('role_process_save', 'admin/Role/roleProcessSave');
 
 Route::rule('ulist','admin/Newfill/list');
 Route::rule('add','admin/Newfill/add');
@@ -226,6 +228,9 @@ Route::rule('process_update','admin/Process/update');
 Route::rule('action_process_getlist','admin/ActionProcess/getList');
 Route::rule('action_process_add','admin/ActionProcess/add');
 Route::rule('action_process_read','admin/ActionProcess/read');
+Route::rule('action_process_update','admin/ActionProcess/update');
+Route::rule('action_process_update','admin/ActionProcess/update');
+Route::rule('action_process_all','admin/ActionProcess/getAll');
 
 Route::rule("expresslist","admin/Express/list");
 Route::rule("expressuse","admin/Express/SetUse");