From c627dcf45d378093b0175f248d354c8f5a421153 Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Fri, 10 May 2024 14:36:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E7=9C=81?= =?UTF-8?q?=E5=B8=82=E5=8C=BA=E9=95=87=E6=9D=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/GeoController.php | 99 ++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 app/admin/controller/GeoController.php diff --git a/app/admin/controller/GeoController.php b/app/admin/controller/GeoController.php new file mode 100644 index 0000000..64e5385 --- /dev/null +++ b/app/admin/controller/GeoController.php @@ -0,0 +1,99 @@ +field('province_code,province_name')->select()->toArray(); + return $this->success('请求成功',$data); + }catch (\Exception $e) { + return $this->fail($e->getMessage()); + } + } + + /** + * 获取某个省份下的城市 + * @params province_code 省份编码 + * @return Response + */ + public function city(): Response + { + $province_code = $this->request->get('province_code'); + if(empty($province_code)){ + return $this->fail('参数错误'); + } + try { + $data = Db::name('geo_city')->field('city_code,city_name')->where('province_code',$province_code)->select()->toArray(); + return $this->success('请求成功',$data); + }catch (\Exception $e) { + return $this->fail($e->getMessage()); + } + } + + /** + * 获取某个城市下面的区县 + * @params city_code 城市编码 + * @return Response + */ + public function area(): Response + { + $city_code = $this->request->get('city_code'); + if(empty($city_code)){ + return $this->fail('参数错误'); + } + try { + $data = Db::name('geo_area')->field('area_code,area_name')->where('city_code',$city_code)->select()->toArray(); + return $this->success('请求成功',$data); + }catch (\Exception $e) { + return $this->fail($e->getMessage()); + } + } + + /** + * 获取某个区县下面的镇街 + * @params area_code 城市编码 + * @return Response + */ + public function street(): Response + { + $area_code = $this->request->get('area_code'); + if(empty($area_code)){ + return $this->fail('参数错误'); + } + try { + $data = Db::name('geo_street')->field('street_code,street_name')->where('area_code',$area_code)->select()->toArray(); + return $this->success('请求成功',$data); + }catch (\Exception $e) { + return $this->fail($e->getMessage()); + } + } + + /** + * 获取某个镇街下面的村社 + * @params street_code 镇街编码 + * @return Response + */ + public function village(): Response + { + $street_code = $this->request->get('street_code'); + if(empty($street_code)){ + return $this->fail('参数错误'); + } + try { + $data = Db::name('geo_village')->field('village_code,village_name')->where('street_code',$street_code)->select()->toArray(); + return $this->success('请求成功',$data); + }catch (\Exception $e) { + return $this->fail($e->getMessage()); + } + } + } \ No newline at end of file