diff --git a/app/adminapi/controller/works/bgsp/OaFlowTypeController.php b/app/adminapi/controller/works/bgsp/OaFlowTypeController.php new file mode 100644 index 000000000..4ce3220b1 --- /dev/null +++ b/app/adminapi/controller/works/bgsp/OaFlowTypeController.php @@ -0,0 +1,108 @@ +dataLists(new OaFlowTypeLists()); + } + + + /** + * @notes 添加审批类型 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function add() + { + $params = (new OaFlowTypeValidate())->post()->goCheck('add'); + $result = OaFlowTypeLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(OaFlowTypeLogic::getError()); + } + + + /** + * @notes 编辑审批类型 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function edit() + { + $params = (new OaFlowTypeValidate())->post()->goCheck('edit'); + $result = OaFlowTypeLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(OaFlowTypeLogic::getError()); + } + + + /** + * @notes 删除审批类型 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function delete() + { + $params = (new OaFlowTypeValidate())->post()->goCheck('delete'); + OaFlowTypeLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取审批类型详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function detail() + { + $params = (new OaFlowTypeValidate())->goCheck('detail'); + $result = OaFlowTypeLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/works/bgsp/OaFlowTypeLists.php b/app/adminapi/lists/works/bgsp/OaFlowTypeLists.php new file mode 100644 index 000000000..1724a8b88 --- /dev/null +++ b/app/adminapi/lists/works/bgsp/OaFlowTypeLists.php @@ -0,0 +1,86 @@ + ['type'], + '%like%' => ['title', 'name'], + ]; + } + + + /** + * @notes 获取审批类型列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function lists(): array + { + return OaFlowType::where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + if(!empty($data['department_ids'])){ + $dept = Dept::where('id','in',$data['department_ids'])->column('name'); + $data['department_names'] = implode(',',$dept); + }else{ + $data['department_names'] = '全公司'; + } + $data['type_text'] = $data->type_text; + }) + ->toArray(); + } + + + /** + * @notes 获取审批类型数量 + * @return int + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function count(): int + { + return OaFlowType::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/works/bgsp/OaFlowTypeLogic.php b/app/adminapi/logic/works/bgsp/OaFlowTypeLogic.php new file mode 100644 index 000000000..0790698c6 --- /dev/null +++ b/app/adminapi/logic/works/bgsp/OaFlowTypeLogic.php @@ -0,0 +1,123 @@ + $params['type'], + 'title' => $params['title'], + 'name' => $params['name'], + 'icon' => $params['icon'] ?? '', + 'department_ids' => $params['department_ids'] ?? '' + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑审批类型 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + OaFlowType::where('id', $params['id'])->update([ + 'type' => $params['type'], + 'title' => $params['title'], + 'name' => $params['name'], + 'icon' => $params['icon'] ?? '', + 'department_ids' => $params['department_ids'] ?? '' + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除审批类型 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public static function delete(array $params): bool + { + return OaFlowType::destroy($params['id']); + } + + + /** + * @notes 获取审批类型详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public static function detail($params): array + { + $data = OaFlowType::findOrEmpty($params['id']); + if(!empty($data['department_ids'])){ + $dept = Dept::where('id','in',$data['department_ids'])->column('name'); + $data['department_names'] = implode(',',$dept); + }else{ + $data['department_names'] = '全公司'; + } + $data['type_text'] = $data->type_text; + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/works/bgsp/OaFlowTypeValidate.php b/app/adminapi/validate/works/bgsp/OaFlowTypeValidate.php new file mode 100644 index 000000000..f63d89e41 --- /dev/null +++ b/app/adminapi/validate/works/bgsp/OaFlowTypeValidate.php @@ -0,0 +1,130 @@ + 'require', + 'type' => 'require|checkType', + 'title' => 'require', + 'name' => 'require', + 'department_ids' => 'checkDept', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'type' => '所属分类', + 'title' => '审批名称', + 'name' => '审批标识', + 'department_ids' => '应用部门', + ]; + + + /** + * @notes 添加场景 + * @return OaFlowTypeValidate + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function sceneAdd() + { + return $this->only(['type','title','name','icon','department_ids']); + } + + + /** + * @notes 编辑场景 + * @return OaFlowTypeValidate + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function sceneEdit() + { + return $this->only(['id','type','title','name','icon','department_ids']); + } + + + /** + * @notes 删除场景 + * @return OaFlowTypeValidate + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return OaFlowTypeValidate + * @author likeadmin + * @date 2024/05/24 13:34 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkType($value): bool|string + { + $dict = DictData::where('type_value', 'oa_approve_cate')->column('value'); + if (!in_array($value, $dict)) { + return '所属分类数据值无效'; + } + return true; + } + + public function checkDept($value): bool|string + { + if(!empty($value)){ + $data = explode(',',$value); + if(empty($data)){ + return '应用部门数据错误'; + } + foreach($data as $v){ + $dept = Dept::where('id',$v)->findOrEmpty(); + if($dept->isEmpty()){ + return '应用部门信息不存在'; + } + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/works/bgsp/OaFlowType.php b/app/common/model/works/bgsp/OaFlowType.php new file mode 100644 index 000000000..0977605f1 --- /dev/null +++ b/app/common/model/works/bgsp/OaFlowType.php @@ -0,0 +1,38 @@ +column('name','value'); + return !empty($data['type']) ? $dict[$data['type']] : ''; + } +} \ No newline at end of file