feat : city
This commit is contained in:
@@ -33,9 +33,9 @@ class CityCache
|
|||||||
public function getCityList(int $deep = -1): array
|
public function getCityList(int $deep = -1): array
|
||||||
{
|
{
|
||||||
$type = match ($deep) {
|
$type = match ($deep) {
|
||||||
1 => 'province',
|
0 => 'province',
|
||||||
2 => 'city',
|
1 => 'city',
|
||||||
3 => 'district',
|
2 => 'district',
|
||||||
default => 'all',
|
default => 'all',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,4 +23,11 @@ class CityCode
|
|||||||
* 不删除
|
* 不删除
|
||||||
*/
|
*/
|
||||||
const IS_NOT_DELETE = 1;
|
const IS_NOT_DELETE = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 深度 0 省 1 市 2 区
|
||||||
|
*/
|
||||||
|
const DEEP_PROVINCE = 0;
|
||||||
|
const DEEP_CITY = 1;
|
||||||
|
const DEEP_DISTRICT = 2;
|
||||||
}
|
}
|
||||||
@@ -5,22 +5,50 @@ declare(strict_types=1);
|
|||||||
namespace App\Controller\Admin;
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
use App\Controller\AbstractController;
|
use App\Controller\AbstractController;
|
||||||
|
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||||
use App\Service\Admin\System\ConfigService;
|
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
|
class ConfigController extends AbstractController
|
||||||
{
|
{
|
||||||
|
#[RequestMapping(path: "module", methods: "GET")]
|
||||||
public function getConfigModule()
|
public function getConfigModule()
|
||||||
{
|
{
|
||||||
return (new ConfigService)->getConfigModule();
|
return (new ConfigService)->getConfigModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[RequestMapping(path: "form", methods: "GET")]
|
||||||
public function getConfigForm()
|
public function getConfigForm()
|
||||||
{
|
{
|
||||||
return (new ConfigService)->getConfigForm();
|
return (new ConfigService)->getConfigForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[RequestMapping(path: "update", methods: "POST")]
|
||||||
public function updateConfig()
|
public function updateConfig()
|
||||||
{
|
{
|
||||||
return (new ConfigService)->handle();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
56
app/Service/System/SystemService.php
Normal file
56
app/Service/System/SystemService.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This service file is part of item.
|
||||||
|
*
|
||||||
|
* @author ctexthuang
|
||||||
|
* @contact ctexthuang@qq.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\System;
|
||||||
|
|
||||||
|
use App\Cache\Redis\Common\CityCache;
|
||||||
|
use App\Constants\Common\CityCode;
|
||||||
|
use App\Service\Admin\BaseService;
|
||||||
|
use Hyperf\Di\Annotation\Inject;
|
||||||
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
use RedisException;
|
||||||
|
|
||||||
|
class SystemService extends BaseService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var CityCache
|
||||||
|
*/
|
||||||
|
#[Inject]
|
||||||
|
protected CityCache $cityCache;
|
||||||
|
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
return $this->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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,3 +35,9 @@ Authorization: Bearer {{admin_token}}
|
|||||||
GET {{host}}/admin/city/del?id=1
|
GET {{host}}/admin/city/del?id=1
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: Bearer {{admin_token}}
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
###城市列表 - 联表数据
|
||||||
|
GET {{host}}/admin/config/system/address_list?deep=1&pid=82
|
||||||
|
Content-Type: application/json
|
||||||
|
Authorization: Bearer {{admin_token}}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user