From 762a5c5f11d20f51e9dab5eda39883c4eae9ba79 Mon Sep 17 00:00:00 2001 From: weiz Date: Mon, 27 Nov 2023 17:30:04 +0800 Subject: [PATCH 1/2] update --- app/api/controller/IndexController.php | 36 ++++++++++++++++++------ app/common/model/monitor/MonitorData.php | 10 +++++++ 2 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 app/common/model/monitor/MonitorData.php diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 25da1422..b9e1eec6 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -5,6 +5,7 @@ use app\common\enum\notice\NoticeEnum; use app\common\model\land\Land; use app\common\model\land\LandProduct; use app\common\model\monitor\AirMonitor; +use app\common\model\monitor\MonitorData; use app\common\model\monitor\SoilMonitor; use app\common\model\product\ProductDevice; use think\facade\Log; @@ -39,15 +40,32 @@ class IndexController extends BaseApiController if($landProduct->isEmpty()){ $data['monitor'] = []; }else{ - $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(); - } - } + $monitor = MonitorData::where('product_id',$landProduct['product_id'])->order('id desc')->findOrEmpty(); + if($monitor->isEmpty()){ + $data['monitor'] = []; + }else{ + $data['monitor']['soil_monitor_data'] = [ + 'wind_direction'=>$monitor['wind_direction'], + 'wind_speed'=>$monitor['wind_speed'], + 'air_temperature'=>$monitor['air_temperature'], + 'air_moisture'=>$monitor['air_moisture'], + 'co2_content'=>$monitor['co2_content'], + 'pressure'=>$monitor['pressure'], + 'rainfall'=>$monitor['rainfall'], + 'light_intensity'=>$monitor['light_intensity'], + 'create_time' => $monitor['create_time'] + ]; + $data['monitor']['air_monitor_data'] = [ + 'soil_temperature'=>$monitor['soil_temperature'], + 'soil_moisture'=>$monitor['soil_moisture'], + 'conductivity'=>$monitor['conductivity'], + 'ph'=>$monitor['ph'], + 'n_content'=>$monitor['n_content'], + 'p_content'=>$monitor['p_content'], + 'k_content'=>$monitor['k_content'], + 'create_time' => $monitor['create_time'] + ]; + } } return $this->success('请求成功',$data); } diff --git a/app/common/model/monitor/MonitorData.php b/app/common/model/monitor/MonitorData.php new file mode 100644 index 00000000..8fad1708 --- /dev/null +++ b/app/common/model/monitor/MonitorData.php @@ -0,0 +1,10 @@ + Date: Mon, 27 Nov 2023 17:52:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=8D=E6=A4=8D?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/PlantController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/api/controller/PlantController.php b/app/api/controller/PlantController.php index 2809e3d1..08deb26f 100644 --- a/app/api/controller/PlantController.php +++ b/app/api/controller/PlantController.php @@ -24,6 +24,20 @@ return $this->success('请求成功',$data); } + public function detail(): Json + { + $params = $this->request->get(['plant_id']); + if(empty($params['plant_id'])){ + return $this->fail('缺少必要参数'); + } + $data = Plant::where('id',$params['plant_id'])->findOrEmpty(); + if($data->isEmpty()){ + return $this->fail('种植信息错误'); + } + $data['pic'] = json_decode($data['pic'],true); + return $this->success('请求成功',$data->toArray()); + } + //添加种植 public function add(): Json {