api添加地区模型

This commit is contained in:
liuxiaoquan 2023-03-02 18:13:42 +08:00
parent b7e2a1deb1
commit 83d0b5f05b
11 changed files with 422 additions and 96 deletions

1
.htaccess Normal file
View File

@ -0,0 +1 @@

7
404.html Normal file
View File

@ -0,0 +1,7 @@
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

View File

@ -0,0 +1,96 @@
<?php
namespace app\api\controller;
use app\api\BaseController;
use app\api\middleware\Auth;
use think\facade\Db;
/**
* 首页接口
*/
class Geo extends BaseController
{
/**
* 控制器中间件 [不需要鉴权]
* @var array
*/
protected $middleware = [
Auth::class => ['except' => ['province','city','area','street','village','brigade'] ]
];
/**
*
*/
public function province(){
$res = Db::table('fa_geo_province')->where(['switch'=>1])
->field('province_id id,province_code code,province_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
*
*/
public function city(){
$pcode = get_params('pcode');
// $pcode = '130000';
if(!$pcode) $this->apiError('请先选择省份');
$res = Db::table('fa_geo_city')->where(['switch'=>1,'province_code'=>$pcode])
->field('city_id id,city_code code,city_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
*
*/
public function area(){
$pcode = get_params('pcode');
// $pcode = '140100';
if(!$pcode) $this->apiError('请先选择城市');
$res = Db::table('fa_geo_area')->where(['switch'=>1,'city_code'=>$pcode])
->field('area_id id,area_code code,area_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
* 街道
*/
public function street(){
$pcode = get_params('pcode');
// $pcode = '410102';
if(!$pcode) $this->apiError('请先选择区/县');
$res = Db::table('fa_geo_street')->where(['switch'=>1,'area_code'=>$pcode])
->field('street_id id,street_code code,street_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
*
*/
public function village(){
$pcode = get_params('pcode');
// $pcode = '410102';
if(!$pcode) $this->apiError('请先选择镇/街道');
$res = Db::table('fa_geo_village')->where(['switch'=>1,'street_code'=>$pcode])
->field('village_id id,village_code code,village_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
* 大队
*/
public function brigade(){
$res = Db::table('fa_geo_brigade')
->select();
$this->apiSuccess('OK',$res);
}
}

View File

@ -1,96 +1,127 @@
<?php
namespace app\api\controller;
use app\api\BaseController;
use app\api\middleware\Auth;
use think\facade\Db;
/**
* 首页接口
*/
class Geo extends BaseController
{
/**
* 控制器中间件 [不需要鉴权]
* @var array
*/
protected $middleware = [
Auth::class => ['except' => ['province','city','area','street','village','brigade'] ]
];
/**
*
*/
public function province(){
$res = Db::table('fa_geo_province')->where(['switch'=>1])
->field('province_id id,province_code code,province_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
*
*/
public function city(){
$pcode = get_params('pcode');
// $pcode = '130000';
if(!$pcode) $this->apiError('请先选择省份');
$res = Db::table('fa_geo_city')->where(['switch'=>1,'province_code'=>$pcode])
->field('city_id id,city_code code,city_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
*
*/
public function area(){
$pcode = get_params('pcode');
// $pcode = '140100';
if(!$pcode) $this->apiError('请先选择城市');
$res = Db::table('fa_geo_area')->where(['switch'=>1,'city_code'=>$pcode])
->field('area_id id,area_code code,area_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
* 街道
*/
public function street(){
$pcode = get_params('pcode');
// $pcode = '410102';
if(!$pcode) $this->apiError('请先选择区/县');
$res = Db::table('fa_geo_street')->where(['switch'=>1,'area_code'=>$pcode])
->field('street_id id,street_code code,street_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
*
*/
public function village(){
$pcode = get_params('pcode');
// $pcode = '410102';
if(!$pcode) $this->apiError('请先选择镇/街道');
$res = Db::table('fa_geo_village')->where(['switch'=>1,'street_code'=>$pcode])
->field('village_id id,village_code code,village_name name')
->select();
$this->apiSuccess('OK',$res);
}
/**
* 大队
*/
public function brigade(){
$res = Db::table('fa_geo_brigade')
->select();
$this->apiSuccess('OK',$res);
}
}
<?php
/**
* @date 2023年03月2日
* @author刘孝全
* @emailq8197264@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);
}
}

26
app/api/model/GeoArea.php Normal file
View File

@ -0,0 +1,26 @@
<?php
/**
* @date 2023年03月2日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 地区联动模型
*/
namespace app\api\model;
use think\model;
class GeoArea extends Model
{
protected $table = "fa_geo_area";
static function Get($pcode){
$list = self::where(['switch'=>1,'city_code'=>$pcode])
->field('area_id id,area_code code,area_name name')
->select();
return $list;
}
}

View File

@ -0,0 +1,22 @@
<?php
/**
* @date 2023年03月2日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 地区联动 - 大队
*/
namespace app\api\model;
use think\model;
class GeoBrigade extends Model
{
protected $table="fa_geo_brigade";
static function Get(){
$res = self::select();
return $res;
}
}

25
app/api/model/GeoCity.php Normal file
View File

@ -0,0 +1,25 @@
<?php
/**
* @date 2023年03月2日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 地区联动模型
*/
namespace app\api\model;
use think\model;
class GeoCity extends Model {
protected $table = "fa_geo_city";
static function Get($pcode){
$list = self::where(['switch'=>1,'province_code'=>$pcode])
->field('city_id id,city_code code,city_name name')
->select();
return $list;
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @date 2023年03月2日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 地区联动模型
*/
namespace app\api\model;
use think\model;
class GeoProvince extends Model {
protected $table = "fa_geo_province";
// public function test(){
// return $this->belongsToMany(User::class,'fa_geo_city','user_id','role_id');
// }
/**
*
*/
static function Get(){
$res = self::where(['switch'=>1])
->field('province_id id,province_code code,province_name name')
->select();
return $res;
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* @date 2023年03月2日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 地区联动模型
*/
namespace app\api\model;
use think\model;
class GeoStreet extends Model{
protected $table = "fa_geo_street";
static function Get($pcode) {
$list = self::where(['switch'=>1,'area_code'=>$pcode])
->field('street_id id,street_code code,street_name name')
->select();
return $list;
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* @date 2023年03月2日
* @author刘孝全
* @emailq8197264@126.com
*
* @ 地区联动模型
*/
namespace app\api\model;
use think\model;
class GeoVillage extends Model
{
protected $table = "fa_geo_village";
static function Get($pcode) {
$list = self::where(['switch'=>1,'street_code'=>$pcode])
->field('village_id id,village_code code,village_name name')
->select();
return $list;
}
}

39
index.html Normal file
View File

@ -0,0 +1,39 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>恭喜,站点创建成功!</title>
<style>
.container {
width: 60%;
margin: 10% auto 0;
background-color: #f0f0f0;
padding: 2% 5%;
border-radius: 10px
}
ul {
padding-left: 20px;
}
ul li {
line-height: 2.3
}
a {
color: #20a53a
}
</style>
</head>
<body>
<div class="container">
<h1>恭喜, 站点创建成功!</h1>
<h3>这是默认index.html本页面由系统自动生成</h3>
<ul>
<li>本页面在FTP根目录下的index.html</li>
<li>您可以修改、删除或覆盖本页面</li>
<li>FTP相关信息请到“面板系统后台 > FTP” 查看</li>
</ul>
</div>
</body>
</html>