537 lines
22 KiB
PHP
537 lines
22 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace app\api\controller;
|
||
|
|
||
|
use app\common\model\Company;
|
||
|
use app\common\model\informationg\UserInformationg;
|
||
|
use app\common\logic\BaseLogic;
|
||
|
use app\common\model\informationg\UserInformationgDemand;
|
||
|
use app\common\model\task\Task;
|
||
|
use app\common\model\task_template\TaskTemplate;
|
||
|
use app\common\model\user\User;
|
||
|
use think\response\Json;
|
||
|
|
||
|
class InformationController extends BaseApiController
|
||
|
{
|
||
|
public array $notNeedLogin = ['groupServiceInfo','captainInfo','farmerInfo','farmerInfoByPhone','farmerLandInfo','farmerPondInfo','farmerList'];
|
||
|
|
||
|
public function list()
|
||
|
{
|
||
|
$param = Request()->param();
|
||
|
[$page, $limit] = $this->getPage();
|
||
|
if (isset($param['user_id']) && $param['user_id'] > 0) {
|
||
|
$data[] = ['create_user_id', '=', $param['user_id']];
|
||
|
} else {
|
||
|
$data[] = ['company_id', '=', $this->userInfo['company_id']];
|
||
|
}
|
||
|
if (isset($param['arr']) && count($param['arr']) > 0) {
|
||
|
$data[] = ['id', 'in', $param['arr']];
|
||
|
}
|
||
|
if (isset($param['is_update'])) {
|
||
|
if ($param['is_update'] > 0) {
|
||
|
$data[] = ['is_update', '=', 1];
|
||
|
} else {
|
||
|
$data[] = ['is_update', '=', 0];
|
||
|
}
|
||
|
}
|
||
|
$res = UserInformationg::list($data, $page, $limit);
|
||
|
if ($res != true) {
|
||
|
return $this->fail(BaseLogic::getError());
|
||
|
}
|
||
|
return $this->success('ok', $res->toArray());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 添加
|
||
|
*/
|
||
|
public function add()
|
||
|
{
|
||
|
$param = Request()->param();
|
||
|
$user = User::where('id', $this->userId)->find();
|
||
|
if (isset($param['street']) && $param['street'] > 0) {
|
||
|
$param['street_id'] = $param['street'];
|
||
|
} else {
|
||
|
$param['street_id'] = $user['street'];
|
||
|
}
|
||
|
if (isset($param['village']) && $param['village'] > 0) {
|
||
|
$param['village_id'] = $param['village'];
|
||
|
} else {
|
||
|
$param['village_id'] = $user['village'];
|
||
|
}
|
||
|
if (isset($param['brigade']) && $param['brigade'] > 0) {
|
||
|
$param['brigade_id'] = $param['brigade'];
|
||
|
} else {
|
||
|
$param['brigade_id'] = $user['brigade'];
|
||
|
}
|
||
|
$param['admin_id'] = $this->userId;
|
||
|
$param['company_id'] = $this->userInfo['company_id'];
|
||
|
$param['province_id'] = $user['province'];
|
||
|
$param['city_id'] = $user['city'];
|
||
|
$param['area_id'] = $user['area'];
|
||
|
$res = UserInformationg::add($param);
|
||
|
if ($res != true) {
|
||
|
return $this->fail(BaseLogic::getError());
|
||
|
}
|
||
|
return $this->success('成功');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 详情
|
||
|
*/
|
||
|
public function details()
|
||
|
{
|
||
|
$param = Request()->param();
|
||
|
$res = UserInformationg::details($param['id']);
|
||
|
if ($res != true) {
|
||
|
return $this->fail(BaseLogic::getError());
|
||
|
}
|
||
|
return $this->success('成功', $res->toArray());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 商机更新
|
||
|
*/
|
||
|
public function opportunity_update()
|
||
|
{
|
||
|
$param = Request()->param();
|
||
|
foreach ($param['datas'] as $k => $v) {
|
||
|
$res = UserInformationg::informationg_demand($v, $param['id'], $this->userId);
|
||
|
}
|
||
|
if ($res != true) {
|
||
|
return $this->fail(BaseLogic::getError());
|
||
|
}
|
||
|
if (isset($param['task_id']) && $param['task_id'] > 0) {
|
||
|
$task = Task::where('id', $param['task_id'])->find();
|
||
|
$extend = $task['extend'];
|
||
|
if (isset($extend['informationg']['update'])) {
|
||
|
$extend['informationg']['update'] += 1;
|
||
|
} else {
|
||
|
$extend['informationg']['update'] = 1;
|
||
|
}
|
||
|
$extend['informationg']['ids'][] = $param['id'];
|
||
|
$task->extend = json_encode($extend);
|
||
|
if ($extend['informationg']['update'] >= 5) {
|
||
|
$task->status = 3;
|
||
|
}
|
||
|
$task->save();
|
||
|
TaskTemplate::where('id', $task['template_id'])->inc('information_count', 1)->update();
|
||
|
}
|
||
|
|
||
|
UserInformationg::where('id', $param['id'])->update(['update_time' => time(), 'is_update' => 1]);
|
||
|
return $this->success('成功');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑
|
||
|
*/
|
||
|
public function edit()
|
||
|
{
|
||
|
$param = Request()->param();
|
||
|
$res = UserInformationg::edit($param);
|
||
|
if ($res != true) {
|
||
|
return $this->fail(BaseLogic::getError());
|
||
|
}
|
||
|
return $this->success('成功');
|
||
|
}
|
||
|
|
||
|
//获取吓阻服务公司用户信息
|
||
|
public function groupServiceInfo(): Json
|
||
|
{
|
||
|
//获取参数
|
||
|
$params = $this->request->post(['user_id']);
|
||
|
if(empty($params['user_id'])){
|
||
|
return $this->fail('参数错误_worker');
|
||
|
}
|
||
|
$userData = User::field('id,company_id,nickname as name,avatar')->where('id',$params['user_id'])->findOrEmpty();
|
||
|
if($userData->isEmpty()){
|
||
|
return $this->fail('用户数据不存在');
|
||
|
}
|
||
|
$companyData = Company::field('id,company_name,company_type')->where('id',$userData['company_id'])->findOrEmpty();
|
||
|
if($companyData->isEmpty() || $companyData['company_type'] != 18){
|
||
|
return $this->fail('当前用户不是小组服务公司用户');
|
||
|
}
|
||
|
$userData['company_name'] = $companyData['company_name'];
|
||
|
//获取小组服务公司下面的队长
|
||
|
$captainList = User::field('id,nickname as name,avatar,province,province province_name,city,city city_name,area,area area_name,street,street street_name,village,village village_name,brigade,brigade brigade_name')->where('company_id',$userData['company_id'])->where('is_captain',1)->select()->each(function($item){
|
||
|
$item['address'] = $item['province_name'].$item['city_name'].$item['area_name'].$item['street_name'].$item['village_name'].$item['brigade_name'];
|
||
|
unset($item['province'],$item['province_name'],$item['city'],$item['city_name'],$item['area'],$item['area_name'],$item['street'],$item['street_name'],$item['village'],$item['village_name'],$item['brigade'],$item['brigade_name']);
|
||
|
$farmerList = UserInformationg::where('create_user_id', $item['id'])->field('id')->select()->each(function($val){
|
||
|
//获取农户档案详情
|
||
|
$information = UserInformationgDemand::field('id,category_child,data')->where('information_id', $val['id'])->where('category_id',6)->where('category_child','in','7,32')->order('id', 'desc')->select()->toArray();
|
||
|
//总面积
|
||
|
$val['land_total_area'] = 0;
|
||
|
$val['pond_total_area'] = 0;
|
||
|
$val['animal_total_area'] = 0;
|
||
|
$val['poultry_total_area'] = 0;
|
||
|
//种养类型
|
||
|
$val['is_zz_user'] = false;
|
||
|
$val['is_sc_user'] = false;
|
||
|
$val['is_jc_user'] = false;
|
||
|
$val['is_jq_user'] = false;
|
||
|
foreach($information as $v){
|
||
|
if($v['category_child'] == 7){
|
||
|
$val['is_zz_user'] = true;
|
||
|
$val['land_total_area'] += floatval($v['data']['area']);
|
||
|
}
|
||
|
if($v['category_child'] == 32){
|
||
|
if($v['data']['breeding_type'] == 1){//水产
|
||
|
$val['is_sc_user'] = true;
|
||
|
$val['pond_total_area'] += floatval($v['data']['area']);
|
||
|
}elseif ($v['data']['breeding_type'] == 2) {//脯乳动物
|
||
|
$val['is_jc_user'] = true;
|
||
|
$val['animal_total_area'] += floatval($v['data']['area']);
|
||
|
}elseif ($v['data']['breeding_type'] == 3){//家禽
|
||
|
$val['is_jq_user'] = true;
|
||
|
$val['poultry_total_area'] += floatval($v['data']['area']);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$val['total_area'] = $val['land_total_area'] + $val['pond_total_area'] + $val['animal_total_area'] + $val['poultry_total_area'];
|
||
|
return $val;
|
||
|
})->toArray();
|
||
|
$item['farmer_total'] = count($farmerList);
|
||
|
$item['farmer_area'] = array_sum(array_column($farmerList,'total_area'));
|
||
|
$item['farmer_zz_total'] = 0;
|
||
|
$item['farmer_sc_total'] = 0;
|
||
|
$item['farmer_jc_total'] = 0;
|
||
|
$item['farmer_jq_total'] = 0;
|
||
|
$item['farmer_zz_area'] = 0;
|
||
|
$item['farmer_sc_area'] = 0;
|
||
|
$item['farmer_jc_area'] = 0;
|
||
|
$item['farmer_jq_area'] = 0;
|
||
|
foreach($farmerList as $v){
|
||
|
if($v['is_zz_user']){
|
||
|
$item['farmer_zz_total'] += 1;
|
||
|
}
|
||
|
if($v['is_sc_user']){
|
||
|
$item['farmer_sc_total'] += 1;
|
||
|
}
|
||
|
if($v['is_jc_user']){
|
||
|
$item['farmer_jc_total'] += 1;
|
||
|
}
|
||
|
if($v['is_jq_user']){
|
||
|
$item['farmer_jq_total'] += 1;
|
||
|
}
|
||
|
$item['farmer_zz_area'] += $v['land_total_area'];
|
||
|
$item['farmer_sc_area'] += $v['pond_total_area'];
|
||
|
$item['farmer_jc_area'] += $v['animal_total_area'];
|
||
|
$item['farmer_jq_area'] += $v['poultry_total_area'];
|
||
|
}
|
||
|
return $item;
|
||
|
})->toArray();
|
||
|
$userData['captain_list'] = $captainList;
|
||
|
return $this->success('请求成功',$userData->toArray());
|
||
|
}
|
||
|
|
||
|
//获取生产队长信息
|
||
|
public function captainInfo(): Json
|
||
|
{
|
||
|
//获取参数
|
||
|
$params = $this->request->post(['user_id']);
|
||
|
if(empty($params['user_id'])){
|
||
|
return $this->fail('参数错误_worker');
|
||
|
}
|
||
|
$userData = User::field('id,nickname as name,avatar,province,province province_name,city,city city_name,area,area area_name,street,street street_name,village,village village_name,brigade,brigade brigade_name')->where('id',$params['user_id'])->where('is_captain',1)->findOrEmpty();
|
||
|
if($userData->isEmpty()){
|
||
|
return $this->fail('用户数据不存在');
|
||
|
}
|
||
|
$userData['address'] = $userData['province_name'].$userData['city_name'].$userData['area_name'].$userData['street_name'].$userData['village_name'].$userData['brigade_name'];
|
||
|
unset($userData['province'],$userData['province_name'],$userData['city'],$userData['city_name'],$userData['area'],$userData['area_name'],$userData['street'],$userData['street_name'],$userData['village'],$userData['village_name'],$userData['brigade'],$userData['brigade_name']);
|
||
|
//获取生产队长下面的农户
|
||
|
$farmerList = UserInformationg::where('create_user_id', $params['user_id'])->field('id,name,phone,area_id,street_id,village_id,brigade_id,area_id area_name,street_id street_name,village_id village_name,brigade_id brigade_name')->select()->each(function($item){
|
||
|
$item['address'] = $item['area_name'].$item['street_name'].$item['village_name'].$item['brigade_name'];
|
||
|
unset($item['area_id'],$item['area_name'],$item['street_id'],$item['street_name'],$item['village_id'],$item['village_name'],$item['brigade_id'],$item['brigade_name']);
|
||
|
//获取农户档案详情
|
||
|
$information = UserInformationgDemand::field('id,category_child,data')->where('information_id', $item['id'])->where('category_id',6)->where('category_child','in','7,32')->order('id', 'desc')->select()->toArray();
|
||
|
//总面积
|
||
|
$item['land_total_area'] = 0;
|
||
|
$item['pond_total_area'] = 0;
|
||
|
$item['animal_total_area'] = 0;
|
||
|
$item['poultry_total_area'] = 0;
|
||
|
//种养类型
|
||
|
$item['is_zz_user'] = false;
|
||
|
$item['is_sc_user'] = false;
|
||
|
$item['is_jc_user'] = false;
|
||
|
$item['is_jq_user'] = false;
|
||
|
foreach($information as $v){
|
||
|
if($v['category_child'] == 7){
|
||
|
$item['is_zz_user'] = true;
|
||
|
$item['land_total_area'] += floatval($v['data']['area']);
|
||
|
}
|
||
|
if($v['category_child'] == 32){
|
||
|
if($v['data']['breeding_type'] == 1){//水产
|
||
|
$item['is_sc_user'] = true;
|
||
|
$item['pond_total_area'] += floatval($v['data']['area']);
|
||
|
}elseif ($v['data']['breeding_type'] == 2) {//脯乳动物
|
||
|
$item['is_jc_user'] = true;
|
||
|
$item['animal_total_area'] += floatval($v['data']['area']);
|
||
|
}elseif ($v['data']['breeding_type'] == 3){//家禽
|
||
|
$item['is_jq_user'] = true;
|
||
|
$item['poultry_total_area'] += floatval($v['data']['area']);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$item['total_area'] = $item['land_total_area'] + $item['pond_total_area'] + $item['animal_total_area'] + $item['poultry_total_area'];
|
||
|
return $item;
|
||
|
})->toArray();
|
||
|
$userData['farmer_total'] = count($farmerList);
|
||
|
$userData['farmer_area'] = array_sum(array_column($farmerList,'total_area'));
|
||
|
$userData['farmer_zz_total'] = 0;
|
||
|
$userData['farmer_sc_total'] = 0;
|
||
|
$userData['farmer_jc_total'] = 0;
|
||
|
$userData['farmer_jq_total'] = 0;
|
||
|
$userData['farmer_zz_area'] = 0;
|
||
|
$userData['farmer_sc_area'] = 0;
|
||
|
$userData['farmer_jc_area'] = 0;
|
||
|
$userData['farmer_jq_area'] = 0;
|
||
|
foreach($farmerList as $v){
|
||
|
if($v['is_zz_user']){
|
||
|
$userData['farmer_zz_total'] += 1;
|
||
|
}
|
||
|
if($v['is_sc_user']){
|
||
|
$userData['farmer_sc_total'] += 1;
|
||
|
}
|
||
|
if($v['is_jc_user']){
|
||
|
$userData['farmer_jc_total'] += 1;
|
||
|
}
|
||
|
if($v['is_jq_user']){
|
||
|
$userData['farmer_jq_total'] += 1;
|
||
|
}
|
||
|
$userData['farmer_zz_area'] += $v['land_total_area'];
|
||
|
$userData['farmer_sc_area'] += $v['pond_total_area'];
|
||
|
$userData['farmer_jc_area'] += $v['animal_total_area'];
|
||
|
$userData['farmer_jq_area'] += $v['poultry_total_area'];
|
||
|
}
|
||
|
$userData['farmer_list'] = $farmerList;
|
||
|
return $this->success('请求成功',$userData->toArray());
|
||
|
}
|
||
|
|
||
|
//获取农户信息,该接口溯源系统调用
|
||
|
public function farmerInfo(): Json
|
||
|
{
|
||
|
//获取参数
|
||
|
$params = $this->request->post(['user_id']);
|
||
|
if(empty($params['user_id'])){
|
||
|
return $this->fail('参数错误_worker');
|
||
|
}
|
||
|
//获取农户信息
|
||
|
$farmerInfo = UserInformationg::alias('f')
|
||
|
->leftJoin('company c','f.company_id = c.id')
|
||
|
->leftJoin('user u','u.id = f.create_user_id')
|
||
|
->leftJoin('user g','g.id = c.user_id')
|
||
|
->where('f.id', $params['user_id'])
|
||
|
->field('f.id,f.create_user_id,f.company_id,f.name,f.phone,f.area_id,f.street_id,f.village_id,f.brigade_id,f.area_id area_name,f.street_id street_name,f.village_id village_name,f.brigade_id brigade_name,c.company_name,f.address,u.nickname as captain_name,g.nickname as group_name')
|
||
|
->findOrEmpty()->toArray();
|
||
|
if(empty($farmerInfo)){
|
||
|
return $this->fail('用户不存在_worker');
|
||
|
}
|
||
|
unset($farmerInfo['area_id'],$farmerInfo['street_id'],$farmerInfo['village_id'],$farmerInfo['brigade_id']);
|
||
|
$data = UserInformationgDemand::field('id,category_child,data')->where('information_id', $params['user_id'])->where('category_id',6)->where('category_child','in','7,32')->order('id', 'desc')->select()->toArray();
|
||
|
//是否是种植户
|
||
|
$farmerInfo['is_zz_user'] = false;
|
||
|
//是否是水产养殖户
|
||
|
$farmerInfo['is_sc_user'] = false;
|
||
|
//是否是家禽养殖户
|
||
|
$farmerInfo['is_jq_user'] = false;
|
||
|
//是否是大型动物养殖户
|
||
|
$farmerInfo['is_dw_user'] = false;
|
||
|
//土地总面积
|
||
|
$farmerInfo['total_land_area'] = 0;
|
||
|
//池塘总面积
|
||
|
$farmerInfo['total_pond_area'] = 0;
|
||
|
//家禽养殖场总面积
|
||
|
$farmerInfo['total_henhouse_area'] = 0;
|
||
|
//动物养殖场总面积
|
||
|
$farmerInfo['total_pasture_area'] = 0;
|
||
|
foreach($data as $v){
|
||
|
if($v['category_child'] == 7){
|
||
|
$farmerInfo['is_zz_user'] = true;
|
||
|
$farmerInfo['total_land_area'] += floatval($v['data']['area']);
|
||
|
$farmerInfo['land_detail'][] = [
|
||
|
'land_id' => $v['id'],
|
||
|
'land_area' => $v['data']['area'],
|
||
|
'land_notes' => $v['data']['notes'],
|
||
|
];
|
||
|
}
|
||
|
if($v['category_child'] == 32){
|
||
|
if($v['data']['breeding_type'] == 1){//水产
|
||
|
$farmerInfo['is_sc_user'] = true;
|
||
|
$farmerInfo['total_pond_area'] += floatval($v['data']['area']);
|
||
|
$farmerInfo['pond_detail'][] = [
|
||
|
'pond_id' => $v['id'],
|
||
|
'pond_area' => $v['data']['area'],
|
||
|
'pond_notes' => $v['data']['notes'],
|
||
|
];
|
||
|
}elseif ($v['data']['breeding_type'] == 2) {//脯乳动物
|
||
|
$farmerInfo['is_jq_user'] = true;
|
||
|
$farmerInfo['total_henhouse_area'] += floatval($v['data']['area']);
|
||
|
}elseif ($v['data']['breeding_type'] == 3){//家禽
|
||
|
$farmerInfo['is_dw_user'] = true;
|
||
|
$farmerInfo['total_pasture_area'] += floatval($v['data']['area']);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return $this->success('请求成功',$farmerInfo);
|
||
|
}
|
||
|
|
||
|
//通过手机号码查找农户
|
||
|
public function farmerInfoByPhone(): Json
|
||
|
{
|
||
|
$params = $this->request->post(['phone']);
|
||
|
if(empty($params['phone'])){
|
||
|
return $this->fail('参数错误');
|
||
|
}
|
||
|
$data = UserInformationg::where('phone',$params['phone'])
|
||
|
->field('id,name,phone,area_id,street_id,village_id,brigade_id,area_id area_name,street_id street_name,village_id village_name,brigade_id brigade_name,address')
|
||
|
->findOrEmpty();
|
||
|
return !$data->isEmpty() ? $this->success('请求成功',$data->toArray()) : $this->fail('请求失败');
|
||
|
}
|
||
|
|
||
|
//获取农户土地信息
|
||
|
public function farmerLandInfo(): Json
|
||
|
{
|
||
|
//获取参数
|
||
|
$params = $this->request->post(['user_id','land_id']);
|
||
|
if(empty($params['user_id']) || empty($params['land_id'])){
|
||
|
return $this->fail('参数错误_worker');
|
||
|
}
|
||
|
//获取农户信息
|
||
|
$data = UserInformationgDemand::field('id,data')->where('id',$params['land_id'])->where('information_id', $params['user_id'])->where('category_id',6)->where('category_child',7)->findOrEmpty()->toArray();
|
||
|
if(empty($data)){
|
||
|
return $this->fail('数据不存在_worker');
|
||
|
}
|
||
|
$resData = [
|
||
|
'land_id' => $data['id'],
|
||
|
'land_area' => $data['data']['area']
|
||
|
];
|
||
|
return $this->success('请求成功',$resData);
|
||
|
}
|
||
|
|
||
|
//获取农户鱼塘信息
|
||
|
public function farmerPondInfo(): Json
|
||
|
{
|
||
|
//获取参数
|
||
|
$params = $this->request->post(['user_id','pond_id']);
|
||
|
if(empty($params['user_id']) || empty($params['pond_id'])){
|
||
|
return $this->fail('参数错误_worker');
|
||
|
}
|
||
|
//获取农户信息
|
||
|
$data = UserInformationgDemand::field('id,data')->where('id',$params['pond_id'])->where('information_id', $params['user_id'])->where('category_id',6)->where('category_child',32)->findOrEmpty()->toArray();
|
||
|
if(empty($data) || empty($data['data'])){
|
||
|
return $this->fail('数据不存在_worker');
|
||
|
}
|
||
|
if($data['data']['breeding_type'] != 1){
|
||
|
return $this->fail('数据错误_work');
|
||
|
}
|
||
|
$resData = [
|
||
|
'pond_id' => $data['id'],
|
||
|
'pond_area' => $data['data']['area']
|
||
|
];
|
||
|
return $this->success('请求成功',$resData);
|
||
|
}
|
||
|
|
||
|
//获取农户列表
|
||
|
public function farmerList(): Json
|
||
|
{
|
||
|
$params = $this->request->post(['farmer_name','farmer_phone','group_name','captain_name','page_no','page_size']);
|
||
|
if(empty($params['page_no']) || empty($params['page_size'])){
|
||
|
return $this->fail('参数错误');
|
||
|
}
|
||
|
$search = [];
|
||
|
if(!empty($params['farmer_name'])){
|
||
|
$search[] = ['f.name','like','%'.$params['farmer_name'].'%'];
|
||
|
}
|
||
|
if(!empty($params['farmer_phone'])){
|
||
|
$search[] = ['f.phone','like','%'.$params['farmer_phone'].'%'];
|
||
|
}
|
||
|
if(!empty($params['group_name'])){
|
||
|
$search[] = ['g.nickname','like','%'.$params['group_name'].'%'];
|
||
|
}
|
||
|
if(!empty($params['captain_name'])){
|
||
|
$search[] = ['u.nickname','like','%'.$params['captain_name'].'%'];
|
||
|
}
|
||
|
$data = UserInformationg::alias('f')
|
||
|
->field('f.id,f.create_user_id,f.company_id,f.name,f.phone,f.area_id,f.street_id,f.village_id,f.brigade_id,c.company_name,u.nickname as captain_name,g.nickname as group_name,f.area_id area_name,f.street_id street_name,f.village_id village_name,f.brigade_id brigade_name,f.address')
|
||
|
->leftJoin('company c','f.company_id = c.id')
|
||
|
->leftJoin('user u','u.id = f.create_user_id')
|
||
|
->leftJoin('user g','g.id = c.user_id')
|
||
|
->where($search)
|
||
|
->page($params['page_no'],$params['page_size'])->order('id desc')->select()
|
||
|
->each(function($item){
|
||
|
$item['address'] = $item['area_name'].$item['street_name'].$item['village_name'].$item['brigade_name'].$item['address'];
|
||
|
unset($item['area_name'],$item['street_name'],$item['village_name'],$item['brigade_name'],$item['area_id'],$item['street_id'],$item['village_id'],$item['brigade_id']);
|
||
|
$userInformationgDemand = UserInformationgDemand::field('id,category_child,data')->where('information_id', $item['id'])->where('category_id',6)->where('category_child','in','7,32')->order('id', 'desc')->select()->toArray();
|
||
|
//是否是种植户
|
||
|
$is_zz_user = false;
|
||
|
//是否是水产养殖户
|
||
|
$is_sc_user = false;
|
||
|
//是否是家禽养殖户
|
||
|
$is_jq_user = false;
|
||
|
//是否是大型动物养殖户
|
||
|
$is_dw_user = false;
|
||
|
//土地总面积
|
||
|
$total_land_area = 0;
|
||
|
//池塘总面积
|
||
|
$total_pond_area = 0;
|
||
|
//家禽养殖场总面积
|
||
|
$total_henhouse_area = 0;
|
||
|
//动物养殖场总面积
|
||
|
$total_pasture_area = 0;
|
||
|
foreach($userInformationgDemand as $v){
|
||
|
if($v['category_child'] == 7){
|
||
|
$is_zz_user = true;
|
||
|
$total_land_area += floatval($v['data']['area']);
|
||
|
}
|
||
|
if($v['category_child'] == 32){
|
||
|
if($v['data']['breeding_type'] == 1){//水产
|
||
|
$is_sc_user = true;
|
||
|
$total_pond_area += floatval($v['data']['area']);
|
||
|
}elseif ($v['data']['breeding_type'] == 2) {//脯乳动物
|
||
|
$is_jq_user = true;
|
||
|
$total_henhouse_area += floatval($v['data']['area']);
|
||
|
}elseif ($v['data']['breeding_type'] == 3){//家禽
|
||
|
$is_dw_user = true;
|
||
|
$total_pasture_area += floatval($v['data']['area']);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
$str = [];
|
||
|
$area = [];
|
||
|
if($is_zz_user){
|
||
|
$str[] = '种植户';
|
||
|
$area[] = $total_land_area;
|
||
|
}
|
||
|
if($is_sc_user){
|
||
|
$str[] = '水产养殖户';
|
||
|
$area[] = $total_pond_area;
|
||
|
}
|
||
|
if($is_jq_user){
|
||
|
$str[] = '家禽养殖户';
|
||
|
$area[] = $total_henhouse_area;
|
||
|
}
|
||
|
if($is_dw_user){
|
||
|
$str[] = '家畜养殖户';
|
||
|
$area[] = $total_pasture_area;
|
||
|
}
|
||
|
$item['farmer_type'] = implode('/',$str);
|
||
|
$item['farmer_area'] = implode('/',$area);
|
||
|
return $item;
|
||
|
})->toArray();
|
||
|
$count = UserInformationg::alias('f')
|
||
|
->field('f.id,f.create_user_id,f.company_id,f.name,f.phone,f.area_id,f.street_id,f.village_id,f.brigade_id,c.company_name,u.nickname as captain_name,g.nickname as group_name,f.area_id area_name,f.street_id street_name,f.village_id village_name,f.brigade_id brigade_name,f.address')
|
||
|
->leftJoin('company c','f.company_id = c.id')
|
||
|
->leftJoin('user u','u.id = f.create_user_id')
|
||
|
->leftJoin('user g','g.id = c.user_id')
|
||
|
->where($search)
|
||
|
->count();
|
||
|
$result = [
|
||
|
'count' => $count,
|
||
|
'page_no' => $params['page_no'],
|
||
|
'page_size' => $params['page_size'],
|
||
|
'lists' => $data
|
||
|
];
|
||
|
return $this->success('请求成功',$result);
|
||
|
|
||
|
}
|
||
|
}
|