| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace App\Module\Task\Dtos;
- use App\Module\Task\Models\TaskReward;
- use UCore\Dto\BaseDto;
- /**
- * 任务奖励数据传输对象
- *
- * 用于在不同层之间传递任务奖励数据,特别是在服务层和控制器层之间。
- */
- class TaskRewardDto extends BaseDto
- {
- /**
- * 奖励ID
- *
- * @var int
- */
- public int $id;
-
- /**
- * 任务ID
- *
- * @var int
- */
- public int $taskId;
-
- /**
- * 奖励类型
- *
- * @var string
- */
- public string $rewardType;
-
- /**
- * 奖励参数1
- *
- * @var string
- */
- public string $rewardParam1;
-
- /**
- * 奖励参数2
- *
- * @var string
- */
- public string $rewardParam2;
-
- /**
- * 奖励数量
- *
- * @var int
- */
- public int $quantity;
-
- /**
- * 额外数据
- *
- * @var array
- */
- public array $extraData = [];
-
- /**
- * 排序权重
- *
- * @var int
- */
- public int $sortOrder = 0;
-
- /**
- * 从TaskReward模型创建DTO
- *
- * @param TaskReward $reward 任务奖励模型
- * @return static
- */
- public static function fromModel(TaskReward $reward): self
- {
- $dto = new self();
-
- $dto->id = $reward->id;
- $dto->taskId = $reward->task_id;
- $dto->rewardType = $reward->reward_type;
- $dto->rewardParam1 = $reward->reward_param1;
- $dto->rewardParam2 = $reward->reward_param2;
- $dto->quantity = $reward->quantity;
- $dto->extraData = $reward->extra_data ?? [];
- $dto->sortOrder = $reward->sort_order ?? 0;
-
- return $dto;
- }
-
- /**
- * 转换为模型数据数组
- *
- * @return array
- */
- public function toModelArray(): array
- {
- return [
- 'id' => $this->id ?? null,
- 'task_id' => $this->taskId,
- 'reward_type' => $this->rewardType,
- 'reward_param1' => $this->rewardParam1,
- 'reward_param2' => $this->rewardParam2,
- 'quantity' => $this->quantity,
- 'extra_data' => $this->extraData,
- 'sort_order' => $this->sortOrder,
- ];
- }
- }
|