This commit is contained in:
chenbo 2024-01-31 18:33:53 +08:00
parent e63dec3f43
commit ae1a9bf9b2
1 changed files with 20 additions and 22 deletions

View File

@ -4,6 +4,7 @@ namespace app\api\controller;
use app\common\enum\notice\NoticeEnum; use app\common\enum\notice\NoticeEnum;
use app\common\logic\RemoteRequestLogic; use app\common\logic\RemoteRequestLogic;
use app\common\model\action\Action; use app\common\model\action\Action;
use app\common\model\animal_info\AnimalInfo;
use app\common\model\device\Device; use app\common\model\device\Device;
use app\common\model\device\MonitorThreshold; use app\common\model\device\MonitorThreshold;
use app\common\model\farm\Farm; use app\common\model\farm\Farm;
@ -16,6 +17,7 @@ use app\common\model\LandCollection;
use app\common\model\monitor\MonitorData; use app\common\model\monitor\MonitorData;
use app\common\model\plant\Plant; use app\common\model\plant\Plant;
use app\common\model\product\ProductDevice; use app\common\model\product\ProductDevice;
use app\common\model\suyuan_operation\AnimalOperateAction;
use think\facade\Log; use think\facade\Log;
use think\response\Json; use think\response\Json;
@ -120,34 +122,30 @@ class IndexController extends BaseApiController
public function suYuan(): Json public function suYuan(): Json
{ {
$params = $this->request->get(['plant_id']); $params = $this->request->get(['animal_sn']);
if(empty($params['plant_id'])){ $pageNo = $this->request->get('page_no', 1);
$pageSize = $this->request->get('page_size', 5);
if(empty($params['animal_sn'])){
return $this->fail('参数错误'); return $this->fail('参数错误');
} }
$plantInfo = Plant::where('id',$params['plant_id'])->findOrEmpty(); $animalInfo = AnimalInfo::where('sn',$params['animal_sn'])->findOrEmpty();
if($plantInfo->isEmpty()){ if($animalInfo->isEmpty()){
return $this->fail('种植信息错误'); return $this->fail('档案信息错误');
} }
if($plantInfo['status'] != 2){
return $this->fail('种植信息状态错误');
}
$landInfo = Land::where('id',$plantInfo['land_id'])->findOrEmpty();
if($landInfo->isEmpty()){
return $this->fail('土地信息错误');
}
$plantInfo['pic'] = json_decode($plantInfo['pic'],true);
$plantInfo['group_day'] = floor(($plantInfo['harvest_date'] - $plantInfo['plant_date']) / 86400);
$plantInfo['plant_date'] = date('Y-m-d',$plantInfo['plant_date']);
$plantInfo['harvest_date'] = date('Y-m-d',$plantInfo['harvest_date']);
$plantInfo['land_name'] = $landInfo['title'];
$plantInfo['land_area'] = $landInfo['total_area'];
$plantInfo['land_address'] = $landInfo['province_name'].$landInfo['city_name'].$landInfo['county_name'].$landInfo['town_name'].$landInfo['village_name'].$landInfo['group_name'];
//获取操作 //获取操作
$action = Action::field('type,type_text,detail,create_time')->where('plant_id',$params['plant_id'])->select()->each(function($item){ $action = AnimalOperateAction::field('type,type_text,detail,create_time')->where('fence_house_id',$animalInfo['fence_house_id'])->whereOr('animal_info_id', $animalInfo['id'])
->page($pageNo, $pageSize)
->select()->each(function($item){
$item['detail'] = json_decode($item['detail'],true); $item['detail'] = json_decode($item['detail'],true);
return $item; return $item;
})->toArray(); })->toArray();
$plantInfo['actions'] = $action; $data = [
return $this->success('请求成功',$plantInfo->toArray()); 'lists' => $action,
'count' => AnimalOperateAction::where('fence_house_id',$animalInfo['fence_house_id'])->whereOr('animal_info_id', $animalInfo['id'])->count(),
'page_no' => $pageNo,
'page_size' => $pageSize,
];
return $this->success('请求成功', $data);
} }
} }