From fe29d2137a8336da2dbb501572ba1df7d2328514 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 22 Feb 2024 10:19:16 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E4=BB=BB=E5=8A=A1=E7=B1=BB=E5=88=AB-?= =?UTF-8?q?=E5=90=8E=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/task/TaskTypeController.php | 108 ++++++++++++++++ app/adminapi/lists/task/TaskTypeLists.php | 77 ++++++++++++ app/adminapi/logic/task/TaskTypeLogic.php | 118 ++++++++++++++++++ .../validate/task/TaskTypeValidate.php | 94 ++++++++++++++ app/common/model/task/TaskType.php | 34 +++++ 5 files changed, 431 insertions(+) create mode 100644 app/adminapi/controller/task/TaskTypeController.php create mode 100644 app/adminapi/lists/task/TaskTypeLists.php create mode 100644 app/adminapi/logic/task/TaskTypeLogic.php create mode 100644 app/adminapi/validate/task/TaskTypeValidate.php create mode 100644 app/common/model/task/TaskType.php diff --git a/app/adminapi/controller/task/TaskTypeController.php b/app/adminapi/controller/task/TaskTypeController.php new file mode 100644 index 000000000..3c605f942 --- /dev/null +++ b/app/adminapi/controller/task/TaskTypeController.php @@ -0,0 +1,108 @@ +dataLists(new TaskTypeLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function add() + { + $params = (new TaskTypeValidate())->post()->goCheck('add'); + $result = TaskTypeLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(TaskTypeLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function edit() + { + $params = (new TaskTypeValidate())->post()->goCheck('edit'); + $result = TaskTypeLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(TaskTypeLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function delete() + { + $params = (new TaskTypeValidate())->post()->goCheck('delete'); + TaskTypeLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function detail() + { + $params = (new TaskTypeValidate())->goCheck('detail'); + $result = TaskTypeLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/task/TaskTypeLists.php b/app/adminapi/lists/task/TaskTypeLists.php new file mode 100644 index 000000000..88bc275e9 --- /dev/null +++ b/app/adminapi/lists/task/TaskTypeLists.php @@ -0,0 +1,77 @@ + ['num', 'name'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function lists(): array + { + return TaskType::where($this->searchWhere) + ->field(['id', 'dataid', 'project', 'num', 'name', 'superior_sort', 'level', 'remarks']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function count(): int + { + return TaskType::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/task/TaskTypeLogic.php b/app/adminapi/logic/task/TaskTypeLogic.php new file mode 100644 index 000000000..e7172745e --- /dev/null +++ b/app/adminapi/logic/task/TaskTypeLogic.php @@ -0,0 +1,118 @@ + $params['dataid'], + 'project' => $params['project'], + 'num' => $params['num'], + 'name' => $params['name'], + 'superior_sort' => $params['superior_sort'], + 'level' => $params['level'], + 'remarks' => $params['remarks'], + ]); + + 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/02/22 10:06 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + TaskType::where('id', $params['id'])->update([ + 'dataid' => $params['dataid'], + 'project' => $params['project'], + 'num' => $params['num'], + 'name' => $params['name'], + 'superior_sort' => $params['superior_sort'], + 'level' => $params['level'], + 'remarks' => $params['remarks'], + ]); + + 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/02/22 10:06 + */ + public static function delete(array $params): bool + { + return TaskType::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public static function detail($params): array + { + return TaskType::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/task/TaskTypeValidate.php b/app/adminapi/validate/task/TaskTypeValidate.php new file mode 100644 index 000000000..23112665c --- /dev/null +++ b/app/adminapi/validate/task/TaskTypeValidate.php @@ -0,0 +1,94 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return TaskTypeValidate + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return TaskTypeValidate + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return TaskTypeValidate + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return TaskTypeValidate + * @author likeadmin + * @date 2024/02/22 10:06 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/task/TaskType.php b/app/common/model/task/TaskType.php new file mode 100644 index 000000000..cde89dfa1 --- /dev/null +++ b/app/common/model/task/TaskType.php @@ -0,0 +1,34 @@ +