This commit is contained in:
weiz 2023-10-30 17:24:55 +08:00
parent b00e7e6bc6
commit 9a6e5b668e
1 changed files with 133 additions and 104 deletions

View File

@ -13,126 +13,155 @@ class UserController extends BaseApiController
public function userInfo(): Json
{
//获取参数
$params = $this->request->get(['user_id']);
if(empty($params['user_id'])){
$params = $this->request->get(['user_id','user_type']);
if(empty($params['user_id']) || empty($params['user_type'])){
return $this->fail('参数错误');
}
$url = env('project.worker_domain').'/api/information/farmerInfo';
$curl_result = curl_post($url,[],$params);
if($curl_result['code'] == 0){
return $this->fail($curl_result['msg']);
if(!in_array($params['user_type'],[1,2,3])){
return $this->fail('用户身份信息错误');
}
//判断是否是种植农户
if($curl_result['data']['is_zz_user']){
$lands = $curl_result['data']['land_detail'];
foreach($lands as $k=>$v) {
//查找种植信息
$land_crop = Db::name('farmer_land_crop')->where([
['user_id','=',$params['user_id']],
['land_id','=',$v['land_id']],
])->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;
}
//农户
if($params['user_type'] == 3){
$url = env('project.worker_domain').'/api/information/farmerInfo';
$curl_result = curl_post($url,[],$params);
if($curl_result['code'] == 0){
return $this->fail($curl_result['msg']);
}
$curl_result['data']['land_detail'] = $lands;
}
//判断是否是家畜养殖户
if($curl_result['data']['is_dw_user']){
//获取家畜养殖数量
$animalCount = Db::name('farmer_animal_breed')->where('user_id',$params['user_id'])->count();
//获取家畜是公的数量
$maleCount = Db::name('farmer_animal_breed')->where('user_id',$params['user_id'])->where('animal_gender',1)->count();
//获取家畜是母的数量
$maternalCount = Db::name('farmer_animal_breed')->where('user_id',$params['user_id'])->where('animal_gender',2)->count();
//获取家畜养殖种类
$animalKind = Db::name('farmer_animal_breed')->distinct(true)->where('user_id',$params['user_id'])->limit(4)->column('animal_kind');
//获取家畜养殖具体品种
$animalBreed = Db::name('farmer_animal_breed')->distinct(true)->where('user_id',$params['user_id'])->limit(4)->column('animal_breed');
$curl_result['data']['animal_detail'] = [
'total_count' => $animalCount,
'male_count' => $maleCount,
'maternal_count' => $maternalCount,
'kind' => $animalKind,
'breed' => $animalBreed
];
}
//判断是否是家禽养殖户
if($curl_result['data']['is_jq_user']){
//获取家畜养殖数量
$poultryCount = Db::name('farmer_poultry_breed')->where('user_id',$params['user_id'])->count();
//获取家畜是公的数量
$maleCount = Db::name('farmer_poultry_breed')->where('user_id',$params['user_id'])->where('gender',1)->count();
//获取家畜是母的数量
$maternalCount = Db::name('farmer_poultry_breed')->where('user_id',$params['user_id'])->where('gender',2)->count();
//获取家畜养殖种类
$poultryKind = Db::name('farmer_poultry_breed')->distinct(true)->where('user_id',$params['user_id'])->limit(4)->column('kind');
//获取家畜养殖具体品种
$poultryBreed = Db::name('farmer_poultry_breed')->distinct(true)->where('user_id',$params['user_id'])->limit(4)->column('breed');
$curl_result['data']['poultry_detail'] = [
'total_count' => $poultryCount,
'male_count' => $maleCount,
'maternal_count' => $maternalCount,
'kind' => $poultryKind,
'breed' => $poultryBreed
];
}
//判断是否是水产养殖户
if($curl_result['data']['is_sc_user']){
$ponds = $curl_result['data']['pond_detail'];
foreach($ponds as $k=>$v) {
//获取养殖信息
$breedData = Db::name('farmer_pond_breed')->where('user_id',$params['user_id'])->where('pond_id',$v['pond_id'])->sum('number');
//获取捕捞信息
$catchData = Db::name('farmer_pond_catch')->where('user_id',$params['user_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['user_id'])->where('pond_id',$v['pond_id'])->limit(4)->column('kind');
//获取水产养殖具体品种
$fiskBreed = Db::name('farmer_pond_breed')->distinct(true)->where('user_id',$params['user_id'])->where('pond_id',$v['pond_id'])->limit(4)->column('breed');
$ponds[$k]['kind'] = $fishKind;
$ponds[$k]['breed'] = $fiskBreed;
//获取去最新的图片
$pic = Db::name('farmer_pond_pic')->field('pic,create_time')->where('pond_id',$v['pond_id'])->findOrEmpty();
if(!empty($pic)){
$ponds[$k]['pic_detail'] = $pic;
$ponds[$k]['pic_detail']['create_time'] = date('Y-m-d H:i:s',$pic['create_time']);
//判断是否是种植农户
if($curl_result['data']['is_zz_user']){
$lands = $curl_result['data']['land_detail'];
foreach($lands as $k=>$v) {
//查找种植信息
$land_crop = Db::name('farmer_land_crop')->where([
['user_id','=',$params['user_id']],
['land_id','=',$v['land_id']],
])->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{
$ponds[$k]['pic_detail'] = [];
$lands[$k]['is_cropped'] = false;
}
//获取养殖时间
$firstBreed = Db::name('farmer_pond_breed')->where('user_id',$params['user_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;
}
$curl_result['data']['land_detail'] = $lands;
}
$curl_result['data']['pond_detail'] = $ponds;
//判断是否是家畜养殖户
if($curl_result['data']['is_dw_user']){
//获取家畜养殖数量
$animalCount = Db::name('farmer_animal_breed')->where('user_id',$params['user_id'])->count();
//获取家畜是公的数量
$maleCount = Db::name('farmer_animal_breed')->where('user_id',$params['user_id'])->where('animal_gender',1)->count();
//获取家畜是母的数量
$maternalCount = Db::name('farmer_animal_breed')->where('user_id',$params['user_id'])->where('animal_gender',2)->count();
//获取家畜养殖种类
$animalKind = Db::name('farmer_animal_breed')->distinct(true)->where('user_id',$params['user_id'])->limit(4)->column('animal_kind');
//获取家畜养殖具体品种
$animalBreed = Db::name('farmer_animal_breed')->distinct(true)->where('user_id',$params['user_id'])->limit(4)->column('animal_breed');
$curl_result['data']['animal_detail'] = [
'total_count' => $animalCount,
'male_count' => $maleCount,
'maternal_count' => $maternalCount,
'kind' => $animalKind,
'breed' => $animalBreed
];
}
//判断是否是家禽养殖户
if($curl_result['data']['is_jq_user']){
//获取家畜养殖数量
$poultryCount = Db::name('farmer_poultry_breed')->where('user_id',$params['user_id'])->count();
//获取家畜是公的数量
$maleCount = Db::name('farmer_poultry_breed')->where('user_id',$params['user_id'])->where('gender',1)->count();
//获取家畜是母的数量
$maternalCount = Db::name('farmer_poultry_breed')->where('user_id',$params['user_id'])->where('gender',2)->count();
//获取家畜养殖种类
$poultryKind = Db::name('farmer_poultry_breed')->distinct(true)->where('user_id',$params['user_id'])->limit(4)->column('kind');
//获取家畜养殖具体品种
$poultryBreed = Db::name('farmer_poultry_breed')->distinct(true)->where('user_id',$params['user_id'])->limit(4)->column('breed');
$curl_result['data']['poultry_detail'] = [
'total_count' => $poultryCount,
'male_count' => $maleCount,
'maternal_count' => $maternalCount,
'kind' => $poultryKind,
'breed' => $poultryBreed
];
}
//判断是否是水产养殖户
if($curl_result['data']['is_sc_user']){
$ponds = $curl_result['data']['pond_detail'];
foreach($ponds as $k=>$v) {
//获取养殖信息
$breedData = Db::name('farmer_pond_breed')->where('user_id',$params['user_id'])->where('pond_id',$v['pond_id'])->sum('number');
//获取捕捞信息
$catchData = Db::name('farmer_pond_catch')->where('user_id',$params['user_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['user_id'])->where('pond_id',$v['pond_id'])->limit(4)->column('kind');
//获取水产养殖具体品种
$fiskBreed = Db::name('farmer_pond_breed')->distinct(true)->where('user_id',$params['user_id'])->where('pond_id',$v['pond_id'])->limit(4)->column('breed');
$ponds[$k]['kind'] = $fishKind;
$ponds[$k]['breed'] = $fiskBreed;
//获取去最新的图片
$pic = Db::name('farmer_pond_pic')->field('pic,create_time')->where('pond_id',$v['pond_id'])->findOrEmpty();
if(!empty($pic)){
$ponds[$k]['pic_detail'] = $pic;
$ponds[$k]['pic_detail']['create_time'] = date('Y-m-d H:i:s',$pic['create_time']);
}else{
$ponds[$k]['pic_detail'] = [];
}
//获取养殖时间
$firstBreed = Db::name('farmer_pond_breed')->where('user_id',$params['user_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;
}
}
$curl_result['data']['pond_detail'] = $ponds;
}
//返回数据
return json($curl_result);
}
//返回数据
return json($curl_result);
//生产队长
if($params['user_type'] == 2){
$url = env('project.worker_domain').'/api/information/captainInfo';
$curl_result = curl_post($url,[],$params);
return json($curl_result);
}
//小组服务公司
if($params['user_type'] == 1){
$url = env('project.worker_domain').'/api/information/groupServiceInfo';
$curl_result = curl_post($url,[],$params);
return json($curl_result);
}
return $this->fail('数据不存在');
}
//获取操作信息
public function actions(): Json
{
//获取参数
$params = $this->request->get(['type']);
$params = $this->request->get(['type','crop_id','pond_id']);
if(empty($params['type']) || !in_array($params['type'],[1,2,3,4])){
return $this->fail('参数错误');
}
if($params['type'] == 1){
if(empty($params['crop_id'])){
return $this->fail('参数错误');
}
}
if($params['type'] == 4){
if(empty($params['pond_id'])){
return $this->fail('参数c错误');
}
}
//获取数据
$actions = Db::name('farmer_action')->where('farmer_type',$params['type'])->select()->each(function($item){
$actionType = Db::name('farmer_action_type')->where('id',$item['type_id'])->findOrEmpty();
@ -155,7 +184,7 @@ class UserController extends BaseApiController
foreach($arr1 as $k=>$v) {
$actionIds = array_column($v['actions'],'id');
$actionsInfo = $v['actions'];
$arr1[$k]['action_record'] = Db::name('farmer_pond_record')->where('action_id','in',$actionIds)->order('id desc')->limit(5)->select()->each(function($item)use($actionsInfo){
$arr1[$k]['action_record'] = Db::name('farmer_pond_record')->where('action_id','in',$actionIds)->where('pond_id',$params['pond_id'])->order('id desc')->limit(5)->select()->each(function($item)use($actionsInfo){
foreach ($actionsInfo as $val){
if($item['action_id'] == $val['id']){
$item['action_name'] = $val['name'];
@ -200,7 +229,7 @@ class UserController extends BaseApiController
foreach($arr1 as $k=>$v) {
$actionIds = array_column($v['actions'],'id');
$actionsInfo = $v['actions'];
$arr1[$k]['action_record'] = Db::name('farmer_land_crop_record')->where('action_id','in',$actionIds)->order('id desc')->limit(5)->select()->each(function($item)use($actionsInfo){
$arr1[$k]['action_record'] = Db::name('farmer_land_crop_record')->where('action_id','in',$actionIds)->where('crop_id',$params['crop_id'])->order('id desc')->limit(5)->select()->each(function($item)use($actionsInfo){
foreach ($actionsInfo as $val){
if($item['action_id'] == $val['id']){
$item['action_name'] = $val['name'];