From 36a893d5a87db150b0646ffb9fb3efd05c9cefe1 Mon Sep 17 00:00:00 2001 From: evoxwht <442384644@qq.com> Date: Mon, 10 Apr 2023 11:24:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=9F=8E=E5=B8=82=E6=95=B0=E6=8D=AE=E5=AE=8C=E6=95=B4=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/v1/setting/SystemCity.php | 2 +- crmeb/app/dao/shipping/SystemCityDao.php | 2 +- .../services/shipping/SystemCityServices.php | 27 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) 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; + } }