subMinutes(10); // 所有房間 $rooms = Room::with('branch')->where('is_online',1)->get(); foreach ($rooms as $room) { $branch = optional($room->branch); $latestStatus = MachineStatus::where('hostname', $room->type->value.$room->name) ->latest('created_at') ->first(); if (!$latestStatus || $latestStatus->created_at < $threshold) { $room->is_online = false; $room->status = RoomStatus::Error; $room->save(); $response = (new MachineStatusForwarder( $branch->external_ip ?? '', '/api/room/receiveSwitch', [ 'branch_name' => $branch->name, 'room_name' => $room->type->value.$room->name, 'command' => 'error', ] ))->forward(); $this->info("Room [{$room->name}] marked as offline (no recent MachineStatus)"); } } return 0; } }