service = new SchoolApprovalConfigService(); } /** * 获取审批流配置列表 */ public function lists() { $page = input('page', 1); $limit = input('limit', 10); $status = input('status', ''); $where = []; if ($status !== '') { $where[] = ['status', '=', intval($status)]; } $config_name = input('config_name', ''); if (!empty($config_name)) { $where[] = ['config_name', 'like', "%{$config_name}%"]; } $data = $this->service->getList($where, $page, $limit); return success($data); } /** * 获取审批流配置详情 */ public function info() { $id = input('id', 0); if (empty($id)) { return error('参数错误'); } $info = $this->service->getInfo($id); if (empty($info)) { return error('审批流配置不存在'); } return success($info); } /** * 添加审批流配置 */ public function add() { $data = Request::only(['config_name', 'description', 'status', 'nodes']); // 验证参数 if (empty($data['config_name'])) { return error('配置名称不能为空'); } if (empty($data['nodes']) || !is_array($data['nodes'])) { return error('至少需要添加一个审批节点'); } // 验证节点数据 foreach ($data['nodes'] as $node) { if (empty($node['node_name'])) { return error('节点名称不能为空'); } if (empty($node['approver_type'])) { return error('审批人类型不能为空'); } if (empty($node['approver_ids'])) { return error('审批人不能为空'); } } // 设置创建人ID $data['creator_id'] = $this->user_info['uid']; try { $config_id = $this->service->add($data); return success(['id' => $config_id]); } catch (\Exception $e) { return error($e->getMessage()); } } /** * 编辑审批流配置 */ public function edit() { $data = Request::only(['id', 'config_name', 'description', 'status', 'nodes']); // 验证参数 if (empty($data['id'])) { return error('参数错误'); } if (empty($data['config_name'])) { return error('配置名称不能为空'); } if (empty($data['nodes']) || !is_array($data['nodes'])) { return error('至少需要添加一个审批节点'); } // 验证节点数据 foreach ($data['nodes'] as $node) { if (empty($node['node_name'])) { return error('节点名称不能为空'); } if (empty($node['approver_type'])) { return error('审批人类型不能为空'); } if (empty($node['approver_ids'])) { return error('审批人不能为空'); } } try { $result = $this->service->edit($data); return success($result); } catch (\Exception $e) { return error($e->getMessage()); } } /** * 删除审批流配置 */ public function delete() { $id = input('id', 0); if (empty($id)) { return error('参数错误'); } try { $result = $this->service->delete($id); return success($result); } catch (\Exception $e) { return error($e->getMessage()); } } /** * 修改状态 */ public function changeStatus() { $id = input('id', 0); $status = input('status', 0); if (empty($id)) { return error('参数错误'); } try { $result = $this->service->changeStatus($id, $status); return success($result); } catch (\Exception $e) { return error($e->getMessage()); } } }