diff --git a/app/Console/Commands/CreateBed.php b/app/Console/Commands/CreateBed.php new file mode 100644 index 0000000..5922f00 --- /dev/null +++ b/app/Console/Commands/CreateBed.php @@ -0,0 +1,75 @@ +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; + } + } +}