Compare commits
No commits in common. "6217980419d463026c80aeaf61bd5fbd9c769cb3" and "d51397ef95b75db31952175acadc6c6eefa7d837" have entirely different histories.
6217980419
...
d51397ef95
|
@ -2,36 +2,7 @@
|
||||||
|
|
||||||
namespace app\api\controller;
|
namespace app\api\controller;
|
||||||
|
|
||||||
use app\common\model\device\Device;
|
|
||||||
use app\common\model\device\MonitorAlarm;
|
|
||||||
use think\response\Json;
|
|
||||||
|
|
||||||
class monitorController extends BaseApiController
|
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('数据添加失败');
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue