From 84a941a1fc1f36f85444227137d0a9fb2e8d2c63 Mon Sep 17 00:00:00 2001 From: weiz Date: Tue, 28 Nov 2023 09:23:40 +0800 Subject: [PATCH 1/5] fixed --- app/api/controller/LandController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/api/controller/LandController.php b/app/api/controller/LandController.php index 61854a62..ee1f7195 100644 --- a/app/api/controller/LandController.php +++ b/app/api/controller/LandController.php @@ -129,13 +129,14 @@ public function product(): Json { $data = Product::field('id as product_id,code,name')->where('status',1)->select()->toArray(); + $result = []; foreach ($data as $k=>$v) { $productDevice = ProductDevice::where('product_id',$v['product_id'])->select()->toArray(); - if(empty($productDevice)){ - unset($data[$k]); + if(!empty($productDevice)){ + $result[] = $v; } } - return $this->success('请求成功',$data); + return $this->success('请求成功',$result); } //绑定产品 From cd0dd00d6d8c4821c7314615990f7d041d99f177 Mon Sep 17 00:00:00 2001 From: weiz Date: Tue, 28 Nov 2023 09:54:57 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=BA=AF=E6=BA=90?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/IndexController.php | 36 ++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index b9e1eec6..a8000bac 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -2,12 +2,11 @@ namespace app\api\controller; use app\common\enum\notice\NoticeEnum; +use app\common\model\action\Action; 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 app\common\model\plant\Plant; use think\facade\Log; use think\response\Json; @@ -102,8 +101,35 @@ class IndexController extends BaseApiController } } - public function suYuan() { - + public function suYuan(): Json + { + $params = $this->request->get(['plant_id']); + if(empty($params['plant_id'])){ + return $this->fail('参数错误'); + } + $plantInfo = Plant::where('id',$params['plant_id'])->findOrEmpty(); + if($plantInfo->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['plant_date'] = date('Y-m-d',$plantInfo['plant_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_text,detail,create_time')->where('plant_id',$params['plant_id'])->select()->each(function($item){ + $item['detail'] = json_decode($item['detail'],true); + return $item; + })->toArray(); + $plantInfo['actions'] = $action; + return $this->success('请求成功',$plantInfo->toArray()); } From 5788063a9bececd30e7cb0ff1dd0d6ee67f1f876 Mon Sep 17 00:00:00 2001 From: weiz Date: Tue, 28 Nov 2023 10:32:22 +0800 Subject: [PATCH 3/5] update --- app/api/controller/IndexController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index a8000bac..f1b6d4ff 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -7,6 +7,7 @@ use app\common\model\land\Land; use app\common\model\land\LandProduct; use app\common\model\monitor\MonitorData; use app\common\model\plant\Plant; +use app\common\model\product\ProductDevice; use think\facade\Log; use think\response\Json; @@ -65,6 +66,12 @@ class IndexController extends BaseApiController 'create_time' => $monitor['create_time'] ]; } + $device = ProductDevice::where('product_id',$landProduct['product_id'])->where('device_type',3)->findOrEmpty(); +// if($device->isEmpty()){ +// $data['monitor']['video_monitor_data'] = ''; +// }else{ +// $data['monitor']['video_monitor_data'] = ''; +// } } return $this->success('请求成功',$data); } @@ -124,13 +131,11 @@ class IndexController extends BaseApiController $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_text,detail,create_time')->where('plant_id',$params['plant_id'])->select()->each(function($item){ + $action = Action::field('type,type_text,detail,create_time')->where('plant_id',$params['plant_id'])->select()->each(function($item){ $item['detail'] = json_decode($item['detail'],true); return $item; })->toArray(); $plantInfo['actions'] = $action; return $this->success('请求成功',$plantInfo->toArray()); } - - } \ No newline at end of file From 4770d6bef7f4ae08655634940c9530873dc1b936 Mon Sep 17 00:00:00 2001 From: weiz Date: Tue, 28 Nov 2023 11:27:34 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E7=9B=91=E6=8E=A7=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/IndexController.php | 33 +++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index f1b6d4ff..35549dd4 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -3,6 +3,7 @@ namespace app\api\controller; use app\common\enum\notice\NoticeEnum; use app\common\model\action\Action; +use app\common\model\device\Device; use app\common\model\land\Land; use app\common\model\land\LandProduct; use app\common\model\monitor\MonitorData; @@ -22,6 +23,7 @@ class IndexController extends BaseApiController public array $notNeedLogin = ['code','suYuan']; + //溯源首页 public function index(): Json { $params = $this->request->get(['land_id']); @@ -66,16 +68,35 @@ class IndexController extends BaseApiController 'create_time' => $monitor['create_time'] ]; } - $device = ProductDevice::where('product_id',$landProduct['product_id'])->where('device_type',3)->findOrEmpty(); -// if($device->isEmpty()){ -// $data['monitor']['video_monitor_data'] = ''; -// }else{ -// $data['monitor']['video_monitor_data'] = ''; -// } } return $this->success('请求成功',$data); } + //视频监控 + public function video() { + $params = $this->request->get(['land_id']); + if(empty($params['land_id'])){ + return $this->fail('参数错误'); + } + //获取土地绑定的产品 + $landProduct = LandProduct::where('land_id',$params['land_id'])->findOrEmpty(); + if($landProduct->isEmpty()){ + return $this->fail('当前土地未绑定设备产品'); + } + //获取监控设备 + $productDevice = ProductDevice::where('product_id',$landProduct['product_id'])->where('device_type',3)->findOrEmpty(); + if($productDevice->isEmpty()){ + return $this->fail('当前土地未绑定监控设备'); + } + //获取设备编号 + $device = Device::where('id',$productDevice['device_id'])->findOrEmpty(); + if($device->isEmpty()){ + return $this->fail('监控设备信息错误'); + } + //获取监控数据 + //todo + } + // 获取短信验证码 public function code(): Json { From 65f3d6f35cfb0d443e749ceda32073af29414969 Mon Sep 17 00:00:00 2001 From: weiz Date: Tue, 28 Nov 2023 17:02:36 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8A=A5=E8=AD=A6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/monitorController.php | 31 +++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/api/controller/monitorController.php b/app/api/controller/monitorController.php index 7eebc1c5..34f65b86 100644 --- a/app/api/controller/monitorController.php +++ b/app/api/controller/monitorController.php @@ -2,7 +2,36 @@ namespace app\api\controller; + use app\common\model\device\Device; + use app\common\model\device\MonitorAlarm; + use think\response\Json; + class monitorController extends BaseApiController { - + public array $notNeedLogin = ['alarm']; + //获取报警数据 + public function alarm(): Json + { + $params = $this->request->post(['device_code','content','value']); + if(empty($params['device_code']) || empty($params['content']) || empty($params['value'])){ + return $this->fail('缺少必要参数'); + } + //获取设备信息 + $device = Device::where('code',$params['device_code'])->findOrEmpty(); + if($device->isEmpty()){ + return $this->fail('设备不匹配'); + } + //写入数据 + $res = MonitorAlarm::create([ + 'user_id' => $device['user_id'], + 'device_id' => $device['id'], + 'type' => $device['type'], + 'content' => $params['content'], + 'value' => $params['value'], + 'solution' => '', + 'create_time' => time(), + 'update_time' => time() + ]); + return $res->id ? $this->success('数据添加成功') : $this->fail('数据添加失败'); + } } \ No newline at end of file