option('room_id'); $total = (int) $this->option('total'); $from = (int)$this->option('from'); $room = Room::find($room_id); if (!$room) { $this->error("病房不存在"); return false; } $this->info("开始生成任务..."); DB::beginTransaction(); try { for ($i = $from; $i <= $total; $i++) { $bed = new Bed(); $bed->name = sprintf('%02d', $i); $bed->area_id = $room->area_id; $bed->project_id = $room->project_id; $bed->room_id = $room->id; $bed->myindex = $i; $bed->building_id = $room->building_id; $bed->save(); } DB::commit(); $this->info('Bed created successfully'); return true; } catch (\Exception $e) { DB::rollBack(); $this->error($e->getMessage()); return false; } } }