data_center/app/adminapi/controller/GeoController.php

67 lines
2.1 KiB
PHP
Raw Normal View History

2023-09-21 15:31:01 +08:00
<?php
namespace app\adminapi\controller;
use think\facade\Db;
use think\response\Json;
class GeoController extends BaseAdminController
{
// 获取省份
public function provinces(): Json
{
$data = Db::name('geo_province')->field('province_code as province,province_name')->select();
return $this->success('请求成功',$data->toArray());
}
// 获取城市
public function cities(): Json
{
$param = $this->request->get('province');
if(empty($param)){
return $this->fail('请选择省份');
}
$data = Db::name('geo_city')->field('city_code as city,city_name')->where('province_code',$param)->select();
return $this->success('请求成功',$data->toArray());
}
// 获取区县
public function areas(): Json
{
$param = $this->request->get('city');
if(empty($param)){
return $this->fail('请选择城市');
}
$data = Db::name('geo_area')->field('area_code as area,area_name')->where('city_code',$param)->select();
return $this->success('请求成功',$data->toArray());
}
// 获取镇街
public function streets(): Json
{
$param = $this->request->get('area');
if(empty($param)){
return $this->fail('请选择区县');
}
$data = Db::name('geo_street')->field('street_code as street,street_name')->where('area_code',$param)->select();
return $this->success('请求成功',$data->toArray());
}
// 获取村社
public function villages(): Json
{
$param = $this->request->get('street');
if(empty($param)){
return $this->fail('请选择镇街');
}
$data = Db::name('geo_village')->field('village_code as village,village_name')->where('street_code',$param)->select();
return $this->success('请求成功',$data->toArray());
}
// 获取小组
public function brigades(): Json
{
$data = Db::name('geo_brigade')->field('id as brigade,brigade_name')->select();
return $this->success('请求成功',$data->toArray());
}
}