ActionProcess.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\admin\controller;
  3. //流程节点
  4. use think\facade\Db;
  5. use think\facade\Validate;
  6. use app\admin\model\ActionProcess as ActionProcessModel;
  7. class ActionProcess extends Base
  8. {
  9. //获取流程节点列表
  10. public function getList()
  11. {
  12. $param = $this->request->filter('trim')->only(['order_type', 'page' => 1, 'size' => 15], 'post');
  13. $val = Validate::rule([
  14. 'order_type|所属流程编码' => 'require',
  15. 'page|页码' => 'require|number|gt:0',
  16. 'size|每页显示的页码' => 'require|number|gt:0',
  17. ]);
  18. if (!$val->check($param)) return error_show(1005, $val->getError());
  19. $where = [];
  20. if ($param['order_type'] != '') $where[] = ['order_type', '=', $param['order_type']];
  21. $count = Db::name('action_process')
  22. ->where($where)
  23. ->count('id');
  24. $list = Db::name('action_process')
  25. ->field('id,status_name,order_process,status,action_type,operation_type,next_action_ids,creater,addtime')
  26. ->where($where)
  27. ->order('id', 'desc')
  28. ->page($param['page'], $param['size'])
  29. ->select()
  30. ->toArray();
  31. $all_next_ids = implode(',', array_column($list, 'next_action_ids'));
  32. //处理下一个节点的名称
  33. $child = Db::name('action_process')
  34. ->whereIn('id', $all_next_ids)
  35. ->column('status_name', 'id');
  36. foreach ($list as &$item) {
  37. if ($item['next_action_ids']) {
  38. $next_action_ids = explode(',', $item['next_action_ids']);
  39. foreach ($next_action_ids as $next_action_id) {
  40. if (isset($child[$next_action_id])) $item['next_actions'][] = $child[$next_action_id];
  41. }
  42. } else $item['next_actions'] = [];
  43. }
  44. return app_show(0, '获取成功', ['count' => $count, 'list' => $list]);
  45. }
  46. //新增流程节点
  47. public function add()
  48. {
  49. $param = $this->request->filter('trim')->only(['token', 'order_type', 'order_name', 'action_type', 'operation_type', 'status_name', 'order_process', 'next_action_ids' => '', 'remark' => ''], 'post');
  50. $val = Validate::rule([
  51. 'token' => 'require',
  52. 'order_type|所属流程编码' => 'require|max:255',
  53. 'order_name|所属流程名称' => 'require|max:255',
  54. 'action_type|节点类型' => 'require|number|between:1,4',
  55. 'operation_type|操作类型' => 'require|number|in:1,2',
  56. 'status_name|节点名称' => 'require|max:255',
  57. 'order_process|节点值' => 'require|number|gt:0',
  58. ]);
  59. if (!$val->check($param)) return error_show(1005, $val->getError());
  60. $user = GetUserInfo($param['token']);
  61. $uid = isset($user['data']['id']) ? $user['data']['id'] : 0;
  62. $uname = isset($user['data']['nickname']) ? $user['data']['nickname'] : '';
  63. $date = date('Y-m-d H:i:s');
  64. return ActionProcessModel::create(array_merge($param, [
  65. 'status' => ActionProcessModel::$status_normal,
  66. 'is_del' => ActionProcessModel::$is_del_normal,
  67. 'createrid' => $uid,
  68. 'creater' => $uname,
  69. 'addtime' => $date,
  70. 'updaterid' => $uid,
  71. 'updater' => $uname,
  72. 'updatetime' => $date,
  73. 'remark' => $param['remark']
  74. ]))->save() ? app_show(0, '新增流程节点成功') : error_show(1005, '新增流程节点失败');
  75. }
  76. }