Process.php 5.4 KB

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