From 8c6701e8e09568bb4b401c0026170501a4baf794 Mon Sep 17 00:00:00 2001 From: xucong <850806214@qq.com> Date: Tue, 20 May 2025 17:37:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=8F=90=E4=BA=A4=E7=BC=BA=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E4=B8=9C=E8=A5=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GoodsCategoryController.php | 108 ++++++++++++++++ app/adminapi/lists/GoodsCategoryLists.php | 77 +++++++++++ app/adminapi/logic/GoodsCategoryLogic.php | 122 ++++++++++++++++++ .../validate/GoodsCategoryValidate.php | 98 ++++++++++++++ app/common/model/GoodsCategory.php | 34 +++++ 5 files changed, 439 insertions(+) create mode 100644 app/adminapi/controller/GoodsCategoryController.php create mode 100644 app/adminapi/lists/GoodsCategoryLists.php create mode 100644 app/adminapi/logic/GoodsCategoryLogic.php create mode 100644 app/adminapi/validate/GoodsCategoryValidate.php create mode 100644 app/common/model/GoodsCategory.php diff --git a/app/adminapi/controller/GoodsCategoryController.php b/app/adminapi/controller/GoodsCategoryController.php new file mode 100644 index 0000000..0179885 --- /dev/null +++ b/app/adminapi/controller/GoodsCategoryController.php @@ -0,0 +1,108 @@ +dataLists(new GoodsCategoryLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function add() + { + $params = (new GoodsCategoryValidate())->post()->goCheck('add'); + $result = GoodsCategoryLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(GoodsCategoryLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function edit() + { + $params = (new GoodsCategoryValidate())->post()->goCheck('edit'); + $result = GoodsCategoryLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(GoodsCategoryLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function delete() + { + $params = (new GoodsCategoryValidate())->post()->goCheck('delete'); + GoodsCategoryLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function detail() + { + $params = (new GoodsCategoryValidate())->goCheck('detail'); + $result = GoodsCategoryLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/GoodsCategoryLists.php b/app/adminapi/lists/GoodsCategoryLists.php new file mode 100644 index 0000000..3e0fb18 --- /dev/null +++ b/app/adminapi/lists/GoodsCategoryLists.php @@ -0,0 +1,77 @@ + ['name', 'pid', 'level', 'sort', 'is_show', 'is_recommend', 'image', 'remark', 'del'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function lists(): array + { + return GoodsCategory::where($this->searchWhere) + ->field(['id', 'name', 'pid', 'level', 'sort', 'is_show', 'is_recommend', 'image', 'remark', 'del']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function count(): int + { + return GoodsCategory::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/GoodsCategoryLogic.php b/app/adminapi/logic/GoodsCategoryLogic.php new file mode 100644 index 0000000..e91173b --- /dev/null +++ b/app/adminapi/logic/GoodsCategoryLogic.php @@ -0,0 +1,122 @@ + $params['name'], + 'pid' => $params['pid'], + 'level' => $params['level'], + 'sort' => $params['sort'], + 'is_show' => $params['is_show'], + 'is_recommend' => $params['is_recommend'], + 'image' => $params['image'], + 'remark' => $params['remark'], + 'del' => $params['del'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + GoodsCategory::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'pid' => $params['pid'], + 'level' => $params['level'], + 'sort' => $params['sort'], + 'is_show' => $params['is_show'], + 'is_recommend' => $params['is_recommend'], + 'image' => $params['image'], + 'remark' => $params['remark'], + 'del' => $params['del'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public static function delete(array $params): bool + { + return GoodsCategory::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public static function detail($params): array + { + return GoodsCategory::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/GoodsCategoryValidate.php b/app/adminapi/validate/GoodsCategoryValidate.php new file mode 100644 index 0000000..1c52589 --- /dev/null +++ b/app/adminapi/validate/GoodsCategoryValidate.php @@ -0,0 +1,98 @@ + 'require', + 'name' => 'require', + 'pid' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '分类名称', + 'pid' => '父级id', + ]; + + + /** + * @notes 添加场景 + * @return GoodsCategoryValidate + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function sceneAdd() + { + return $this->only(['name','pid']); + } + + + /** + * @notes 编辑场景 + * @return GoodsCategoryValidate + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function sceneEdit() + { + return $this->only(['id','name','pid']); + } + + + /** + * @notes 删除场景 + * @return GoodsCategoryValidate + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return GoodsCategoryValidate + * @author likeadmin + * @date 2025/05/20 17:35 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/GoodsCategory.php b/app/common/model/GoodsCategory.php new file mode 100644 index 0000000..1766eb8 --- /dev/null +++ b/app/common/model/GoodsCategory.php @@ -0,0 +1,34 @@ +