mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-29 14:01:07 +00:00
格式化获取城市数据完整列表
This commit is contained in:
parent
d6db8fabdd
commit
36a893d5a8
@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user