67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Api\System;
|
|
|
|
use App\Cache\Redis\Common\CityCache;
|
|
use App\Constants\Common\CityCode;
|
|
use App\Model\SystemCity;
|
|
use App\Model\SystemCityConfig;
|
|
use App\Service\Api\BaseService;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
class CityListService extends BaseService
|
|
{
|
|
|
|
/**
|
|
* @var SystemCity
|
|
*/
|
|
#[Inject]
|
|
protected SystemCity $systemCityModel;
|
|
|
|
/**
|
|
* @var SystemCityConfig
|
|
*/
|
|
#[Inject]
|
|
protected SystemCityConfig $systemCityConfigModel;
|
|
|
|
/**
|
|
* @var CityCache
|
|
*/
|
|
#[Inject]
|
|
protected CityCache $cityCache;
|
|
|
|
/**
|
|
* @return array
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
$allInfo = array_column($this->cityCache->getCityList(),'title','id');
|
|
|
|
$list = $this->systemCityModel
|
|
->where('is_del', CityCode::IS_NOT_DELETE)
|
|
->select(['id','title','status','city_id','province_id'])
|
|
->get();
|
|
|
|
if (empty($list)) return $this->return->success('success', ['list' => []]);
|
|
|
|
$list = $list->toArray();
|
|
foreach ($list as &$v) {
|
|
$v['city_name'] = $allInfo[$v['city_id']];
|
|
$v['province_name'] = $allInfo[$v['province_id']];
|
|
}
|
|
|
|
return $this->return->success('success', ['list' => $list]);
|
|
}
|
|
} |