初始版本
This commit is contained in:
44
server/app/api/logic/CityLogic.php
Executable file
44
server/app/api/logic/CityLogic.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace app\api\logic;
|
||||
use app\common\model\city\City;
|
||||
|
||||
class CityLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 获取城市列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author cjhao
|
||||
* @date 2024/10/6 17:49
|
||||
*/
|
||||
public function getCityLists()
|
||||
{
|
||||
$lists = City::where(['level'=>2])->select()->toArray();
|
||||
$cityLists = [];
|
||||
foreach ($lists as $city){
|
||||
$parent = $cityLists[$city['parent_id']] ?? [];
|
||||
if($parent){
|
||||
$parent['sons'][] =[
|
||||
'id' => $city['city_id'],
|
||||
'name' => $city['name'],
|
||||
];
|
||||
}else{
|
||||
$parent = [
|
||||
'id' => $city['parent_id'],
|
||||
'name' => $city['parent_name'],
|
||||
'sons' => [
|
||||
[
|
||||
'id' => $city['city_id'],
|
||||
'name' => $city['name'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
$cityLists[$city['parent_id']] = $parent;
|
||||
}
|
||||
return array_values($cityLists);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user