diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index da2baa9..ef3a63b 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -4,6 +4,7 @@ namespace app\api\controller; use app\common\enum\notice\NoticeEnum; use app\common\logic\RemoteRequestLogic; use app\common\model\action\Action; +use app\common\model\animal_info\AnimalInfo; use app\common\model\device\Device; use app\common\model\device\MonitorThreshold; 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\plant\Plant; use app\common\model\product\ProductDevice; +use app\common\model\suyuan_operation\AnimalOperateAction; use think\facade\Log; use think\response\Json; @@ -120,34 +122,30 @@ class IndexController extends BaseApiController public function suYuan(): Json { - $params = $this->request->get(['plant_id']); - if(empty($params['plant_id'])){ + $params = $this->request->get(['animal_sn']); + $pageNo = $this->request->get('page_no', 1); + $pageSize = $this->request->get('page_size', 5); + if(empty($params['animal_sn'])){ return $this->fail('参数错误'); } - $plantInfo = Plant::where('id',$params['plant_id'])->findOrEmpty(); - if($plantInfo->isEmpty()){ - return $this->fail('种植信息错误'); + $animalInfo = AnimalInfo::where('sn',$params['animal_sn'])->findOrEmpty(); + if($animalInfo->isEmpty()){ + 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); return $item; })->toArray(); - $plantInfo['actions'] = $action; - return $this->success('请求成功',$plantInfo->toArray()); + $data = [ + '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); } } \ No newline at end of file