123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
- namespace app\admin\controller;
- use app\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 Base
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function list()
- {
- $page = isset($this->post['page']) && $this->post['page'] != "" ? intval($this->post['page']) : 1;
- $size = isset($this->post['size']) && $this->post['size'] != "" ? intval($this->post['size']) : 10;
- $count = Db::name("process")->where('is_del', 0)->count();
- $total = ceil($count / $size);
- $page = $page > $total ? $total : $page;
- $list = Db::name("process")->where('is_del', 0)->page($page, $size)->select();
- return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
- }
- /**
- * @return \think\response\Json|void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function info()
- {
- $id = isset($this->post['id']) && $this->post['id'] != "" ? intval($this->post['id']) : "";
- if ($id == "") {
- return error_show(1004, "参数id 不能为空");
- }
- $info = Db::name("process")->where(['id' => $id, "is_del" => 0])->find();
- if (empty($info)) {
- return error_show(1004, "流程信息未找到");
- }
- $list = Db::name("action_process")->where(["pid" => $id, "is_del" => 0])->order("weight,id")->select();
- $info['item'] = empty($list) ? [] : $list;
- return app_show(0, "获取成功", $info);
- }
- //审核记录
- public function process()
- {
- $param = $this->request->filter('trim')->only(['type', 'orderCode'], 'post');
- $val = Validate::rule([
- 'type'=>'require',
- 'orderCode'=>'require',
- ]);
- if (!$val->check($param)) return error_show(1004, $val->getError());
- // $process_type = isset($this->post['type']) && $this->post['type'] != "" ? $this->post['type'] : "";
- // if ($process_type == "") {
- // return error_show(1004, "参数type 不能为空");
- // }
- // $orderCode = isset($this->post['orderCode']) && $this->post['orderCode'] != "" ? $this->post['orderCode'] : "";
- // if ($orderCode == "") {
- // return error_show(1004, "参数orderCode不能为空");
- // }
- // $list = Db::name("action_process")
- // ->where(['order_type' => $param['type'], "is_del" => 0, "status" => 1])
- // ->order("weight desc,id desc")
- // ->column('*', 'order_process');
- //根据所有的状态,查询对应的操作
- // $order_process_s = array_column($list, 'order_process');
- $rs = Db::name("process_order")
- ->alias('a')
- ->leftJoin('action_process b', 'b.order_type=a.order_type AND b.order_process=a.action_process')
- ->where(["a.order_type" => $param['type']])
- ->order('a.id', 'asc')
- ->field('a.id,a.action_uid,a.action_name,a.addtime,a.action_process,a.order_type,a.source,a.level,a.action_process,b.status_name');
- if (is_numeric($param['orderCode'])) $rs->where('a.order_id', $param['orderCode']);
- else $rs->where('a.order_code', $param['orderCode']);
- $node = $rs
- ->select()
- ->toArray();
- $i = 0;
- $data = [['status_name' => '创建', 'order_process' => -1]];
- foreach ($node as $value) {
- $data[$i] = array_merge($data[$i], [
- 'action_uid' => $value['action_uid'],
- 'action_name' => $value['action_name'],
- 'addtime' => $value['addtime'],
- 'source' => $value['source'],
- 'level' => $value['level'],
- ]);
- $data[$i + 1] = [
- 'status_name' => $value['status_name'],
- 'order_process' => $value['action_process']
- ];
- // $value['order_process'] = isset($list[$value['action_process']]['order_process']) ? $list[$value['action_process']]['order_process'] : 0;
- // $value['order_name'] = isset($list[$value['action_process']]['order_name']) ? $list[$value['action_process']]['order_name'] : '';
- // $value['pid'] = isset($list[$value['action_process']]['pid']) ? $list[$value['action_process']]['pid'] : '';
- // $value['status_name'] = isset($list[$value['action_process']]['status_name']) ? $list[$value['action_process']]['status_name'] : '';
- // $value['roleid'] = isset($list[$value['action_process']]['roleid']) ? $list[$value['action_process']]['roleid'] : '';
- // $value['status'] = isset($list[$value['action_process']]['status']) ? $list[$value['action_process']]['status'] : '';
- // $value['weight'] = isset($list[$value['action_process']]['weight']) ? $list[$value['action_process']]['weight'] : '';
- // $value['is_del'] = isset($list[$value['action_process']]['is_del']) ? $list[$value['action_process']]['is_del'] : '';
- $i++;
- }
- // if ($node) array_unshift($node, ['status_name' => '创建', 'order_process' => -1]);
- return app_show(0, "获取成功", $data);
- }
- //获取流程列表
- 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, '修改流程失败');
- }
- }
|