diff --git a/app/adminapi/controller/ShopMerchantController.php b/app/adminapi/controller/ShopMerchantController.php new file mode 100644 index 000000000..011080859 --- /dev/null +++ b/app/adminapi/controller/ShopMerchantController.php @@ -0,0 +1,108 @@ +dataLists(new ShopMerchantLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function add() + { + $params = (new ShopMerchantValidate())->post()->goCheck('add'); + $result = ShopMerchantLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ShopMerchantLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function edit() + { + $params = (new ShopMerchantValidate())->post()->goCheck('edit'); + $result = ShopMerchantLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ShopMerchantLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function delete() + { + $params = (new ShopMerchantValidate())->post()->goCheck('delete'); + ShopMerchantLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function detail() + { + $params = (new ShopMerchantValidate())->goCheck('detail'); + $result = ShopMerchantLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/ShopMerchantLists.php b/app/adminapi/lists/ShopMerchantLists.php new file mode 100644 index 000000000..c4f479652 --- /dev/null +++ b/app/adminapi/lists/ShopMerchantLists.php @@ -0,0 +1,77 @@ + ['company_name', 'master_name', 'master_phone'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function lists(): array + { + return ShopMerchant::where($this->searchWhere) + ->field(['id', 'company_name', 'organization_code', 'master_name', 'master_phone']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function count(): int + { + return ShopMerchant::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/ShopMerchantLogic.php b/app/adminapi/logic/ShopMerchantLogic.php new file mode 100644 index 000000000..f625bb5a7 --- /dev/null +++ b/app/adminapi/logic/ShopMerchantLogic.php @@ -0,0 +1,106 @@ +getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ShopMerchant::where('id', $params['id'])->update([ + + ]); + + 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/09/13 16:45 + */ + public static function delete(array $params): bool + { + return ShopMerchant::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public static function detail($params): array + { + return ShopMerchant::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/ShopMerchantValidate.php b/app/adminapi/validate/ShopMerchantValidate.php new file mode 100644 index 000000000..bea8edd96 --- /dev/null +++ b/app/adminapi/validate/ShopMerchantValidate.php @@ -0,0 +1,94 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ShopMerchantValidate + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ShopMerchantValidate + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ShopMerchantValidate + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ShopMerchantValidate + * @author likeadmin + * @date 2023/09/13 16:45 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file