From 65f3d6f35cfb0d443e749ceda32073af29414969 Mon Sep 17 00:00:00 2001 From: weiz Date: Tue, 28 Nov 2023 17:02:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8A=A5=E8=AD=A6=E6=95=B0?= =?UTF-8?q?=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