From 2887c9937f346c3ef0033b3cb1ff1a199039e58f Mon Sep 17 00:00:00 2001 From: weiz Date: Thu, 14 Dec 2023 15:29:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E8=AE=BE=E7=BD=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ProjectDocumentSetController.php | 108 ++++++++++++++ .../lists/project/ProjectDocumentSetLists.php | 95 ++++++++++++ .../logic/project/ProjectDocumentSetLogic.php | 122 ++++++++++++++++ .../project/ProjectDocumentSetValidate.php | 137 ++++++++++++++++++ .../model/project/ProjectDocumentSet.php | 34 +++++ 5 files changed, 496 insertions(+) create mode 100644 app/adminapi/controller/project/ProjectDocumentSetController.php create mode 100644 app/adminapi/lists/project/ProjectDocumentSetLists.php create mode 100644 app/adminapi/logic/project/ProjectDocumentSetLogic.php create mode 100644 app/adminapi/validate/project/ProjectDocumentSetValidate.php create mode 100644 app/common/model/project/ProjectDocumentSet.php diff --git a/app/adminapi/controller/project/ProjectDocumentSetController.php b/app/adminapi/controller/project/ProjectDocumentSetController.php new file mode 100644 index 000000000..364a7f64a --- /dev/null +++ b/app/adminapi/controller/project/ProjectDocumentSetController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectDocumentSetLists()); + } + + + /** + * @notes 添加项目文档设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function add() + { + $params = (new ProjectDocumentSetValidate())->post()->goCheck('add'); + $result = ProjectDocumentSetLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectDocumentSetLogic::getError()); + } + + + /** + * @notes 编辑项目文档设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function edit() + { + $params = (new ProjectDocumentSetValidate())->post()->goCheck('edit'); + $result = ProjectDocumentSetLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectDocumentSetLogic::getError()); + } + + + /** + * @notes 删除项目文档设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function delete() + { + $params = (new ProjectDocumentSetValidate())->post()->goCheck('delete'); + ProjectDocumentSetLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取项目文档设置详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function detail() + { + $params = (new ProjectDocumentSetValidate())->goCheck('detail'); + $result = ProjectDocumentSetLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectDocumentSetLists.php b/app/adminapi/lists/project/ProjectDocumentSetLists.php new file mode 100644 index 000000000..ecba3bca2 --- /dev/null +++ b/app/adminapi/lists/project/ProjectDocumentSetLists.php @@ -0,0 +1,95 @@ + ['is_upload'], + '%like%' => ['large_category', 'middle_category', 'small_category', 'name'], + ]; + } + + + /** + * @notes 获取项目文档设置列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function lists(): array + { + $params = $this->request->param(); + $where = []; + if(isset($params['project_type_name']) && $params['project_type_name'] != ''){ + $projectTypeIds = ProjectTypeSet::where('name','like','%'.$params['project_type_name'].'%')->column('id'); + $where[] = ['project_type_id','in',$projectTypeIds]; + } + return ProjectDocumentSet::where($this->searchWhere)->where($where) + ->field(['id', 'project_type_id', 'large_category', 'middle_category', 'small_category', 'name', 'describe', 'is_upload', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $projectType = ProjectTypeSet::field('name')->where('id',$item['project_type_id'])->findOrEmpty(); + $item['project_type_name'] = $projectType['name']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取项目文档设置数量 + * @return int + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function count(): int + { + $params = $this->request->param(); + $where = []; + if(isset($params['project_type_name']) && $params['project_type_name'] != ''){ + $projectTypeIds = ProjectTypeSet::where('name','like','%'.$params['project_type_name'].'%')->column('id'); + $where[] = ['project_type_id','in',$projectTypeIds]; + } + return ProjectDocumentSet::where($this->searchWhere)->where($where)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectDocumentSetLogic.php b/app/adminapi/logic/project/ProjectDocumentSetLogic.php new file mode 100644 index 000000000..38435578d --- /dev/null +++ b/app/adminapi/logic/project/ProjectDocumentSetLogic.php @@ -0,0 +1,122 @@ + $params['project_type_id'], + 'large_category' => $params['large_category'], + 'middle_category' => $params['middle_category'], + 'small_category' => $params['small_category'], + 'name' => $params['name'], + 'describe' => $params['describe'], + 'is_upload' => $params['is_upload'], + 'sort' => $params['sort'], + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑项目文档设置 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectDocumentSet::where('id', $params['id'])->update([ + 'project_type_id' => $params['project_type_id'], + 'large_category' => $params['large_category'], + 'middle_category' => $params['middle_category'], + 'small_category' => $params['small_category'], + 'name' => $params['name'], + 'describe' => $params['describe'], + 'is_upload' => $params['is_upload'], + 'sort' => $params['sort'], + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除项目文档设置 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public static function delete(array $params): bool + { + return ProjectDocumentSet::destroy($params['id']); + } + + + /** + * @notes 获取项目文档设置详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public static function detail($params): array + { + $data = ProjectDocumentSet::field('id,project_type_id,large_category,middle_category,small_category,name,describe,is_upload,sort')->findOrEmpty($params['id'])->toArray(); + $projectType = ProjectTypeSet::field('name')->where('id',$data['project_type_id'])->findOrEmpty(); + $data['project_type_name'] = $projectType['name']; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectDocumentSetValidate.php b/app/adminapi/validate/project/ProjectDocumentSetValidate.php new file mode 100644 index 000000000..4bdcd1ef4 --- /dev/null +++ b/app/adminapi/validate/project/ProjectDocumentSetValidate.php @@ -0,0 +1,137 @@ + 'require|checkProjectDoc', + 'project_type_id' => 'require|checkProjectType', + 'large_category' => 'require', + 'middle_category' => 'require', + 'name' => 'require', + 'is_upload' => 'require|in:1,2', + 'sort' => 'require|integer', + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'project_type_id.require' => '请选择项目类型', + 'large_category.require' => '请填写文档大类', + 'middle_category.require' => '请填写文档中类', + 'name.require' => '请填写文档名称', + 'is_upload.require' => '请选择是否必传', + 'is_upload.in' => '是否必传选项数据值错误', + 'sort.require' => '请填写排序码', + 'sort.integer' => '排序码数据格式错误', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'project_type_id' => '项目类型id', + 'large_category' => '文档大类', + 'middle_category' => '文档中类', + 'name' => '文档名称', + 'is_upload' => '必传 1-是 2-否', + 'sort' => '排序号', + + ]; + + + /** + * @notes 添加场景 + * @return ProjectDocumentSetValidate + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ProjectDocumentSetValidate + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ProjectDocumentSetValidate + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectDocumentSetValidate + * @author likeadmin + * @date 2023/12/14 14:26 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkProjectDoc($value): bool|string + { + $data = ProjectDocumentSet::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '数据不存在'; + } + return true; + } + + public function checkProjectType($value): bool|string + { + $data = ProjectTypeSet::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目类型不存在'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/project/ProjectDocumentSet.php b/app/common/model/project/ProjectDocumentSet.php new file mode 100644 index 000000000..570958fef --- /dev/null +++ b/app/common/model/project/ProjectDocumentSet.php @@ -0,0 +1,34 @@ +