diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index f0b780f1..25da1422 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -1,26 +1,12 @@ request->get('land_id'); + $params = $this->request->get(['land_id']); //获取土地信息 if(isset($params['land_id']) && $params['land_id'] !=''){ - $land = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty(); + $data = Land::where('user_id',$this->userId)->where('id',$params['land_id'])->order('id desc')->findOrEmpty()->toArray(); }else{ - $land = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty(); + $data = Land::where('user_id',$this->userId)->order('id desc')->findOrEmpty()->toArray(); } - if($land->isEmpty()){ + if(empty($data)){ return $this->success('请求成功',[]); } - $land['pic'] = json_decode($land['pic'],true); - //获取监测数据 - $landDeviceForSoil = LandDevice::where('land_id',$land['id'])->where('device_type',1)->findOrEmpty(); - if($landDeviceForSoil->isEmpty()){ - $land['soil_device'] = 0; + $data['pic'] = json_decode($data['pic'],true); + //获取绑定产品 + $landProduct = LandProduct::where('land_id',$data['id'])->findOrEmpty(); + if($landProduct->isEmpty()){ + $data['monitor'] = []; }else{ - $land['soil_device'] = 1; - $land['soil_monitor_data'] = SoilMonitor::where('device_id',$landDeviceForSoil['device_id'])->order('id desc')->findOrEmpty(); + $device = ProductDevice::where('product_id',$landProduct['product_id'])->select(); + foreach($device as $v) { + if($v['device_type'] == 1){ + $data['monitor']['soil_monitor_data'] = SoilMonitor::where('device_id',$v['device_id'])->order('id desc')->findOrEmpty()->toArray(); + } + if($v['device_type'] == 2){ + $data['monitor']['air_monitor_data'] = AirMonitor::where('device_id',$v['device_id'])->order('id desc')->findOrEmpty()->toArray(); + } + } } - $landDeviceForAir = LandDevice::where('land_id',$land['id'])->where('device_type',2)->findOrEmpty(); - if($landDeviceForAir->isEmpty()){ - $land['air_device'] = 0; - }else{ - $land['air_device'] = 1; - $land['air_monitor_data'] = AirMonitor::where('device_id',$landDeviceForAir['device_id'])->order('id desc')->findOrEmpty(); - } - $landDeviceForVideo = LandDevice::where('land_id',$land['id'])->where('device_type',3)->findOrEmpty(); - if($landDeviceForVideo->isEmpty()){ - $land['video_device'] = 0; - }else{ - $land['video_device'] = 1; - $land['video_monitor_data'] = ''; - } - return $this->success('请求成功',$land->toArray()); + return $this->success('请求成功',$data); } // 获取短信验证码 diff --git a/app/api/controller/LandController.php b/app/api/controller/LandController.php index 22a8f5fe..53a10f2c 100644 --- a/app/api/controller/LandController.php +++ b/app/api/controller/LandController.php @@ -9,9 +9,6 @@ use app\common\model\geo\Town; use app\common\model\geo\Village; use app\common\model\land\Land; - use app\common\model\land\LandDevice; - use app\common\model\monitor\AirMonitor; - use app\common\model\monitor\SoilMonitor; use think\response\Json; class LandController extends BaseApiController @@ -47,28 +44,6 @@ return $this->fail('土地信息不存在'); } $data['pic'] = json_decode($data['pic'],true); - //获取监测数据 - $landDeviceForSoil = LandDevice::where('land_id',$params['land_id'])->where('device_type',1)->findOrEmpty(); - if($landDeviceForSoil->isEmpty()){ - $data['soil_device'] = 0; - }else{ - $data['soil_device'] = 1; - $data['soil_monitor_data'] = SoilMonitor::where('device_id',$landDeviceForSoil['device_id'])->order('id desc')->findOrEmpty(); - } - $landDeviceForAir = LandDevice::where('land_id',$params['land_id'])->where('device_type',2)->findOrEmpty(); - if($landDeviceForAir->isEmpty()){ - $data['air_device'] = 0; - }else{ - $data['air_device'] = 1; - $data['air_monitor_data'] = AirMonitor::where('device_id',$landDeviceForAir['device_id'])->order('id desc')->findOrEmpty(); - } - $landDeviceForVideo = LandDevice::where('land_id',$params['land_id'])->where('device_type',3)->findOrEmpty(); - if($landDeviceForVideo->isEmpty()){ - $data['video_device'] = 0; - }else{ - $data['video_device'] = 1; - $data['video_monitor_data'] = ''; - } return $this->success('请求成功',$data->toArray()); } diff --git a/app/common/model/land/LandProduct.php b/app/common/model/land/LandProduct.php new file mode 100644 index 00000000..7b1e921f --- /dev/null +++ b/app/common/model/land/LandProduct.php @@ -0,0 +1,10 @@ +