City.php
4.3 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\api\model\City as CityModel;
use app\api\model\University as UniversityModel;
/**
* 城市相关
*/
class City extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['*'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
/**
* 获取省
* @ApiTitle (获取省)
* @ApiSummary (获取省)
* @ApiMethod (GET)
* @ApiReturnParams (name="code", type="integer", required=true, description="状态码")
* @ApiReturnParams (name="msg", type="string", required=true, description="提示语")
* @ApiReturnParams (name="data", type="object", description="对象")
* @ApiReturn ({
"code": 1,
"msg": "获取省份成功",
"time": "1585874807",
"data": [
{
"id": "101010100(省份ID)",
"city_en": "beijing",
"city_zh": "北京",
"province_en": "beijing",
"province_zh": "北京(省份名称)",
"country_en": "China",
"country_zh": "中国",
"leader_en": "beijing",
"leader_zh": "北京",
"lat": "39.904989",
"lon": "116.405285"
}})
*/
public function getAllProvince()
{
$city = new CityModel();
$cityData = $city->getAllProvince();
$this->success('获取省份成功', $cityData);
}
/**
* 获取一级城市
* @ApiTitle (获取一级城市)
* @ApiSummary (获取一级城市)
* @ApiMethod (GET)
* @ApiParams (name="province_id", type="integer", required=true, description="城市ID")
* @ApiReturnParams (name="code", type="integer", required=true, description="状态码")
* @ApiReturnParams (name="msg", type="string", required=true, description="提示语")
* @ApiReturnParams (name="data", type="object", description="对象")、
* @ApiReturn ({
"code": 1,
"msg": "获取大城市成功",
"time": "1585874953",
"data": [
{
"id": "101300101",
"city_en": "nanning",
"city_zh": "南宁(城市名称)",
"province_en": "guangxi",
"province_zh": "广西",
"country_en": "China",
"country_zh": "中国",
"leader_en": "nanning",
"leader_zh": "南宁",
"lat": "22.82402",
"lon": "108.320004"
}})
*/
public function getBigCity()
{
$provinceId = $this->request->param('province_id', '', 'int');
if(!$provinceId || !is_numeric($provinceId)) {
$this->error('您的提交存在问题');
}
$city = new CityModel();
$cityInfo = $city->getOneById($provinceId);
if(!$cityInfo) {
$this->error('您的提交存在问题');
}
$cityData = $city->getBigCity($cityInfo['province_zh']);
$this->success('获取大城市成功', $cityData);
}
/**
* 获取市的大学
* @ApiTitle (获取市的大学)
* @ApiSummary (获取市的大学)
* @ApiMethod (GET)
* @ApiParams (name="city_id", type="integer", required=true, description="城市ID")
* @ApiReturnParams (name="code", type="integer", required=true, description="状态码")
* @ApiReturnParams (name="msg", type="string", required=true, description="提示语")
* @ApiReturnParams (name="data", type="object", description="对象")、
* @ApiReturn ({
"code": 1,
"msg": "获取市的大学成功",
"time": "1586420249",
"data": [
{
"id": 1,
"name": "哈哈",
"des_content": "1",
"des_image": "",
"updatetime": 0,
"createtime": 0,
"url": "",
"wechat": "",
"show_switch": 1,
"icon_image": "",
"weigh": 0,
"province_id": 1,
"city_id": 1,
"deletetime": null,
"level_id": 1
}
]
})
*/
public function getUniversityByCity()
{
$cityId = $this->request->param('city_id', 0, 'int');
if(!$cityId) {
$this->error('您的提交存在问题');
}
$university = new UniversityModel();
$universityList = $university->listByCityId($cityId);
$this->success('获取市的大学成功', $universityList);
}
}