新增报警数据接口

This commit is contained in:
weiz 2023-11-28 17:02:36 +08:00
parent d51397ef95
commit 65f3d6f35c
1 changed files with 30 additions and 1 deletions

View File

@ -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('数据添加失败');
}
}