| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Module\Game\Dtos;
- /**
- * 消耗组DTO
- */
- class ConsumeGroupDto
- {
- /**
- * 消耗组ID
- *
- * @var int
- */
- public int $id;
- /**
- * 消耗组名称
- *
- * @var string
- */
- public string $name;
- /**
- * 消耗组编码
- *
- * @var string
- */
- public string $code;
- /**
- * 消耗组描述
- *
- * @var string|null
- */
- public ?string $description;
- /**
- * 消耗项列表
- *
- * @var ConsumeItemDto[]
- */
- public array $items = [];
- /**
- * 从模型创建DTO
- *
- * @param \App\Module\Game\Models\GameConsumeGroup $model
- * @param bool $withItems 是否包含消耗项
- * @return self
- */
- public static function fromModel($model, bool $withItems = false): self
- {
- $dto = new self();
- $dto->id = $model->id;
- $dto->name = $model->name;
- $dto->code = $model->code;
- $dto->description = $model->description;
- if ($withItems && $model->relationLoaded('consumeItems')) {
- foreach ($model->consumeItems as $item) {
- $dto->items[] = ConsumeItemDto::fromModel($item);
- }
- }
- return $dto;
- }
- }
|