新增省市县镇村组模型和接口
This commit is contained in:
parent
5eff598ff7
commit
8ad44e8b05
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\model\geo\City;
|
||||
use app\common\model\geo\County;
|
||||
use app\common\model\geo\Group;
|
||||
use app\common\model\geo\Province;
|
||||
use app\common\model\geo\Town;
|
||||
use app\common\model\geo\Village;
|
||||
use app\common\model\land\Land;
|
||||
use think\response\Json;
|
||||
|
||||
class LandController extends BaseApiController
|
||||
{
|
||||
//添加土地
|
||||
public function addLand(): Json
|
||||
{
|
||||
$fields = ['title','area','province_code','city_code','county_code','town_code','village_code','group_code','master_name','master_phone'];
|
||||
$params = $this->request->post($fields);
|
||||
foreach($fields as $v){
|
||||
if(!isset($params[$v]) || $params[$v] == ''){
|
||||
return $this->fail('缺少必要参数');
|
||||
}
|
||||
}
|
||||
$land = Land::where('user_id',$this->userId)->where('title',$params['title'])->findOrEmpty();
|
||||
if(!$land->isEmpty()){
|
||||
return $this->fail('土地名称已存在');
|
||||
}
|
||||
$province = Province::field('province_name')->where('province_code',$params['province_code'])->findOrEmpty();
|
||||
if($province->isEmpty()){
|
||||
return $this->fail('省份编码错误');
|
||||
}
|
||||
$city = City::field('city_name')->where('province_code',$params['province_code'])->where('city_code',$params['city_code'])->findOrEmpty();
|
||||
if($city->isEmpty()){
|
||||
return $this->fail('城市编码错误');
|
||||
}
|
||||
$county = County::field('county_name')->where('city_code',$params['city_code'])->where('county_code',$params['county_code'])->findOrEmpty();
|
||||
if($county->isEmpty()){
|
||||
return $this->fail('区县编码错误');
|
||||
}
|
||||
$town = Town::field('town_name')->where('county_code',$params['county_code'])->where('town_code',$params['town_code'])->findOrEmpty();
|
||||
if($town->isEmpty()){
|
||||
return $this->fail('镇街编码错误');
|
||||
}
|
||||
$village = Village::field('village_name')->where('town_code',$params['town_code'])->where('village_code',$params['village_code'])->findOrEmpty();
|
||||
if($village->isEmpty()){
|
||||
return $this->fail('乡村编码错误');
|
||||
}
|
||||
$group = Group::field('group_name')->where('id',$params['group_code'])->findOrEmpty();
|
||||
if($group->isEmpty()){
|
||||
return $this->fail('小组编码错误');
|
||||
}
|
||||
$land = Land::create([
|
||||
'user_id' => $this->userId,
|
||||
'title' => $params['title'],
|
||||
'total_area' => $params['area'],
|
||||
'residual_area' => $params['area'],
|
||||
'province_code' => $params['province_code'],
|
||||
'province_name' => $province['province_name'],
|
||||
'city_code' => $params['city_code'],
|
||||
'city_name' => $city['city_name'],
|
||||
'county_code' => $params['county_code'],
|
||||
'county_name' => $county['county_name'],
|
||||
'town_code' => $params['town_code'],
|
||||
'town_name' => $town['town_name'],
|
||||
'village_code' => $params['village_code'],
|
||||
'village_name' => $village['village_name'],
|
||||
'group_code' => $params['group_code'],
|
||||
'group_name' => $group['group_name'],
|
||||
'master_name' => $params['master_name'],
|
||||
'master_phone' => $params['master_phone'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
]);
|
||||
if($land->id){
|
||||
return $this->success('土地添加成功');
|
||||
}else{
|
||||
return $this->fail('土地添加失败');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\model\geo\City;
|
||||
use app\common\model\geo\County;
|
||||
use app\common\model\geo\Group;
|
||||
use app\common\model\geo\Province;
|
||||
use app\common\model\geo\Town;
|
||||
use app\common\model\geo\Village;
|
||||
use think\facade\Db;
|
||||
use think\response\Json;
|
||||
|
||||
class GeoController extends BaseLikeAdminController
|
||||
{
|
||||
// 获取省份
|
||||
public function province(): Json
|
||||
{
|
||||
$data = Province::field('province_code,province_name')->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取城市
|
||||
public function city(): Json
|
||||
{
|
||||
$province_code = $this->request->get('province_code');
|
||||
if(empty($province_code)){
|
||||
return $this->fail('请选择省份');
|
||||
}
|
||||
$data = City::field('city_code,city_name')->where('province_code',$province_code)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取区县
|
||||
public function county(): Json
|
||||
{
|
||||
$city_code = $this->request->get('city_code');
|
||||
if(empty($city_code)){
|
||||
return $this->fail('请选择城市');
|
||||
}
|
||||
$data = County::field('county_code,county_name')->where('city_code',$city_code)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取镇街
|
||||
public function towns(): Json
|
||||
{
|
||||
$county_code = $this->request->get('county_code');
|
||||
if(empty($county_code)){
|
||||
return $this->fail('请选择区县');
|
||||
}
|
||||
$data = Town::field('town_code,town_name')->where('county_code',$county_code)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取村社
|
||||
public function villages(): Json
|
||||
{
|
||||
$town_code = $this->request->get('town_code');
|
||||
if(empty($town_code)){
|
||||
return $this->fail('请选择镇街');
|
||||
}
|
||||
$data = Village::field('village_code,village_name')->where('town_code',$town_code)->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
|
||||
// 获取小组
|
||||
public function groups(): Json
|
||||
{
|
||||
$data = Group::field('id as group_code,group_name')->select();
|
||||
return $this->success('请求成功',$data->toArray());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class City extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_city';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class County extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_county';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Group extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_group';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Province extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_province';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Town extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_town';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\geo;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Village extends BaseModel
|
||||
{
|
||||
protected $name = 'geo_village';
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\land;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class Land extends BaseModel
|
||||
{
|
||||
|
||||
}
|
|
@ -33,7 +33,8 @@
|
|||
"alibabacloud/client": "^1.5",
|
||||
"rmccue/requests": "^2.0",
|
||||
"w7corp/easywechat": "^6.8",
|
||||
"tencentcloud/sms": "^3.0"
|
||||
"tencentcloud/sms": "^3.0",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2",
|
||||
|
|
Loading…
Reference in New Issue