127 lines
2.7 KiB
PHP
127 lines
2.7 KiB
PHP
<?php
|
||
/**
|
||
* @date :2023年03月2日
|
||
* @author:刘孝全
|
||
* @email:q8197264@126.com
|
||
*
|
||
* @ 地区联动模型 省->市->区->街道/农村->大队
|
||
*/
|
||
namespace app\api\controller;
|
||
|
||
|
||
use app\api\BaseController;
|
||
use app\api\middleware\Auth;
|
||
use app\api\model\GeoProvince as GeoProvinceModel;
|
||
use app\api\model\GeoCity as GeoCityModel;
|
||
use app\api\model\GeoArea as GeoAreaModel;
|
||
use app\api\model\GeoStreet as GeoStreetModel;
|
||
use app\api\model\GeoVillage as GeoVillageModel;
|
||
use app\api\model\GeoBrigade as GeoBrigadeModel;
|
||
|
||
/**
|
||
* 首页接口
|
||
*/
|
||
class Geo1 extends BaseController
|
||
{
|
||
|
||
/**
|
||
* 控制器中间件 [不需要鉴权]
|
||
* @var array
|
||
*/
|
||
protected $middleware = [
|
||
Auth::class => ['except' => ['Province','City','Area','Street','Village', 'Brigade']]
|
||
];
|
||
|
||
/**
|
||
* 省
|
||
*
|
||
* echo json
|
||
*/
|
||
function Province(GeoProvinceModel $province){
|
||
$list = $province::Get();
|
||
|
||
$this->apiSuccess('OK',$list);
|
||
}
|
||
|
||
/**
|
||
* 市
|
||
*
|
||
* @param $pcode 码
|
||
*
|
||
* @echo json
|
||
*/
|
||
function City(GeoCityModel $city){
|
||
$pcode = get_params('pcode');
|
||
// $pcode = '130000';
|
||
if(!$pcode) $this->apiError('请先选择省份');
|
||
|
||
$list = $city::Get($pcode);
|
||
|
||
$this->apiSuccess('OK',$list);
|
||
}
|
||
|
||
/**
|
||
* 区
|
||
*
|
||
* @param $pcode 码
|
||
*
|
||
* echo json
|
||
*/
|
||
function Area(GeoAreaModel $area){
|
||
$pcode = get_params('pcode');
|
||
// $pcode = '140100';
|
||
if(!$pcode) $this->apiError('请先选择城市');
|
||
|
||
$list = $area::Get($pcode);
|
||
|
||
$this->apiSuccess('OK',$list);
|
||
}
|
||
|
||
/**
|
||
* 镇/街道
|
||
*
|
||
* @param $pcode 码
|
||
*
|
||
* echo json
|
||
*/
|
||
function Street(GeoStreetModel $street){
|
||
$pcode = get_params('pcode');
|
||
// $pcode = '410102';
|
||
if(!$pcode) $this->apiError('请先选择镇/街道');
|
||
|
||
$list = $street::Get($pcode);
|
||
|
||
$this->apiSuccess('OK',$list);
|
||
}
|
||
|
||
/**
|
||
* 村
|
||
*
|
||
* @param $pcode 码
|
||
*
|
||
* echo json
|
||
*/
|
||
function Village(GeoVillageModel $village){
|
||
$pcode = get_params('pcode');
|
||
// $pcode = '410102';
|
||
if(!$pcode) $this->apiError('请先选择镇/街道');
|
||
|
||
$list = $village::Get($pcode);
|
||
|
||
$this->apiSuccess('OK',$list);
|
||
}
|
||
|
||
|
||
/**
|
||
* 大队
|
||
*
|
||
* @param $pcode 码
|
||
*
|
||
* echo json
|
||
*/
|
||
function Brigade(GeoBrigadeModel $brigade) {
|
||
$list = $brigade::Get();
|
||
|
||
$this->apiSuccess('OK',$list);
|
||
}
|
||
} |