City.php
938 字节
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
40
41
42
<?php
namespace app\api\model;
use think\Model;
class City extends Model
{
protected $name = 'city';
// 获取热门城市(省会)
public function getHotCity()
{
return $this->order('id', 'asc')->having('')->select();
}
// 获取所有的省
public function getAllProvince()
{
return $this->order('id', ' asc')->group('province_zh')->select();
}
// 根据ID获取一个城市
public function getOneById($id)
{
return $this->where(['id' => ['=', $id]])->find();
}
// 根据省名称获取大城市
public function getBigCity($province)
{
return $this->where(['province_zh' => ['=', $province]])->order('id', 'asc')->having('leader_zh = city_zh')->select();
}
// 获取小城市
public function getSmallCity($leader)
{
return $this->where(['leader_zh' => ['=', $leader]])->order('id', 'asc')->select();
}
}