123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace app\admin\controller;
- //流程节点
- use think\facade\Db;
- use think\facade\Validate;
- use app\admin\model\ActionProcess as ActionProcessModel;
- class ActionProcess extends Base
- {
- //获取流程节点列表
- public function getList()
- {
- $param = $this->request->filter('trim')->only(['order_type', 'page' => 1, 'size' => 15], 'post');
- $val = Validate::rule([
- 'order_type|所属流程编码' => 'require',
- 'page|页码' => 'require|number|gt:0',
- 'size|每页显示的页码' => 'require|number|gt:0',
- ]);
- if (!$val->check($param)) return error_show(1005, $val->getError());
- $where = [];
- if ($param['order_type'] != '') $where[] = ['order_type', '=', $param['order_type']];
- $count = Db::name('action_process')
- ->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')
- ->where($where)
- ->order('id', 'desc')
- ->page($param['page'], $param['size'])
- ->select()
- ->toArray();
- $all_next_ids = implode(',', array_column($list, 'next_action_ids'));
- //处理下一个节点的名称
- $child = Db::name('action_process')
- ->whereIn('id', $all_next_ids)
- ->column('status_name', 'id');
- foreach ($list as &$item) {
- if ($item['next_action_ids']) {
- $next_action_ids = explode(',', $item['next_action_ids']);
- foreach ($next_action_ids as $next_action_id) {
- if (isset($child[$next_action_id])) $item['next_actions'][] = $child[$next_action_id];
- }
- } else $item['next_actions'] = [];
- }
- return app_show(0, '获取成功', ['count' => $count, 'list' => $list]);
- }
- //新增流程节点
- public function add()
- {
- $param = $this->request->filter('trim')->only(['token', 'order_type', 'order_name', 'action_type', 'operation_type', 'status_name', 'order_process', 'next_action_ids' => '', 'remark' => ''], 'post');
- $val = Validate::rule([
- 'token' => 'require',
- 'order_type|所属流程编码' => 'require|max:255',
- 'order_name|所属流程名称' => 'require|max:255',
- 'action_type|节点类型' => 'require|number|between:1,4',
- 'operation_type|操作类型' => 'require|number|in:1,2',
- 'status_name|节点名称' => 'require|max:255',
- 'order_process|节点值' => 'require|number|gt:0',
- ]);
- 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');
- return ActionProcessModel::create(array_merge($param, [
- 'status' => ActionProcessModel::$status_normal,
- 'is_del' => ActionProcessModel::$is_del_normal,
- 'createrid' => $uid,
- 'creater' => $uname,
- 'addtime' => $date,
- 'updaterid' => $uid,
- 'updater' => $uname,
- 'updatetime' => $date,
- 'remark' => $param['remark']
- ]))->save() ? app_show(0, '新增流程节点成功') : error_show(1005, '新增流程节点失败');
- }
- }
|