| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace App\Module\Activity\Dtos;
- use App\Module\Activity\Models\ActivityConfig;
- use UCore\Dto\BaseDto;
- /**
- * 活动配置数据传输对象
- */
- class ActivityConfigDto extends BaseDto
- {
- /**
- * 活动ID
- *
- * @var int
- */
- public int $id;
- /**
- * 活动名称
- *
- * @var string
- */
- public string $name;
- /**
- * 活动类型
- *
- * @var int
- */
- public int $type;
- /**
- * 活动类型名称
- *
- * @var string
- */
- public string $typeName;
- /**
- * 活动描述
- *
- * @var string
- */
- public string $description;
- /**
- * 开始时间
- *
- * @var string
- */
- public string $startTime;
- /**
- * 结束时间
- *
- * @var string
- */
- public string $endTime;
- /**
- * 活动状态
- *
- * @var int
- */
- public int $status;
- /**
- * 活动状态名称
- *
- * @var string
- */
- public string $statusName;
- /**
- * 显示顺序
- *
- * @var int
- */
- public int $displayOrder;
- /**
- * 活动图标URL
- *
- * @var string|null
- */
- public ?string $icon;
- /**
- * 活动横幅URL
- *
- * @var string|null
- */
- public ?string $banner;
- /**
- * 奖励组ID
- *
- * @var int|null
- */
- public ?int $rewardGroupId;
- /**
- * 奖励组编码
- *
- * @var string|null
- */
- public ?string $rewardGroupCode;
- /**
- * 活动特定配置参数
- *
- * @var array
- */
- public array $configParams = [];
- /**
- * 活动条件列表
- *
- * @var ActivityConditionDto[]
- */
- public array $conditions = [];
- /**
- * 用户参与状态
- *
- * @var ActivityParticipationDto|null
- */
- public ?ActivityParticipationDto $participation = null;
- /**
- * 从模型创建DTO
- *
- * @param ActivityConfig $model 活动配置模型
- * @param bool $withConditions 是否包含条件
- * @return self
- */
- public static function fromModel(ActivityConfig $model, bool $withConditions = false): self
- {
- $dto = new self();
- $dto->id = $model->id;
- $dto->name = $model->name;
- $dto->type = $model->type;
- $dto->typeName = $model->getTypeName();
- $dto->description = $model->description ?? '';
- $dto->startTime = $model->start_time ? $model->start_time->format('Y-m-d H:i:s') : '';
- $dto->endTime = $model->end_time ? $model->end_time->format('Y-m-d H:i:s') : '';
- $dto->status = $model->status;
- $dto->statusName = $model->getStatusName();
- $dto->displayOrder = $model->display_order;
- $dto->icon = $model->icon;
- $dto->banner = $model->banner;
- $dto->rewardGroupId = $model->reward_group_id;
- $dto->rewardGroupCode = $model->reward_group_code;
- $dto->configParams = $model->config_params ?? [];
- // 加载条件
- if ($withConditions && $model->relationLoaded('conditions')) {
- foreach ($model->conditions as $condition) {
- $dto->conditions[] = ActivityConditionDto::fromModel($condition);
- }
- }
- return $dto;
- }
- /**
- * 转换为模型数据数组
- *
- * @return array
- */
- public function toModelArray(): array
- {
- return [
- 'id' => $this->id ?? null,
- 'name' => $this->name,
- 'type' => $this->type,
- 'description' => $this->description,
- 'start_time' => $this->startTime,
- 'end_time' => $this->endTime,
- 'status' => $this->status,
- 'display_order' => $this->displayOrder,
- 'icon' => $this->icon,
- 'banner' => $this->banner,
- 'reward_group_id' => $this->rewardGroupId,
- 'reward_group_code' => $this->rewardGroupCode,
- 'config_params' => $this->configParams,
- ];
- }
- }
|