新增管理后台农户管理模块相关接口

This commit is contained in:
weiz 2023-11-01 16:34:14 +08:00
parent 1603adda7c
commit 993e6cbe55
1 changed files with 158 additions and 0 deletions

View File

@ -0,0 +1,158 @@
<?php
namespace app\adminapi\controller\farmer;
use app\adminapi\controller\BaseAdminController;
use think\facade\Db;
use think\response\Json;
class FarmerController extends BaseAdminController
{
//农户列表
public function lists(): Json
{
$params = $this->request->get(['farmer_name','farmer_phone','group_name','captain_name','page_no','page_size']);
//设置分页条件
$params['page_no'] = empty($params['page_no']) || $params['page_no'] < 0 ? 1 : $params['page_no'];
$params['page_size'] = empty($params['page_size']) || $params['page_size'] < 0 ? 10 : $params['page_size'];
//获取数据
$url = env('project.worker_domain').'/api/information/farmerList';
$data = curl_post($url,[],$params);
if(empty($data) || $data['code'] == 0){
return $this->fail('请求失败');
}
return json($data);
}
//农户详情
public function detail(): Json
{
$params = $this->request->get(['id']);
if(empty($params['id'])){
return $this->fail('参数错误');
}
//获取数据
$url = env('project.worker_domain').'/api/information/farmerInfo';
$result = curl_post($url,[],['user_id'=>$params['id']]);
if(empty($result) || $result['code'] == 0){
return $this->fail('请求失败');
}
$data = $result['data'];
if(empty($data)){
return $this->fail('数据为空');
}
$data['address'] = $data['area_name'].$data['street_name'].$data['village_name'].$data['brigade_name'].$data['address'];
$str = [];
$area = [];
$item['farmer_type'] = implode('/',$str);
$item['farmer_area'] = implode('/',$area);
//判断是否是种植农户
if($data['is_zz_user']){
$str[] = '种植户';
$area[] = $data['total_land_area'];
$lands = $data['land_detail'];
foreach($lands as $k=>$v) {
//查找种植信息
$land_crop = Db::name('farmer_land_crop')->where([
['user_id','=',$params['id']],
['land_id','=',$v['land_id']],
['flag','=',1]
])->order('id desc')->findOrEmpty();
if(!empty($land_crop)){
$lands[$k]['is_cropped'] = true;
$lands[$k]['source_code'] = $land_crop['source_code'];
$lands[$k]['crop_name'] = $land_crop['crop_name'];
$lands[$k]['crop_variety'] = $land_crop['crop_variety'];
$lands[$k]['crop_brand'] = $land_crop['crop_brand'];
$lands[$k]['crop_yield'] = $land_crop['crop_yield'];
$lands[$k]['seed_time'] = date('Y-m-d H:i:s',$land_crop['seed_time']);
$lands[$k]['ripe_time'] = !empty($land_crop['ripe_time']) && !empty($land_crop['crop_yield']) ? date('Y-m-d H:i:s',$land_crop['ripe_time']) : $land_crop['ripe_time'];
}else{
$lands[$k]['is_cropped'] = false;
}
}
$data['land_detail'] = $lands;
}
//判断是否是水产养殖户
if($data['is_sc_user']){
$str[] = '水产养殖户';
$area[] = $data['total_pond_area'];
$ponds = $data['pond_detail'];
foreach($ponds as $k=>$v) {
//获取养殖信息
$breedData = Db::name('farmer_pond_breed')->where('user_id',$params['id'])->where('pond_id',$v['pond_id'])->sum('number');
//获取捕捞信息
$catchData = Db::name('farmer_pond_catch')->where('user_id',$params['id'])->where('pond_id',$v['pond_id'])->sum('number');
if($breedData - $catchData != 0){
$ponds[$k]['is_culture'] = true;
$ponds[$k]['total_num'] = $breedData - $catchData;
//获取水产养殖种类
$fishKind = Db::name('farmer_pond_breed')->distinct(true)->where('user_id',$params['id'])->where('pond_id',$v['pond_id'])->limit(4)->column('kind');
//获取水产养殖具体品种
$fiskBreed = Db::name('farmer_pond_breed')->distinct(true)->where('user_id',$params['id'])->where('pond_id',$v['pond_id'])->limit(4)->column('breed');
$ponds[$k]['kind'] = $fishKind;
$ponds[$k]['breed'] = $fiskBreed;
//获取养殖时间
$firstBreed = Db::name('farmer_pond_breed')->where('user_id',$params['id'])->where('pond_id',$v['pond_id'])->findOrEmpty();
$ponds[$k]['source_code'] = $firstBreed['source_code'];
$ponds[$k]['create_time'] = date('Y-m-d H:i:s',$firstBreed['create_time']);
}else{
$ponds[$k]['is_culture'] = false;
}
}
$data['pond_detail'] = $ponds;
}
//判断是否是家畜养殖户
if($data['is_dw_user']){
$str[] = '家畜养殖户';
$area[] = $data['total_pasture_area'];
//获取家畜养殖数量
$animalCount = Db::name('farmer_animal_breed')->where('user_id',$params['id'])->count();
//获取家畜是公的数量
$maleCount = Db::name('farmer_animal_breed')->where('user_id',$params['id'])->where('animal_gender',1)->count();
//获取家畜是母的数量
$maternalCount = Db::name('farmer_animal_breed')->where('user_id',$params['id'])->where('animal_gender',2)->count();
//获取家畜养殖种类
$animalKind = Db::name('farmer_animal_breed')->distinct(true)->where('user_id',$params['id'])->limit(4)->column('animal_kind');
//获取家畜养殖具体品种
$animalBreed = Db::name('farmer_animal_breed')->distinct(true)->where('user_id',$params['id'])->limit(4)->column('animal_breed');
$animalLists = Db::name('farmer_animal_breed')->where('user_id',$params['id'])->select()->toArray();
$data['animal_detail'] = [
'total_count' => $animalCount,
'male_count' => $maleCount,
'maternal_count' => $maternalCount,
'kind' => $animalKind,
'breed' => $animalBreed,
'lists' => $animalLists
];
}
//判断是否是家禽养殖户
if($data['is_jq_user']){
$str[] = '家禽养殖户';
$area[] = $data['total_henhouse_area'];
//获取家畜养殖数量
$poultryCount = Db::name('farmer_poultry_breed')->where('user_id',$params['id'])->count();
//获取家畜是公的数量
$maleCount = Db::name('farmer_poultry_breed')->where('user_id',$params['id'])->where('gender',1)->count();
//获取家畜是母的数量
$maternalCount = Db::name('farmer_poultry_breed')->where('user_id',$params['id'])->where('gender',2)->count();
//获取家畜养殖种类
$poultryKind = Db::name('farmer_poultry_breed')->distinct(true)->where('user_id',$params['id'])->limit(4)->column('kind');
//获取家畜养殖具体品种
$poultryBreed = Db::name('farmer_poultry_breed')->distinct(true)->where('user_id',$params['id'])->limit(4)->column('breed');
$poultryList = Db::name('farmer_poultry_breed')->where('user_id',$params['id'])->select()->toArray();
$data['poultry_detail'] = [
'total_count' => $poultryCount,
'male_count' => $maleCount,
'maternal_count' => $maternalCount,
'kind' => $poultryKind,
'breed' => $poultryBreed,
'lists' => $poultryList
];
}
$data['farmer_type'] = implode('/',$str);
$data['farmer_area'] = implode('/',$area);
unset($data['area_name'],$data['street_name'],$data['village_name'],$data['brigade_name'],$data['is_zz_user'],$data['is_dw_user'],$data['is_jq_user'],$data['is_sc_user'],$data['total_land_area'],$data['total_pasture_area'],$data['total_henhouse_area'],$data['total_pond_area']);
return $this->success('请求成功',$data);
}
}