diff --git a/app/adminapi/controller/oa/FlowTypeController.php b/app/adminapi/controller/oa/FlowTypeController.php new file mode 100644 index 000000000..4ba9c000a --- /dev/null +++ b/app/adminapi/controller/oa/FlowTypeController.php @@ -0,0 +1,108 @@ +dataLists(new FlowTypeLists()); + } + + + /** + * @notes 添加审批类型 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function add() + { + $params = (new FlowTypeValidate())->post()->goCheck('add'); + $result = FlowTypeLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(FlowTypeLogic::getError()); + } + + + /** + * @notes 编辑审批类型 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function edit() + { + $params = (new FlowTypeValidate())->post()->goCheck('edit'); + $result = FlowTypeLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(FlowTypeLogic::getError()); + } + + + /** + * @notes 删除审批类型 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function delete() + { + $params = (new FlowTypeValidate())->post()->goCheck('delete'); + FlowTypeLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取审批类型详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function detail() + { + $params = (new FlowTypeValidate())->goCheck('detail'); + $result = FlowTypeLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/oa/FlowTypeLists.php b/app/adminapi/lists/oa/FlowTypeLists.php new file mode 100644 index 000000000..c48a12660 --- /dev/null +++ b/app/adminapi/lists/oa/FlowTypeLists.php @@ -0,0 +1,88 @@ + ['type'], + '%like%' => ['title'], + ]; + } + + + /** + * @notes 获取审批类型列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function lists(): array + { + return FlowType::where($this->searchWhere) + ->field(['id', 'type', 'title', 'name', 'org_id', 'department_ids', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::where('id','in',$data['department_ids'])->column('name'); + $data['org_name'] = $org['name']; + $data['dept_name'] = implode(',',$dept); + $data['type_text'] = $data->type_text; + $data['status_text'] = $data->status_text; + unset($data['org_id'],$data['department_ids']); + }) + ->toArray(); + } + + + /** + * @notes 获取审批类型数量 + * @return int + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function count(): int + { + return FlowType::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/oa/FlowTypeLogic.php b/app/adminapi/logic/oa/FlowTypeLogic.php new file mode 100644 index 000000000..ad52882a6 --- /dev/null +++ b/app/adminapi/logic/oa/FlowTypeLogic.php @@ -0,0 +1,124 @@ + $params['type'], + 'title' => $params['title'], + 'name' => $params['name'], + 'org_id' => $params['org_id'], + 'department_ids' => implode(',',$params['department_ids']), + 'status' => 2 + ]); + 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/01/31 10:48 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + FlowType::where('id', $params['id'])->update([ + 'type' => $params['type'], + 'title' => $params['title'], + 'name' => $params['name'], + 'org_id' => $params['org_id'], + 'department_ids' => implode(',',$params['department_ids']), + 'status' => $params['status'] + ]); + 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/01/31 10:48 + */ + public static function delete(array $params): bool + { + return FlowType::destroy($params['id']); + } + + + /** + * @notes 获取审批类型详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public static function detail($params): array + { + $data = FlowType::field('id,type,title,name,org_id,department_ids,status')->findOrEmpty($params['id']); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::where('id','in',$data['department_ids'])->column('name'); + $data['org_name'] = $org['name']; + $data['dept_name'] = implode(',',$dept); + $data['type_text'] = $data->type_text; + $data['status_text'] = $data->status_text; + $data['department_ids'] = explode(',',$data['department_ids']); + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/oa/FlowTypeValidate.php b/app/adminapi/validate/oa/FlowTypeValidate.php new file mode 100644 index 000000000..5ad491510 --- /dev/null +++ b/app/adminapi/validate/oa/FlowTypeValidate.php @@ -0,0 +1,153 @@ + 'require', + 'type' => 'require|checkType', + 'title' => 'require', + 'name' => 'require', + 'org_id' => 'require|checkOrg', + 'department_ids' => 'require|checkDepartmentIds', + 'status' => 'require|checkStatus', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'type' => '所属分类', + 'title' => '名称', + 'name' => '标识', + 'org_id' => '应用组织', + 'department_ids' => '应用部门', + 'status' => '状态', + ]; + + + /** + * @notes 添加场景 + * @return FlowTypeValidate + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function sceneAdd() + { + return $this->remove('id',true)->remove('status',true); + } + + + /** + * @notes 编辑场景 + * @return FlowTypeValidate + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function sceneEdit() + { + return $this->only(['id','type','title','name','org_id','department_ids','status']); + } + + + /** + * @notes 删除场景 + * @return FlowTypeValidate + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return FlowTypeValidate + * @author likeadmin + * @date 2024/01/31 10:48 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkType($value): bool|string + { + $dict = DictData::where('type_value','flow_type')->column('value'); + if(!in_array($value,$dict)){ + return '所属分类无效'; + } + return true; + } + + public function checkOrg($value): bool|string + { + $data = Orgs::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '组织不存在'; + } + return true; + } + + public function checkDepartmentIds($value,$rule,$data): bool|string + { + if(!is_array($value)){ + return '应用部门数据格式错误'; + } + foreach($value as $v){ + $dept = Dept::where('id',$v)->findOrEmpty(); + if($dept->isEmpty()){ + return '部门不存在'; + } + if($dept['org_id'] != $data['org_id']) { + return '部门信息无效'; + } + } + return true; + } + + public function checkStatus($value): bool|string + { + $dict = DictData::where('type_value','flow_type_status')->column('value'); + if(!in_array($value,$dict)){ + return '状态值无效'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/oa/FlowType.php b/app/common/model/oa/FlowType.php new file mode 100644 index 000000000..a146d3d88 --- /dev/null +++ b/app/common/model/oa/FlowType.php @@ -0,0 +1,43 @@ +column('name','value'); + return !empty($data['type']) ? $dict[$data['type']] : ''; + } + + public function getStatusTextAttr($value,$data){ + $dict = DictData::where('type_value','flow_type_status')->column('name','value'); + return !empty($data['status']) ? $dict[$data['status']] : ''; + } +} \ No newline at end of file