123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace app\admin\controller;
- use app\admin\BaseController;
- use think\App;
- use think\facade\Db;
- use think\facade\Validate;
- use app\admin\model\Process as ProcessModel;
- use app\admin\model\ActionProcess as APModel;
- //流程
- class Process extends BaseController
- {
- //获取流程列表
- public function getList()
- {
- $param = $this->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, '修改流程失败');
- }
- }
|