ActivityConditionDto.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Module\Activity\Dtos;
  3. use App\Module\Activity\Models\ActivityCondition;
  4. use UCore\Dto\BaseDto;
  5. /**
  6. * 活动条件数据传输对象
  7. */
  8. class ActivityConditionDto extends BaseDto
  9. {
  10. /**
  11. * 条件ID
  12. *
  13. * @var int
  14. */
  15. public int $id;
  16. /**
  17. * 活动ID
  18. *
  19. * @var int
  20. */
  21. public int $activityId;
  22. /**
  23. * 条件类型
  24. *
  25. * @var int
  26. */
  27. public int $conditionType;
  28. /**
  29. * 条件类型名称
  30. *
  31. * @var string
  32. */
  33. public string $conditionTypeName;
  34. /**
  35. * 条件参数
  36. *
  37. * @var array
  38. */
  39. public array $conditionParams = [];
  40. /**
  41. * 是否为参与条件
  42. *
  43. * @var bool
  44. */
  45. public bool $isParticipationCondition;
  46. /**
  47. * 是否为完成条件
  48. *
  49. * @var bool
  50. */
  51. public bool $isCompletionCondition;
  52. /**
  53. * 显示顺序
  54. *
  55. * @var int
  56. */
  57. public int $displayOrder;
  58. /**
  59. * 从模型创建DTO
  60. *
  61. * @param ActivityCondition $model 活动条件模型
  62. * @return self
  63. */
  64. public static function fromModel(ActivityCondition $model): self
  65. {
  66. $dto = new self();
  67. $dto->id = $model->id;
  68. $dto->activityId = $model->activity_id;
  69. $dto->conditionType = $model->condition_type;
  70. $dto->conditionTypeName = $model->getConditionTypeName();
  71. $dto->conditionParams = $model->condition_params ?? [];
  72. $dto->isParticipationCondition = $model->isParticipationCondition();
  73. $dto->isCompletionCondition = $model->isCompletionCondition();
  74. $dto->displayOrder = $model->display_order;
  75. return $dto;
  76. }
  77. /**
  78. * 转换为模型数据数组
  79. *
  80. * @return array
  81. */
  82. public function toModelArray(): array
  83. {
  84. return [
  85. 'id' => $this->id ?? null,
  86. 'activity_id' => $this->activityId,
  87. 'condition_type' => $this->conditionType,
  88. 'condition_params' => $this->conditionParams,
  89. 'is_participation_condition' => $this->isParticipationCondition,
  90. 'is_completion_condition' => $this->isCompletionCondition,
  91. 'display_order' => $this->displayOrder,
  92. ];
  93. }
  94. }