From c491fb79d8da963b11287808ad8830fe72b2e1e8 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Fri, 8 Nov 2024 16:27:25 +0800 Subject: [PATCH] feat : kitchen --- app/Aspect/Admin/AdminLoginLogAspect.php | 2 +- app/Aspect/Admin/AdminOperationAspect.php | 41 ++-- app/Cache/Redis/Common/CommonRedisKey.php | 9 + app/Cache/Redis/RedisCache.php | 52 ++++- app/Constants/Common/SiteCode.php | 56 ++++++ app/Controller/Admin/KitchenController.php | 55 ++++++ app/Controller/Admin/SiteController.php | 55 ++++++ app/Model/Kitchen.php | 63 ++++++ app/Model/Site.php | 65 +++++++ app/Model/SystemCity.php | 9 + app/Request/Admin/KitchenRequest.php | 50 +++++ app/Request/Admin/SiteRequest.php | 28 +++ app/Service/Admin/System/KitchenService.php | 184 ++++++++++++++++++ app/Service/Admin/System/SiteService.php | 41 ++++ app/Service/ServiceTrait/Common/SiteTrait.php | 42 ++++ 15 files changed, 727 insertions(+), 25 deletions(-) create mode 100644 app/Constants/Common/SiteCode.php create mode 100644 app/Controller/Admin/KitchenController.php create mode 100644 app/Controller/Admin/SiteController.php create mode 100644 app/Model/Kitchen.php create mode 100644 app/Model/Site.php create mode 100644 app/Request/Admin/KitchenRequest.php create mode 100644 app/Request/Admin/SiteRequest.php create mode 100644 app/Service/Admin/System/KitchenService.php create mode 100644 app/Service/Admin/System/SiteService.php create mode 100644 app/Service/ServiceTrait/Common/SiteTrait.php diff --git a/app/Aspect/Admin/AdminLoginLogAspect.php b/app/Aspect/Admin/AdminLoginLogAspect.php index e875d04..c45f963 100644 --- a/app/Aspect/Admin/AdminLoginLogAspect.php +++ b/app/Aspect/Admin/AdminLoginLogAspect.php @@ -44,7 +44,7 @@ class AdminLoginLogAspect extends AbstractAspect return $result; } catch (AdminException $e) { - var_dump($e->getMessage()); +// var_dump($e->getMessage()); throw new AdminException($e->getMessage()); } } diff --git a/app/Aspect/Admin/AdminOperationAspect.php b/app/Aspect/Admin/AdminOperationAspect.php index 7aefdb9..051e960 100644 --- a/app/Aspect/Admin/AdminOperationAspect.php +++ b/app/Aspect/Admin/AdminOperationAspect.php @@ -23,8 +23,7 @@ class AdminOperationAspect extends AbstractAspect public array $classes = [ 'App\\Service\\Admin\\User\\*Service', 'App\\Service\\Admin\\Third\\*Service', - 'App\Service\Admin\System\CityService', - 'App\Service\Admin\System\ConfigService', + 'App\\Service\\Admin\\System\\*Service', ]; /** @@ -47,7 +46,7 @@ class AdminOperationAspect extends AbstractAspect public function process(ProceedingJoinPoint $proceedingJoinPoint): mixed { // 鉴权 - $this->checkAuthentication(); +// $this->checkAuthentication(); // 写操作日志 $this->writeOperationLog(); @@ -56,24 +55,24 @@ class AdminOperationAspect extends AbstractAspect return $proceedingJoinPoint->process(); } - /** - * @return void - */ - private function checkAuthentication(): void - { - $adminId = Context::get('admin_id'); - $roleId = Context::get('role_id'); - - //如果没有id 说明没有登录 抛出异常 - if (empty($adminId) || empty($roleId)) { - throw new AdminException('请先登录'); - } - - //超级管理员不需要鉴权 - if ($roleId == 1) return; - - //todo 其他角色需要鉴权 - } +// /** +// * @return void +// */ +// private function checkAuthentication(): void +// { +// $adminId = Context::get('admin_id'); +// $roleId = Context::get('role_id'); +// +// //如果没有id 说明没有登录 抛出异常 +// if (empty($adminId) || empty($roleId)) { +// throw new AdminException('请先登录'); +// } +// +// //超级管理员不需要鉴权 +// if ($roleId == 1) return; +// +// //其他角色需要鉴权 +// } /** * 写入请求日志 diff --git a/app/Cache/Redis/Common/CommonRedisKey.php b/app/Cache/Redis/Common/CommonRedisKey.php index 92e7351..8312f79 100644 --- a/app/Cache/Redis/Common/CommonRedisKey.php +++ b/app/Cache/Redis/Common/CommonRedisKey.php @@ -30,4 +30,13 @@ class CommonRedisKey { return '__system:deleteOssImgList:oss_id'; } + + /** + * 获取激活的站点列表 + * @return string + */ + public static function getActivateSiteList(): string + { + return '__system:activate:site:list'; + } } \ No newline at end of file diff --git a/app/Cache/Redis/RedisCache.php b/app/Cache/Redis/RedisCache.php index 9784d94..60508ea 100644 --- a/app/Cache/Redis/RedisCache.php +++ b/app/Cache/Redis/RedisCache.php @@ -492,17 +492,63 @@ class RedisCache * 加入有序集合 * @param $key * @param $score + * @param $value * @param string $poolName - * @param ...$value * @return false|int|Redis * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws RedisException */ - public function zAdd($key, $score, string $poolName = 'default', ...$value) + public function zAdd($key, $score, $value, string $poolName = 'default'): false|int|Redis { - return $this->getRedis($poolName)->zAdd($key, $score, ...$value); + return $this->getRedis($poolName)->zAdd($key, $score, $value); } + /** + * @param $key + * @param $value + * @param string $poolName + * @return false|int|Redis + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws RedisException + */ + public function zRem($key, $value, string $poolName = 'default'): false|int|Redis + { + return $this->getRedis($poolName)->zRem($key, $value); + } + // +-------------------------------------------------------------------------------------------------------------------------------------------- + // | geo + // +-------------------------------------------------------------------------------------------------------------------------------------------- + /** + * @param $key + * @param $lng + * @param $lat + * @param $value + * @param string $poolName + * @return false|int|Redis + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws RedisException + */ + public function geoAdd($key, $lng, $lat, $value, string $poolName = 'default'): false|int|Redis + { + return $this->getRedis($poolName)->geoAdd($key, $lng, $lat, $value); + } + /** + * @param $key + * @param $value1 + * @param $value2 + * @param string $unit [m|km|ft|mi] + * @param string $poolName + * @return false|int|Redis + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws RedisException + */ + public function geoDist($key, $value1, $value2, string $unit = 'km', string $poolName = 'default'): false|int|Redis + { + return $this->getRedis($poolName)->geoDist($key, $value1, $value2, $unit); + } } \ No newline at end of file diff --git a/app/Constants/Common/SiteCode.php b/app/Constants/Common/SiteCode.php new file mode 100644 index 0000000..ddb3fe8 --- /dev/null +++ b/app/Constants/Common/SiteCode.php @@ -0,0 +1,56 @@ +add(); + } + + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "edit")] + public function edit(KitchenRequest $request) + { + return (new KitchenService)->edit(); + } + + #[RequestMapping(path: "del", methods: "GET")] + #[Scene(scene: "del")] + public function del(KitchenRequest $request) + { + return (new KitchenService)->del(); + } + + #[RequestMapping(path: "list", methods: "GET")] + #[Scene(scene: "list")] + public function list(KitchenRequest $request) + { + return (new KitchenService)->handle(); + } + + #[RequestMapping(path: "info", methods: "GET")] + #[Scene(scene: "info")] + public function info(KitchenRequest $request) + { + return (new KitchenService)->info(); + } +} diff --git a/app/Controller/Admin/SiteController.php b/app/Controller/Admin/SiteController.php new file mode 100644 index 0000000..7057033 --- /dev/null +++ b/app/Controller/Admin/SiteController.php @@ -0,0 +1,55 @@ +add(); + } + + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "edit")] + public function edit(SiteRequest $request) + { + return (new SiteService)->edit(); + } + + #[RequestMapping(path: "del", methods: "GET")] + #[Scene(scene: "del")] + public function del(SiteRequest $request) + { + return (new SiteService)->del(); + } + + #[RequestMapping(path: "list", methods: "GET")] + #[Scene(scene: "list")] + public function list(SiteRequest $request) + { + return (new SiteService)->handle(); + } + + #[RequestMapping(path: "info", methods: "GET")] + #[Scene(scene: "info")] + public function info(SiteRequest $request) + { + return (new SiteService)->info(); + } +} diff --git a/app/Model/Kitchen.php b/app/Model/Kitchen.php new file mode 100644 index 0000000..1da4060 --- /dev/null +++ b/app/Model/Kitchen.php @@ -0,0 +1,63 @@ + 'integer', 'city_id' => 'integer', 'status' => 'integer']; + + const string CREATED_AT = 'create_time'; + + const string UPDATED_AT = 'update_time'; + + /** + * @param string $name + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoByName(string $name): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('name', $name)->where('is_del',SiteCode::KITCHEN_NO_DEL)->first(); + } + + /** + * @param int $id + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getInfoById(int $id): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('id',$id)->where('is_del',SiteCode::KITCHEN_NO_DEL)->first(); + } +} diff --git a/app/Model/Site.php b/app/Model/Site.php new file mode 100644 index 0000000..65fc9b7 --- /dev/null +++ b/app/Model/Site.php @@ -0,0 +1,65 @@ + 'integer', 'pid' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'status' => 'integer', 'image_id' => 'integer', 'delivered_id' => 'integer', 'is_del' => 'integer']; + + const string CREATED_AT = 'create_time'; + + const string UPDATED_AT = 'update_time'; + + /** + * 禁用厨房下所有点 + * @param int $kitchenId + * @return int + */ + public function disableStatusByKitchenId(int $kitchenId) + { + return $this + ->where('kitchen_id',$kitchenId) + ->where('is_del',SiteCode::SITE_NO_DEL) + ->update(['status' => SiteCode::SITE_DISABLE]); + } +} diff --git a/app/Model/SystemCity.php b/app/Model/SystemCity.php index 54dd599..3f8d7ee 100644 --- a/app/Model/SystemCity.php +++ b/app/Model/SystemCity.php @@ -58,4 +58,13 @@ class SystemCity extends Model { return $this->where('id', $id)->where('is_del',CityCode::IS_NOT_DELETE)->first(); } + + /** + * @param $ids + * @return array + */ + public function getCityNameByIds($ids): array + { + return $this->whereIn('id',$ids)->pluck('title','id')->toArray(); + } } diff --git a/app/Request/Admin/KitchenRequest.php b/app/Request/Admin/KitchenRequest.php new file mode 100644 index 0000000..6a5448e --- /dev/null +++ b/app/Request/Admin/KitchenRequest.php @@ -0,0 +1,50 @@ + 'required', + 'city_id' => 'required|integer|exists:system_city,id', + 'status' => 'required|integer|in:1,2', + 'address' => 'required|string', + 'lng' => 'required|string', + 'lat' => 'required|string', + 'id' => 'required|integer', + 'limit' => 'required|integer', + ]; + } + + public function messages(): array + { + return [ + + ]; + } + + protected array $scenes = [ + 'add' => ['name', 'city_id', 'status', 'address', 'lng', 'lat'], + 'edit' => ['name', 'city_id', 'status', 'address', 'lng', 'lat','id'], + 'del' => ['id'], + 'info' => ['id'], + 'list' => ['limit'], + ]; +} diff --git a/app/Request/Admin/SiteRequest.php b/app/Request/Admin/SiteRequest.php new file mode 100644 index 0000000..28d61a5 --- /dev/null +++ b/app/Request/Admin/SiteRequest.php @@ -0,0 +1,28 @@ +request->input('limit', 10); + + $this->getWhere(); + + if (empty($this->where)) { + $data = $this->kitchenModel->orderBy('id','desc')->paginate($limit)->toArray(); + }else{ + $data = $this->kitchenModel->orderBy('id','desc')->where($this->where)->paginate($limit)->toArray(); + } + + $cityId = array_unique(array_column($data['data'],'city_id')); + $cityName = $this->systemCityModel->getCityNameByIds($cityId); + + foreach ($data['data'] as &$one) { + $one['city_name'] = $cityName[$one['city_id']] ?? ''; + } + + return $this->return->success(); + } + + /** + * @return void + */ + private function getWhere(): void + { + $this->where[] = ['is_del','=',SiteCode::KITCHEN_NO_DEL]; + + if ($this->request->input('city_id',0) > 0) { + $this->where[] = ['city_id', '=', $this->request->input('city_id')]; + } + } + + /** + * @return array + */ + public function add(): array + { + $name = $this->request->input('name'); + + $info = $this->kitchenModel->getInfoByName($name); + if (!empty($info)) throw new AdminException('数据已存在'); + + $model = new Kitchen(); + + $model->name = $this->request->input('name'); + $model->city_id = $this->request->input('city_id'); + $model->address = $this->request->input('address'); + $model->lng = $this->request->input('lng'); + $model->lat = $this->request->input('lat'); + $model->status = $this->request->input('status'); + + if (!$model->save()) throw new AdminException('添加失败'); + +// if ($model->status == SiteCode::KITCHEN_ENABLE) { +// $this->setSiteCache(SiteCode::KITCHEN_REDIS_PREFIX.$model->id,$model->lng,$model->lat); +// } + + return $this->return->success(); + } + + /** + * @return array + */ + public function edit(): array + { + $id = (int)$this->request->input('id'); + $name = $this->request->input('name'); + $status = (int)$this->request->input('status'); + + $info = $this->kitchenModel->getInfoById($id); + if (empty($info)) throw new AdminException('数据不存在'); + + $name = $this->kitchenModel->getInfoByName($name); + if ($name->id != $info->id) throw new AdminException('数据已存在'); + + if ($info->status == SiteCode::KITCHEN_ENABLE && $status == SiteCode::KITCHEN_DISABLE) { + $this->siteModel->disableStatusByKitchenId($info->id); + } + + $info->name = $this->request->input('name'); + $info->address = $this->request->input('address'); + $info->lng = $this->request->input('lng'); + $info->lat = $this->request->input('lat'); + $info->status = $status; + + if (!$info->save()) throw new AdminException('修改失败'); + + return $this->return->success(); + } + + /** + * @return array + * @throws Exception + */ + public function del(): array + { + $id = (int)$this->request->input('id'); + + $info = $this->kitchenModel->getInfoById($id); + if (empty($info)) throw new AdminException('数据不存在'); + + $this->siteModel->disableStatusByKitchenId($info->id); + + $info->is_del = SiteCode::SITE_DEL; + + if (!$info->save()) throw new AdminException('删除失败'); + + return $this->return->success(); + } + + /** + * @return array + */ + public function info(): array + { + $data = $this + ->kitchenModel + ->where('id', $this->request->input('id')) + ->where('is_del', SiteCode::KITCHEN_NO_DEL) + ->first(['id','city_id','name','address','lng','lat','status']); + if (empty($data)) throw new AdminException('数据不存在'); + + $res = $data->toArray(); + $res['city_name'] = $this->systemCityModel->where('id',$data->city_id)->value('title'); + + return $this->return->success('success', $res); + } +} \ No newline at end of file diff --git a/app/Service/Admin/System/SiteService.php b/app/Service/Admin/System/SiteService.php new file mode 100644 index 0000000..641e7a2 --- /dev/null +++ b/app/Service/Admin/System/SiteService.php @@ -0,0 +1,41 @@ +return->success(); + } + + public function add() + { + return $this->return->success(); + } + + public function edit() + { + return $this->return->success(); + } + + public function del() + { + return $this->return->success(); + } + + public function info() + { + + } +} \ No newline at end of file diff --git a/app/Service/ServiceTrait/Common/SiteTrait.php b/app/Service/ServiceTrait/Common/SiteTrait.php new file mode 100644 index 0000000..3d3f8c4 --- /dev/null +++ b/app/Service/ServiceTrait/Common/SiteTrait.php @@ -0,0 +1,42 @@ +redisCache->zRem($key,$value,'system'); + $this->redisCache->geoAdd($key,$lng,$lat,$value,'system'); + } +} \ No newline at end of file