初始版本

This commit is contained in:
贾祥聪
2025-08-19 14:16:51 +08:00
commit f937a1f9b9
4373 changed files with 359728 additions and 0 deletions

View 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);
}
}