From 0371af159d38a46c4a184809b6861b0fa8cf7d1a Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 31 Jul 2023 14:02:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E6=9C=BA=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CategoryBusinessController.php | 106 +++++++++++++++++ .../CategoryBusinessLists.php | 77 ++++++++++++ .../CategoryBusinessLogic.php | 112 ++++++++++++++++++ .../CategoryBusinessValidate.php | 102 ++++++++++++++++ .../category_business/CategoryBusiness.php | 34 ++++++ 5 files changed, 431 insertions(+) create mode 100644 app/adminapi/controller/category_business/CategoryBusinessController.php create mode 100644 app/adminapi/lists/category_business/CategoryBusinessLists.php create mode 100644 app/adminapi/logic/category_business/CategoryBusinessLogic.php create mode 100644 app/adminapi/validate/category_business/CategoryBusinessValidate.php create mode 100644 app/common/model/category_business/CategoryBusiness.php diff --git a/app/adminapi/controller/category_business/CategoryBusinessController.php b/app/adminapi/controller/category_business/CategoryBusinessController.php new file mode 100644 index 000000000..459e3c699 --- /dev/null +++ b/app/adminapi/controller/category_business/CategoryBusinessController.php @@ -0,0 +1,106 @@ +dataLists(new CategoryBusinessLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function add() + { + $params = (new CategoryBusinessValidate())->post()->goCheck('add'); + $result = CategoryBusinessLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(CategoryBusinessLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function edit() + { + $params = (new CategoryBusinessValidate())->post()->goCheck('edit'); + $result = CategoryBusinessLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(CategoryBusinessLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function delete() + { + $params = (new CategoryBusinessValidate())->post()->goCheck('delete'); + CategoryBusinessLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function detail() + { + $params = (new CategoryBusinessValidate())->goCheck('detail'); + $result = CategoryBusinessLogic::detail($params); + return $this->data($result); + } +} \ No newline at end of file diff --git a/app/adminapi/lists/category_business/CategoryBusinessLists.php b/app/adminapi/lists/category_business/CategoryBusinessLists.php new file mode 100644 index 000000000..155a753e7 --- /dev/null +++ b/app/adminapi/lists/category_business/CategoryBusinessLists.php @@ -0,0 +1,77 @@ + ['name', 'sort', 'status','pid'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function lists(): array + { + return CategoryBusiness::where($this->searchWhere) + ->field(['id', 'name', 'pid', 'sort', 'status']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function count(): int + { + return CategoryBusiness::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/category_business/CategoryBusinessLogic.php b/app/adminapi/logic/category_business/CategoryBusinessLogic.php new file mode 100644 index 000000000..94e42f293 --- /dev/null +++ b/app/adminapi/logic/category_business/CategoryBusinessLogic.php @@ -0,0 +1,112 @@ + $params['name'], + 'pid' => $params['pid'], + 'sort' => $params['sort'], + '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 2023/07/31 11:21 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + CategoryBusiness::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'pid' => $params['pid'], + 'sort' => $params['sort'], + '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 2023/07/31 11:21 + */ + public static function delete(array $params): bool + { + return CategoryBusiness::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public static function detail($params): array + { + return CategoryBusiness::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/category_business/CategoryBusinessValidate.php b/app/adminapi/validate/category_business/CategoryBusinessValidate.php new file mode 100644 index 000000000..04945aab2 --- /dev/null +++ b/app/adminapi/validate/category_business/CategoryBusinessValidate.php @@ -0,0 +1,102 @@ + 'require', + 'name' => 'require', + 'pid' => 'require', + 'sort' => 'require', + 'status' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '名称', + 'pid' => '上级id', + 'sort' => '排序', + 'status' => '状态(0停用 1正常)', + ]; + + + /** + * @notes 添加场景 + * @return CategoryBusinessValidate + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function sceneAdd() + { + return $this->only(['name','pid','sort','status']); + } + + + /** + * @notes 编辑场景 + * @return CategoryBusinessValidate + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function sceneEdit() + { + return $this->only(['id','name','pid','sort','status']); + } + + + /** + * @notes 删除场景 + * @return CategoryBusinessValidate + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return CategoryBusinessValidate + * @author likeadmin + * @date 2023/07/31 11:21 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/category_business/CategoryBusiness.php b/app/common/model/category_business/CategoryBusiness.php new file mode 100644 index 000000000..35e6a50b8 --- /dev/null +++ b/app/common/model/category_business/CategoryBusiness.php @@ -0,0 +1,34 @@ +