| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Module\Activity\Dtos;
- use App\Module\Activity\Models\ActivityCondition;
- use UCore\Dto\BaseDto;
- /**
- * 活动条件数据传输对象
- */
- class ActivityConditionDto extends BaseDto
- {
- /**
- * 条件ID
- *
- * @var int
- */
- public int $id;
- /**
- * 活动ID
- *
- * @var int
- */
- public int $activityId;
- /**
- * 条件类型
- *
- * @var int
- */
- public int $conditionType;
- /**
- * 条件类型名称
- *
- * @var string
- */
- public string $conditionTypeName;
- /**
- * 条件参数
- *
- * @var array
- */
- public array $conditionParams = [];
- /**
- * 是否为参与条件
- *
- * @var bool
- */
- public bool $isParticipationCondition;
- /**
- * 是否为完成条件
- *
- * @var bool
- */
- public bool $isCompletionCondition;
- /**
- * 显示顺序
- *
- * @var int
- */
- public int $displayOrder;
- /**
- * 从模型创建DTO
- *
- * @param ActivityCondition $model 活动条件模型
- * @return self
- */
- public static function fromModel(ActivityCondition $model): self
- {
- $dto = new self();
- $dto->id = $model->id;
- $dto->activityId = $model->activity_id;
- $dto->conditionType = $model->condition_type;
- $dto->conditionTypeName = $model->getConditionTypeName();
- $dto->conditionParams = $model->condition_params ?? [];
- $dto->isParticipationCondition = $model->isParticipationCondition();
- $dto->isCompletionCondition = $model->isCompletionCondition();
- $dto->displayOrder = $model->display_order;
- return $dto;
- }
- /**
- * 转换为模型数据数组
- *
- * @return array
- */
- public function toModelArray(): array
- {
- return [
- 'id' => $this->id ?? null,
- 'activity_id' => $this->activityId,
- 'condition_type' => $this->conditionType,
- 'condition_params' => $this->conditionParams,
- 'is_participation_condition' => $this->isParticipationCondition,
- 'is_completion_condition' => $this->isCompletionCondition,
- 'display_order' => $this->displayOrder,
- ];
- }
- }
|