From 2d8f35ddf0d2cb80384ff27821b08ee3f3b33772 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Thu, 31 Oct 2024 16:52:32 +0800 Subject: [PATCH] feat : city --- app/Cache/Redis/Common/CityCache.php | 6 +-- app/Constants/Common/CityCode.php | 7 +++ app/Controller/Admin/ConfigController.php | 28 ++++++++++++ app/Service/System/SystemService.php | 56 +++++++++++++++++++++++ sync/http/admin/address.http | 6 +++ 5 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 app/Service/System/SystemService.php diff --git a/app/Cache/Redis/Common/CityCache.php b/app/Cache/Redis/Common/CityCache.php index 849c3cf..f326c81 100644 --- a/app/Cache/Redis/Common/CityCache.php +++ b/app/Cache/Redis/Common/CityCache.php @@ -33,9 +33,9 @@ class CityCache public function getCityList(int $deep = -1): array { $type = match ($deep) { - 1 => 'province', - 2 => 'city', - 3 => 'district', + 0 => 'province', + 1 => 'city', + 2 => 'district', default => 'all', }; diff --git a/app/Constants/Common/CityCode.php b/app/Constants/Common/CityCode.php index a8a039b..9f7e7f0 100644 --- a/app/Constants/Common/CityCode.php +++ b/app/Constants/Common/CityCode.php @@ -23,4 +23,11 @@ class CityCode * 不删除 */ const IS_NOT_DELETE = 1; + + /** + * 深度 0 省 1 市 2 区 + */ + const DEEP_PROVINCE = 0; + const DEEP_CITY = 1; + const DEEP_DISTRICT = 2; } \ No newline at end of file diff --git a/app/Controller/Admin/ConfigController.php b/app/Controller/Admin/ConfigController.php index cd5c7e7..e3cc0b3 100644 --- a/app/Controller/Admin/ConfigController.php +++ b/app/Controller/Admin/ConfigController.php @@ -5,22 +5,50 @@ declare(strict_types=1); namespace App\Controller\Admin; use App\Controller\AbstractController; +use App\Middleware\Admin\JwtAuthMiddleware; use App\Service\Admin\System\ConfigService; +use App\Service\System\SystemService; +use Hyperf\HttpServer\Annotation\Controller; +use Hyperf\HttpServer\Annotation\Middlewares; +use Hyperf\HttpServer\Annotation\RequestMapping; +use Hyperf\Validation\Annotation\Scene; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; +use RedisException; +#[Controller(prefix: "admin/config")] +#[Middlewares([ + JwtAuthMiddleware::class, +])] class ConfigController extends AbstractController { + #[RequestMapping(path: "module", methods: "GET")] public function getConfigModule() { return (new ConfigService)->getConfigModule(); } + #[RequestMapping(path: "form", methods: "GET")] public function getConfigForm() { return (new ConfigService)->getConfigForm(); } + #[RequestMapping(path: "update", methods: "POST")] public function updateConfig() { return (new ConfigService)->handle(); } + + /** + * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws RedisException + */ + #[RequestMapping(path: "system/address_list", methods: "GET")] + public function getAddressList() + { + return (new SystemService)->address_list(); + } } diff --git a/app/Service/System/SystemService.php b/app/Service/System/SystemService.php new file mode 100644 index 0000000..242fc5d --- /dev/null +++ b/app/Service/System/SystemService.php @@ -0,0 +1,56 @@ +return->success(); + } + + /** + * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws RedisException + */ + public function address_list(): array + { + $deep = (int)$this->request->input('deep'); + $pid = $this->request->input('pid',0); + + $deepList = $this->cityCache->getCityList($deep); + + if (in_array($deep,[CityCode::DEEP_CITY,CityCode::DEEP_PROVINCE]) && $pid != 0) { + $column = 'pid'; + $filteredData = array_values(array_filter($deepList, function($value) use ($column, $pid) { + return $value[$column] == $pid; + })); + } + + return $this->return->success('success', ['list' => $filteredData ?? $deepList]); + } +} \ No newline at end of file diff --git a/sync/http/admin/address.http b/sync/http/admin/address.http index 95b5f92..8546bd4 100644 --- a/sync/http/admin/address.http +++ b/sync/http/admin/address.http @@ -35,3 +35,9 @@ Authorization: Bearer {{admin_token}} GET {{host}}/admin/city/del?id=1 Content-Type: application/json Authorization: Bearer {{admin_token}} + +###城市列表 - 联表数据 +GET {{host}}/admin/config/system/address_list?deep=1&pid=82 +Content-Type: application/json +Authorization: Bearer {{admin_token}} +