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