City.php
943 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Models\Com;
use App\Helper\Arr;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
/**
* Class City
* @package App\Models
* @author zbj
* @date 2023/6/20
*/
class City extends Model
{
//设置关联表名
protected $table = 'gl_system_city';
public static function getTreeList(){
$cache_key = 'city_select_tree';
$data = Cache::get($cache_key);
if(!$data){
$list = self::select(['city_id', 'parent_id', 'name'])->whereIn('level', [0,1])->get()->toArray();
$data = Arr::listToTree($list, 'city_id', 'parent_id');
Cache::put($cache_key, $data, 24 * 3600);
}
return $data;
}
public static function source($city_id){
$where = [
'parent_id' => $city_id,
'is_show' => 1,
];
return self::where($where)->pluck('name', 'city_id')->toArray();
}
}