diff --git a/crmeb/app/adminapi/controller/v1/setting/SystemCity.php b/crmeb/app/adminapi/controller/v1/setting/SystemCity.php index 2d83f000f..07e2400ae 100644 --- a/crmeb/app/adminapi/controller/v1/setting/SystemCity.php +++ b/crmeb/app/adminapi/controller/v1/setting/SystemCity.php @@ -151,6 +151,6 @@ class SystemCity extends AuthController */ public function fullList() { - return app('json')->success($this->services->fullList('parent_id,city_id,id,name,name as label,city_id as value')); + return app('json')->success($this->services->fullList('parent_id,name as label,city_id as value')); } } diff --git a/crmeb/app/dao/shipping/SystemCityDao.php b/crmeb/app/dao/shipping/SystemCityDao.php index 185ffed14..2cea41b0e 100644 --- a/crmeb/app/dao/shipping/SystemCityDao.php +++ b/crmeb/app/dao/shipping/SystemCityDao.php @@ -96,6 +96,6 @@ class SystemCityDao extends BaseDao */ public function fullList($field = '*') { - return $this->getModel()->with('children')->order('id asc')->field($field)->select()->toArray(); + return $this->getModel()->order('id asc')->field($field)->select()->toArray(); } } diff --git a/crmeb/app/services/shipping/SystemCityServices.php b/crmeb/app/services/shipping/SystemCityServices.php index 954da63ec..a4327d0ba 100644 --- a/crmeb/app/services/shipping/SystemCityServices.php +++ b/crmeb/app/services/shipping/SystemCityServices.php @@ -153,13 +153,36 @@ class SystemCityServices extends BaseServices } /** - * 获取城市数据 + * 获取城市数据完整列表 * @return mixed */ public function fullList($field = '*') { return CacheService::remember('CITY_FULL_LIST', function () use ($field) { - return $this->dao->fullList($field); + return $this->fullListTree($this->dao->fullList($field)); }, 0); } + + /** + * 格式化获取城市数据完整列表 + * @param $data + * @param int $pid + * @param array $navList + * @return array|mixed + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/04/10 + */ + function fullListTree($data, $pid = 0, $navList = []) + { + foreach ($data as $k => $menu) { + if ($menu['parent_id'] == $pid) { + unset($menu['parent_id']); + unset($data[$k]); + $menu['children'] = $this->fullListTree($data, $menu['value']); + $navList[] = $menu; + } + } + return $navList; + } }