2023-11-25 13:42:20 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
2023-11-28 17:02:36 +08:00
|
|
|
use app\common\model\device\Device;
|
|
|
|
use app\common\model\device\MonitorAlarm;
|
|
|
|
use think\response\Json;
|
|
|
|
|
2023-11-25 13:42:20 +08:00
|
|
|
class monitorController extends BaseApiController
|
|
|
|
{
|
2023-11-28 17:02:36 +08:00
|
|
|
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('数据添加失败');
|
|
|
|
}
|
2023-11-25 13:42:20 +08:00
|
|
|
}
|