| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Module\Game\Dtos;
- /**
- * 奖励组DTO
- */
- class RewardGroupDto
- {
- /**
- * 奖励组ID
- *
- * @var int
- */
- public int $id;
- /**
- * 奖励组名称
- *
- * @var string
- */
- public string $name;
- /**
- * 奖励组编码
- *
- * @var string
- */
- public string $code;
- /**
- * 奖励组描述
- *
- * @var string|null
- */
- public ?string $description;
- /**
- * 是否随机发放
- *
- * @var bool
- */
- public bool $isRandom;
- /**
- * 随机发放时的奖励数量
- *
- * @var int
- */
- public int $randomCount;
- /**
- * 奖励模式(1:权重选择模式, 2:独立概率模式)
- *
- * @var int
- */
- public int $rewardMode;
- /**
- * 奖励项列表
- *
- * @var RewardItemDto[]
- */
- public array $items = [];
- /**
- * 从模型创建DTO
- *
- * @param \App\Module\Game\Models\GameRewardGroup $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;
- $dto->isRandom = (bool)$model->is_random;
- $dto->randomCount = $model->random_count;
- $dto->rewardMode = $model->reward_mode ?? 1; // 默认为权重选择模式
- if ($withItems && $model->relationLoaded('rewardItems')) {
- foreach ($model->rewardItems as $item) {
- $dto->items[] = RewardItemDto::fromModel($item);
- }
- }
- return $dto;
- }
- }
|