filled('notify_type')) { $this->handleDeviceStateNotify($request); } return response()->json(['code' => 0, 'msg' => 'ok']); } /** * 设备状态通知 */ protected function handleDeviceStateNotify(Request $request): void { if ($request->notify_type !== 'online_state_change') { return; } foreach ($request->input('data', []) as $item) { if (is_null($device = Device::where('sn', $item['device_id'])->first())) { continue; } if ($request->filled('online_state')) { $state = match ((int) $request->online_state) { 0 => Device::STATE_OFFLINE, 1 => Device::STATE_ONLINE, default => $device->state, }; $device->forceFill([ 'state' => $state, ])->save(); } } } }