市->区->街道/农村->大队 */ namespace app\api\controller; use app\api\BaseController; use app\api\middleware\Auth; use app\common\model\geo\GeoProvince as GeoProvinceModel; use app\common\model\geo\GeoCity as GeoCityModel; use app\common\model\geo\GeoArea as GeoAreaModel; use app\common\model\geo\GeoStreet as GeoStreetModel; use app\common\model\geo\GeoVillage as GeoVillageModel; use app\common\model\geo\GeoBrigade as GeoBrigadeModel; /** * 首页接口 */ class Geo extends BaseController { /** * 控制器中间件 [不需要鉴权] * @var array */ protected $middleware = [ Auth::class => ['except' => ['Province','City','Area','Street','Village', 'Brigade','test']] ]; /** * 省 * * 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); } }