AdministrativeDivisionController.php
5.8 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 控制层: 行政区划 控制类
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Http\Api\V1\Controllers\System
* @package App\Http\Api\V1\Controllers\System
* @author Richer <yangzi1028@163.com>
* @date 2021年12月16日 18:16:16
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Http\Api\V1\Controllers\System;
use App\Http\Api\V1\Controllers\BaseController;
use App\Models\System\AdministrativeDivision;
use App\Services\System\AdministrativeDivisionService;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
/**
* Class AdministrativeDivisionController
*
* @category App\Http\Api\V1\Controllers\System
* @package App\Http\Api\V1\Controllers\System
* @author Richer <yangzi1028@163.com>
* @date 2021年12月16日 18:16:16
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class AdministrativeDivisionController extends BaseController
{
/**
* AdministrativeDivisionService constructor.
*
* @param AdministrativeDivisionService $service 注入service层
*/
public function __construct(AdministrativeDivisionService $service)
{
// 执行父类构造方法
parent::__construct($service);
}
/**
* 获取全部的省份
*
* @return Response
*/
public function getProvinces()
{
// 获取参数
$list = $this->service->getRegions(AdministrativeDivision::PROVINCE);
if ($list) {
return $this->success($list);
} else {
return $this->error($this->service->getMessage(), 1001);
}
}
/**
* 获取全部的城市
*
* @return Response
*/
public function getCities()
{
// 获取参数
$list = $this->service->getRegions(AdministrativeDivision::CITY);
if ($list) {
return $this->success($list);
} else {
return $this->error($this->service->getMessage(), 1001);
}
}
/**
* 根据上级code获取全部的城市
*
* @param $pcode
* @return Response
*/
public function getCitiesByPcode($pcode)
{
// 获取参数
$list = $this->service->getRegions(AdministrativeDivision::CITY, $pcode);
return $this->success($list);
if ($list) {
return $this->success($list);
} else {
return $this->error($this->service->getMessage(), 1001);
}
}
/**
* 获取全部的城市
*
* @return Response
*/
public function getDistricts()
{
// 获取参数
$list = $this->service->getRegions(AdministrativeDivision::COUNTY);
if ($list) {
return $this->success($list);
} else {
return $this->error($this->service->getMessage(), 1001);
}
}
/**
* 根据上级code获取全部的城市
*
* @param $pcode
* @return Response
*/
public function getCountiesByPcode($pcode)
{
// 获取参数
$list = $this->service->getRegions(AdministrativeDivision::COUNTY, $pcode);
return $this->success($list);
if ($list) {
return $this->success($list);
} else {
return $this->error($this->service->getMessage(), 1001);
}
}
/**
* 根据省份区域的code获取省份的代码集:主要为laravel-admin的select组件使用
*
* @return
*/
public function getProvinceSelectOptions()
{
// 获取参数
$codeset = $this->service->getSelectOptions('province');
return $codeset;
}
/**
* 根据省份的code获取城市的代码集:主要为laravel-admin的select组件使用
*
* @return
*/
public function getCitySelectOptions()
{
// 获取参数
return $this->service->getSelectOptions(AdministrativeDivision::CITY, request()->get('q'));
}
/**
* 根据城市的code获取区县的代码集:主要为laravel-admin的select组件使用
*
* @return
*/
public function getDistrictSelectOptions()
{
// 获取参数
return $this->service->getSelectOptions(AdministrativeDivision::COUNTY, request()->get('q'));
}
/**
* 根据省份的code获取城市的代码集:主要为laravel-admin的select组件使用
*
* @return
*/
public function getCitySelectOptionsByKeyword()
{
// 获取参数
return $this->service->getSelectOptionsByKeyword('city', request('q'));
}
/**
* 获取热门城市
*
* @return Response
*/
public function getHotCities()
{
// 获取参数
$list = $this->service->getHotCities();
if ($list) {
return $this->success($list);
} else {
return $this->error($this->service->getMessage(), 1001);
}
}
/**
* 获取商圈
*
* @param $pcode
* @return Response
*/
public function getBizdistricts($pcode)
{
// 获取参数
$list = $this->service->getBizdistricts($pcode);
if ($list) {
return $this->success($list);
} else {
return $this->error($this->service->getMessage(), 1001);
}
}
/**
* 根据区县获取商圈
*
* @return Response
*/
public function getBizdistrictSelectOptions()
{
// 获取参数
return $list = $this->service->getBizdistrictSelectOptions();
}
}