|
@@ -3,8 +3,11 @@
|
|
|
declare (strict_types = 1);
|
|
|
namespace app\admin\controller;
|
|
|
use app\admin\BaseController;
|
|
|
+use app\admin\model\ActionProcess as APModel;
|
|
|
+use app\admin\model\Process as PModel;
|
|
|
use think\App;
|
|
|
use think\facade\Db;
|
|
|
+use think\facade\Validate;
|
|
|
|
|
|
class Role extends BaseController{
|
|
|
|
|
@@ -253,4 +256,111 @@ class Role extends BaseController{
|
|
|
$list =Db::name("role")->select();
|
|
|
return app_show(0,"获取成功",$list);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //获取角色对应的流程权限id
|
|
|
+ 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, '操作失败');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取角色对应的流程权限详情
|
|
|
+ public function roleProcessDetail()
|
|
|
+ {
|
|
|
+
|
|
|
+ $roleid = $this->request->filter('trim')->post('roleid/d', 0);
|
|
|
+
|
|
|
+ $action_data = Db::name("role_process")
|
|
|
+ ->where('role_id', $roleid)
|
|
|
+ ->value('action_data');
|
|
|
+
|
|
|
+ $data = PModel::where(['is_del' => PModel::$is_del_normal, 'status' => PModel::$status_normal])
|
|
|
+ ->append(['child'])
|
|
|
+ ->withAttr('child', function () {
|
|
|
+ return [];
|
|
|
+ })
|
|
|
+ ->column('id,process_name,process_type', 'id');
|
|
|
+
|
|
|
+ $action = APModel::where([
|
|
|
+ 'is_del' => APModel::$is_del_normal,
|
|
|
+ 'status' => APModel::$status_normal,
|
|
|
+ 'operation_type' => APModel::$operation_type_approval
|
|
|
+ ])->whereIn('id', $action_data)
|
|
|
+ ->field('id,process_id,order_process,status_name')
|
|
|
+ ->cursor();
|
|
|
+
|
|
|
+ foreach ($action as $item) {
|
|
|
+ if (isset($data[$item->process_id])) $data[$item->process_id]['child'][] = $item->toArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ return app_show(0, '请求成功', array_column($data, null, null));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|