diff --git a/app/admin/controller/system_store/SystemStoreController.php b/app/admin/controller/system_store/SystemStoreController.php new file mode 100644 index 000000000..c01ef820e --- /dev/null +++ b/app/admin/controller/system_store/SystemStoreController.php @@ -0,0 +1,95 @@ +<?php + +namespace app\admin\controller\system_store; + + +use app\admin\controller\BaseAdminController; +use app\admin\lists\system_store\SystemStoreLists; +use app\admin\logic\system_store\SystemStoreLogic; +use app\admin\validate\system_store\SystemStoreValidate; + + +/** + * 门店列表控制器 + * Class SystemStoreController + * @package app\admin\controller\system_store + */ +class SystemStoreController extends BaseAdminController +{ + + + /** + * @notes 获取门店列表列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function lists() + { + return $this->dataLists(new SystemStoreLists()); + } + + + /** + * @notes 添加门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function add() + { + $params = (new SystemStoreValidate())->post()->goCheck('add'); + $result = SystemStoreLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SystemStoreLogic::getError()); + } + + + /** + * @notes 编辑门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function edit() + { + $params = (new SystemStoreValidate())->post()->goCheck('edit'); + $result = SystemStoreLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SystemStoreLogic::getError()); + } + + + /** + * @notes 删除门店列表 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function delete() + { + $params = (new SystemStoreValidate())->post()->goCheck('delete'); + SystemStoreLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取门店列表详情 + * @return \think\response\Json + * @author admin + * @date 2024/05/31 17:45 + */ + public function detail() + { + $params = (new SystemStoreValidate())->goCheck('detail'); + $result = SystemStoreLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/system_store/SystemStoreLists.php b/app/admin/lists/system_store/SystemStoreLists.php new file mode 100644 index 000000000..e10aaa4fc --- /dev/null +++ b/app/admin/lists/system_store/SystemStoreLists.php @@ -0,0 +1,65 @@ +<?php + +namespace app\admin\lists\system_store; + + +use app\admin\lists\BaseAdminDataLists; +use app\common\model\system_store\SystemStore; +use app\common\lists\ListsSearchInterface; + + +/** + * 门店列表列表 + * Class SystemStoreLists + * @package app\admin\listssystem_store + */ +class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterface +{ + + + /** + * @notes 设置搜索条件 + * @return \string[][] + * @author admin + * @date 2024/05/31 17:45 + */ + public function setSearch(): array + { + return [ + '=' => ['name', 'phone'], + ]; + } + + + /** + * @notes 获取门店列表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2024/05/31 17:45 + */ + public function lists(): array + { + return SystemStore::where($this->searchWhere) + ->field(['id', 'name', 'phone', 'detailed_address', 'image', 'is_show']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取门店列表数量 + * @return int + * @author admin + * @date 2024/05/31 17:45 + */ + public function count(): int + { + return SystemStore::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/system_store/SystemStoreLogic.php b/app/admin/logic/system_store/SystemStoreLogic.php new file mode 100644 index 000000000..42a601854 --- /dev/null +++ b/app/admin/logic/system_store/SystemStoreLogic.php @@ -0,0 +1,106 @@ +<?php + +namespace app\admin\logic\system_store; + + +use app\common\model\system_store\SystemStore; +use app\common\logic\BaseLogic; +use think\facade\Db; + + +/** + * 门店列表逻辑 + * Class SystemStoreLogic + * @package app\admin\logic\system_store + */ +class SystemStoreLogic extends BaseLogic +{ + + + /** + * @notes 添加门店列表 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 17:45 + */ + public static function add(array $params): bool + { + Db::startTrans(); + try { + SystemStore::create([ + 'name' => $params['name'], + 'introduction' => $params['introduction'], + 'phone' => $params['phone'], + 'detailed_address' => $params['detailed_address'], + 'image' => $params['image'], + 'is_show' => $params['is_show'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑门店列表 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 17:45 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + SystemStore::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'introduction' => $params['introduction'], + 'phone' => $params['phone'], + 'detailed_address' => $params['detailed_address'], + 'image' => $params['image'], + 'latitude' => $params['latitude'], + 'longitude' => $params['longitude'], + 'is_show' => $params['is_show'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除门店列表 + * @param array $params + * @return bool + * @author admin + * @date 2024/05/31 17:45 + */ + public static function delete(array $params): bool + { + return SystemStore::destroy($params['id']); + } + + + /** + * @notes 获取门店列表详情 + * @param $params + * @return array + * @author admin + * @date 2024/05/31 17:45 + */ + public static function detail($params): array + { + return SystemStore::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/system_store/SystemStoreValidate.php b/app/admin/validate/system_store/SystemStoreValidate.php new file mode 100644 index 000000000..a3590881c --- /dev/null +++ b/app/admin/validate/system_store/SystemStoreValidate.php @@ -0,0 +1,94 @@ +<?php + +namespace app\admin\validate\system_store; + + +use app\common\validate\BaseValidate; + + +/** + * 门店列表验证器 + * Class SystemStoreValidate + * @package app\admin\validate\system_store + */ +class SystemStoreValidate extends BaseValidate +{ + + /** + * 设置校验规则 + * @var string[] + */ + protected $rule = [ + 'id' => 'require', + 'name' => 'require', + 'phone' => 'require', + 'detailed_address' => 'require', + 'image' => 'require', + 'latitude' => 'require', + 'longitude' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '门店名称', + 'phone' => '手机号码', + 'detailed_address' => '详细地址', + 'image' => '门店logo', + 'latitude' => '纬度', + 'longitude' => '经度', + ]; + + + /** + * @notes 添加场景 + * @return SystemStoreValidate + * @author admin + * @date 2024/05/31 17:45 + */ + public function sceneAdd() + { + return $this->only(['name','phone','detailed_address','image','latitude','longitude']); + } + + + /** + * @notes 编辑场景 + * @return SystemStoreValidate + * @author admin + * @date 2024/05/31 17:45 + */ + public function sceneEdit() + { + return $this->only(['id','name','phone','detailed_address','image','latitude','longitude']); + } + + + /** + * @notes 删除场景 + * @return SystemStoreValidate + * @author admin + * @date 2024/05/31 17:45 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SystemStoreValidate + * @author admin + * @date 2024/05/31 17:45 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/system_store/SystemStore.php b/app/common/model/system_store/SystemStore.php new file mode 100644 index 000000000..ac1c4345b --- /dev/null +++ b/app/common/model/system_store/SystemStore.php @@ -0,0 +1,22 @@ +<?php + +namespace app\common\model\system_store; + + +use app\common\model\BaseModel; +use think\model\concern\SoftDelete; + + +/** + * 门店列表模型 + * Class SystemStore + * @package app\common\model\system_store + */ +class SystemStore extends BaseModel +{ + use SoftDelete; + protected $name = 'system_store'; + protected $deleteTime = 'delete_time'; + + +} \ No newline at end of file