request->filter('trim')->only(['status' => '', 'process_name' => '', 'creater' => '', 'addtime_start' => '', 'addtime_end' => '', 'page' => 1, 'size' => 15], 'post'); $where = [['is_del', '=', ProcessModel::$is_del_normal]]; if ($param['status'] != '') $where[] = ['status', '=', $param['status']]; if ($param['process_name'] != '') $where[] = ['process_name', 'like', '%' . $param['process_name'] . '%']; if ($param['creater'] != '') $where[] = ['creater', 'like', '%' . $param['creater'] . '%']; if ($param['addtime_start'] != '' && $param['addtime_end'] != '') $where[] = ['addtime', 'between', [$param['addtime_start'], $param['addtime_end'] . ' 23:59:59']]; $count = Db::name('process') ->where($where) ->count('id'); $list = ProcessModel::field('id,process_name,process_type,status,creater,addtime') ->where($where) ->order(['weight' => 'desc', 'id' => 'desc']) ->page($param['page'], $param['size']) ->select() ->toArray(); return app_show(0, '获取成功', ['count' => $count, 'list' => $list]); } //增加流程 public function add() { $param = $this->request->filter('trim')->only(['token', 'process_name', 'process_type', 'remark' => ''], 'post'); $val = Validate::rule([ 'token' => 'require', 'process_name|流程名称' => 'require|max:255', 'process_type|流程值' => 'require|max:255|checkProcessType:', ]); $val->extend('checkProcessType', function ($val) { return ProcessModel::where(['process_type' => $val, 'is_del' => ProcessModel::$is_del_normal])->field('id')->findOrEmpty()->isEmpty() ? true : '该流程值已存在'; }); 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 ProcessModel::create(array_merge($param, [ 'is_del' => ProcessModel::$is_del_normal, 'status' => ProcessModel::$status_disable, 'createrid' => $uid, 'creater' => $uname, 'addtime' => $date, 'updaterid' => $uid, 'updater' => $uname, 'updatetime' => $date, ]))->save() ? app_show(0, '新增流程成功') : error_show(1005, '新增流程失败'); } //读取 public function read() { $id = $this->request->filter('trim')->post('id/d', 0); $res = ProcessModel::field('id,process_name,process_type') ->where(['id' => $id, 'is_del' => ProcessModel::$is_del_normal]) ->findOrEmpty() ->toArray(); return app_show(0, '获取详情成功', $res); } //修改流程 public function update() { $param = $this->request->filter('trim')->only(['token', 'id', 'process_name', 'process_type', 'status', 'is_del', 'remark'], 'post'); $val = Validate::rule([ 'token' => 'require', 'id|ID' => 'require|number|gt:0', 'process_name|流程名称' => 'max:255', 'process_type|流程值' => 'max:255|checkProcessType:', 'status|状态' => 'number|in:' . ProcessModel::$status_normal . ',' . ProcessModel::$status_disable, 'is_del|是否删除' => 'number|eq:' . ProcessModel::$is_deleted, ]); $val->extend('checkProcessType', function ($val, $rule, $data) { return ProcessModel::where(['process_type' => $val, 'is_del' => ProcessModel::$is_del_normal])->where('id', '<>', $data['id'])->field('id')->findOrEmpty()->isEmpty() ? true : '该流程值已存在'; }); if (!$val->check($param)) return error_show(1005, $val->getError()); if (isset($param['status']) && $param['status'] == ProcessModel::$status_normal) { //启用流程时候,校验该流程下有没有开始节点和结束节点 $ap_info = APModel::where([ 'process_id' => $param['id'], 'is_del' => APModel::$is_del_normal, 'status' => APModel::$status_normal ])->whereIn('action_type', [ APModel::$action_type_start, APModel::$action_type_end ])->column('id', 'action_type'); if (count($ap_info) != 2) return error_show(1005, '该流程下缺少开始节点和结束节点'); } $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 ProcessModel::where(['id' => $param['id'], 'is_del' => ProcessModel::$is_del_normal])->strict(false)->save(array_merge($param, [ 'updaterid' => $uid, 'updater' => $uname, 'updatetime' => $date, ])) ? app_show(0, '修改流程成功') : error_show(1005, '修改流程失败'); } }