Process.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. use think\facade\Validate;
  7. use app\admin\model\Process as ProcessModel;
  8. use app\admin\model\ActionProcess as APModel;
  9. //流程
  10. class Process extends BaseController
  11. {
  12. //获取流程列表
  13. public function getList()
  14. {
  15. $param = $this->request->filter('trim')->only(['status' => '', 'process_name' => '', 'creater' => '', 'addtime_start' => '', 'addtime_end' => '', 'page' => 1, 'size' => 15], 'post');
  16. $where = [['is_del', '=', ProcessModel::$is_del_normal]];
  17. if ($param['status'] != '') $where[] = ['status', '=', $param['status']];
  18. if ($param['process_name'] != '') $where[] = ['process_name', 'like', '%' . $param['process_name'] . '%'];
  19. if ($param['creater'] != '') $where[] = ['creater', 'like', '%' . $param['creater'] . '%'];
  20. if ($param['addtime_start'] != '' && $param['addtime_end'] != '') $where[] = ['addtime', 'between', [$param['addtime_start'], $param['addtime_end'] . ' 23:59:59']];
  21. $count = Db::name('process')
  22. ->where($where)
  23. ->count('id');
  24. $list = ProcessModel::field('id,process_name,process_type,status,creater,addtime')
  25. ->where($where)
  26. ->order(['weight' => 'desc', 'id' => 'desc'])
  27. ->page($param['page'], $param['size'])
  28. ->select()
  29. ->toArray();
  30. return app_show(0, '获取成功', ['count' => $count, 'list' => $list]);
  31. }
  32. //增加流程
  33. public function add()
  34. {
  35. $param = $this->request->filter('trim')->only(['token', 'process_name', 'process_type', 'remark' => ''], 'post');
  36. $val = Validate::rule([
  37. 'token' => 'require',
  38. 'process_name|流程名称' => 'require|max:255',
  39. 'process_type|流程值' => 'require|max:255|checkProcessType:',
  40. ]);
  41. $val->extend('checkProcessType', function ($val) {
  42. return ProcessModel::where(['process_type' => $val, 'is_del' => ProcessModel::$is_del_normal])->field('id')->findOrEmpty()->isEmpty() ? true : '该流程值已存在';
  43. });
  44. if (!$val->check($param)) return error_show(1005, $val->getError());
  45. $user = GetUserInfo($param['token']);
  46. $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  47. $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  48. $date = date('Y-m-d H:i:s');
  49. return ProcessModel::create(array_merge($param, [
  50. 'is_del' => ProcessModel::$is_del_normal,
  51. 'status' => ProcessModel::$status_disable,
  52. 'createrid' => $uid,
  53. 'creater' => $uname,
  54. 'addtime' => $date,
  55. 'updaterid' => $uid,
  56. 'updater' => $uname,
  57. 'updatetime' => $date,
  58. ]))->save() ? app_show(0, '新增流程成功') : error_show(1005, '新增流程失败');
  59. }
  60. //读取
  61. public function read()
  62. {
  63. $id = $this->request->filter('trim')->post('id/d', 0);
  64. $res = ProcessModel::field('id,process_name,process_type')
  65. ->where(['id' => $id, 'is_del' => ProcessModel::$is_del_normal])
  66. ->findOrEmpty()
  67. ->toArray();
  68. return app_show(0, '获取详情成功', $res);
  69. }
  70. //修改流程
  71. public function update()
  72. {
  73. $param = $this->request->filter('trim')->only(['token', 'id', 'process_name', 'process_type', 'status', 'is_del', 'remark'], 'post');
  74. $val = Validate::rule([
  75. 'token' => 'require',
  76. 'id|ID' => 'require|number|gt:0',
  77. 'process_name|流程名称' => 'max:255',
  78. 'process_type|流程值' => 'max:255|checkProcessType:',
  79. 'status|状态' => 'number|in:' . ProcessModel::$status_normal . ',' . ProcessModel::$status_disable,
  80. 'is_del|是否删除' => 'number|eq:' . ProcessModel::$is_deleted,
  81. ]);
  82. $val->extend('checkProcessType', function ($val, $rule, $data) {
  83. return ProcessModel::where(['process_type' => $val, 'is_del' => ProcessModel::$is_del_normal])->where('id', '<>', $data['id'])->field('id')->findOrEmpty()->isEmpty() ? true : '该流程值已存在';
  84. });
  85. if (!$val->check($param)) return error_show(1005, $val->getError());
  86. if (isset($param['status']) && $param['status'] == ProcessModel::$status_normal) {
  87. //启用流程时候,校验该流程下有没有开始节点和结束节点
  88. $ap_info = APModel::where([
  89. 'process_id' => $param['id'],
  90. 'is_del' => APModel::$is_del_normal,
  91. 'status' => APModel::$status_normal
  92. ])->whereIn('action_type', [
  93. APModel::$action_type_start,
  94. APModel::$action_type_end
  95. ])->column('id', 'action_type');
  96. if (count($ap_info) != 2) return error_show(1005, '该流程下缺少开始节点和结束节点');
  97. }
  98. $user = GetUserInfo($param['token']);
  99. $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  100. $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  101. $date = date('Y-m-d H:i:s');
  102. return ProcessModel::where(['id' => $param['id'], 'is_del' => ProcessModel::$is_del_normal])->strict(false)->save(array_merge($param, [
  103. 'updaterid' => $uid,
  104. 'updater' => $uname,
  105. 'updatetime' => $date,
  106. ])) ? app_show(0, '修改流程成功') : error_show(1005, '修改流程失败');
  107. }
  108. }