|
|
|
@ -12,9 +12,9 @@ declare (strict_types=1); |
|
|
|
|
|
|
|
|
|
namespace app\common\model; |
|
|
|
|
|
|
|
|
|
use app\common\library\helper; |
|
|
|
|
use cores\BaseModel; |
|
|
|
|
use think\facade\Cache; |
|
|
|
|
use app\common\library\helper; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 地区模型 |
|
|
|
@ -44,11 +44,13 @@ class Region extends BaseModel |
|
|
|
|
|
|
|
|
|
// 当前数据版本号 |
|
|
|
|
private static string $version = '1.0.3'; |
|
|
|
|
|
|
|
|
|
public static function init() |
|
|
|
|
{ |
|
|
|
|
self::$storeId = 0; |
|
|
|
|
app()->request->setStoreId(0); |
|
|
|
|
// self::$storeId = 0; |
|
|
|
|
// app()->request->setStoreId(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据ID获取地区名称 |
|
|
|
|
* @param int $id |
|
|
|
@ -143,7 +145,9 @@ class Region extends BaseModel |
|
|
|
|
} |
|
|
|
|
return $cacheData[$item]; |
|
|
|
|
} |
|
|
|
|
public function getNewTreeList(){ |
|
|
|
|
|
|
|
|
|
public function getNewTreeList() |
|
|
|
|
{ |
|
|
|
|
$treeList = Cache::get('region2'); |
|
|
|
|
if ($treeList) { |
|
|
|
|
return $treeList; |
|
|
|
@ -152,7 +156,7 @@ class Region extends BaseModel |
|
|
|
|
->field('id, pid, name, level') |
|
|
|
|
->select() |
|
|
|
|
->toArray(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$treeList = []; |
|
|
|
|
$i = 0; |
|
|
|
|
foreach ($allList as $pKey => $province) { |
|
|
|
@ -161,7 +165,7 @@ class Region extends BaseModel |
|
|
|
|
unset($allList[$pKey]); |
|
|
|
|
$j = 0; |
|
|
|
|
foreach ($allList as $cKey => $city) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($city['level'] == 2 && $city['pid'] == $province['id']) { // 城市 |
|
|
|
|
$treeList[$i]['children'][$j] = $city; |
|
|
|
|
unset($allList[$cKey]); |
|
|
|
@ -181,8 +185,9 @@ class Region extends BaseModel |
|
|
|
|
} |
|
|
|
|
Cache::tag('cache')->set('region2', $treeList); |
|
|
|
|
return $treeList; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取地区缓存 |
|
|
|
|
* @return array |
|
|
|
|