From fedba7efe0d562d268d2825d01b6ec91699ae569 Mon Sep 17 00:00:00 2001 From: weiz Date: Wed, 20 Dec 2023 15:16:42 +0800 Subject: [PATCH] QualityProfessionalCategory --- .../QualityProfessionalCategoryController.php | 108 +++++++++++++++ .../QualityProfessionalCategoryLists.php | 86 ++++++++++++ .../QualityProfessionalCategoryLogic.php | 125 ++++++++++++++++++ .../QualityProfessionalCategoryValidate.php | 115 ++++++++++++++++ .../quality/QualityProfessionalCategory.php | 34 +++++ 5 files changed, 468 insertions(+) create mode 100644 app/adminapi/controller/quality/QualityProfessionalCategoryController.php create mode 100644 app/adminapi/lists/quality/QualityProfessionalCategoryLists.php create mode 100644 app/adminapi/logic/quality/QualityProfessionalCategoryLogic.php create mode 100644 app/adminapi/validate/quality/QualityProfessionalCategoryValidate.php create mode 100644 app/common/model/quality/QualityProfessionalCategory.php diff --git a/app/adminapi/controller/quality/QualityProfessionalCategoryController.php b/app/adminapi/controller/quality/QualityProfessionalCategoryController.php new file mode 100644 index 000000000..a7389a8e4 --- /dev/null +++ b/app/adminapi/controller/quality/QualityProfessionalCategoryController.php @@ -0,0 +1,108 @@ +dataLists(new QualityProfessionalCategoryLists()); + } + + + /** + * @notes 添加专业类别 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function add() + { + $params = (new QualityProfessionalCategoryValidate())->post()->goCheck('add'); + $result = QualityProfessionalCategoryLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(QualityProfessionalCategoryLogic::getError()); + } + + + /** + * @notes 编辑专业类别 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function edit() + { + $params = (new QualityProfessionalCategoryValidate())->post()->goCheck('edit'); + $result = QualityProfessionalCategoryLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(QualityProfessionalCategoryLogic::getError()); + } + + + /** + * @notes 删除专业类别 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function delete() + { + $params = (new QualityProfessionalCategoryValidate())->post()->goCheck('delete'); + QualityProfessionalCategoryLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取专业类别详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function detail() + { + $params = (new QualityProfessionalCategoryValidate())->goCheck('detail'); + $result = QualityProfessionalCategoryLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/quality/QualityProfessionalCategoryLists.php b/app/adminapi/lists/quality/QualityProfessionalCategoryLists.php new file mode 100644 index 000000000..fabc17665 --- /dev/null +++ b/app/adminapi/lists/quality/QualityProfessionalCategoryLists.php @@ -0,0 +1,86 @@ + ['classify_name'], + + ]; + } + + + /** + * @notes 获取专业类别列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function lists(): array + { + return QualityProfessionalCategory::where($this->searchWhere) + ->field(['id', 'org_id', 'dept_id', 'classify_name', 'remark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty(); + $item['org_name'] = $org['name']; + $item['dept_name'] = $dept['name']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取专业类别数量 + * @return int + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function count(): int + { + return QualityProfessionalCategory::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/quality/QualityProfessionalCategoryLogic.php b/app/adminapi/logic/quality/QualityProfessionalCategoryLogic.php new file mode 100644 index 000000000..15181f910 --- /dev/null +++ b/app/adminapi/logic/quality/QualityProfessionalCategoryLogic.php @@ -0,0 +1,125 @@ + $params['org_id'], + 'dept_id' => $params['dept_id'], + 'classify_name' => $params['classify_name'], + 'remark' => $params['remark'], + 'add_user' => $admin_id, + 'update_user' => $admin_id, + ]); + 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/20 14:50 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + QualityProfessionalCategory::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'], + 'dept_id' => $params['dept_id'], + 'classify_name' => $params['classify_name'], + 'remark' => $params['remark'], + 'update_user' => $admin_id, + 'update_time' => time(), + ]); + 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/20 14:50 + */ + public static function delete(array $params): bool + { + return QualityProfessionalCategory::destroy($params['id']); + } + + + /** + * @notes 获取专业类别详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public static function detail($params): array + { + $data = QualityProfessionalCategory::findOrEmpty($params['id'])->toArray(); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id'); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['add_user_name'] = $admin[$data['add_user']]; + $data['update_user_name'] = $admin[$data['update_user']]; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/quality/QualityProfessionalCategoryValidate.php b/app/adminapi/validate/quality/QualityProfessionalCategoryValidate.php new file mode 100644 index 000000000..985428d64 --- /dev/null +++ b/app/adminapi/validate/quality/QualityProfessionalCategoryValidate.php @@ -0,0 +1,115 @@ + 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'classify_name' => 'require', + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'classify_name.require' => '请填写分类名', + ]; + + /** + * @notes 添加场景 + * @return QualityProfessionalCategoryValidate + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return QualityProfessionalCategoryValidate + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return QualityProfessionalCategoryValidate + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return QualityProfessionalCategoryValidate + * @author likeadmin + * @date 2023/12/20 14:50 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkOrg($value): bool|string + { + $data = Orgs::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '组织不存在'; + } + return true; + } + + public function checkDept($value,$rule,$data): bool|string + { + $dept = Dept::where('id',$value)->findOrEmpty(); + if($dept->isEmpty()){ + return '部门不存在'; + } + if($dept['org_id'] != $data['org_id']){ + return '部门不属于当前选择的组织'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/quality/QualityProfessionalCategory.php b/app/common/model/quality/QualityProfessionalCategory.php new file mode 100644 index 000000000..f249ab796 --- /dev/null +++ b/app/common/model/quality/QualityProfessionalCategory.php @@ -0,0 +1,34 @@ +