| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Module\Game\Dtos;
- /**
- * 条件组DTO
- */
- class ConditionGroupDto
- {
- /**
- * 条件组ID
- *
- * @var int
- */
- public int $id;
- /**
- * 条件组名称
- *
- * @var string
- */
- public string $name;
- /**
- * 条件组编码
- *
- * @var string
- */
- public string $code;
- /**
- * 条件组描述
- *
- * @var string|null
- */
- public ?string $description;
- /**
- * 逻辑类型(1:全部满足, 2:任一满足)
- *
- * @var int
- */
- public int $logicType;
- /**
- * 条件项列表
- *
- * @var ConditionItemDto[]
- */
- public array $items = [];
- /**
- * 从模型创建DTO
- *
- * @param \App\Module\Game\Models\GameConditionGroup $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->logicType = $model->logic_type;
- if ($withItems && $model->relationLoaded('conditionItems')) {
- foreach ($model->conditionItems as $item) {
- $dto->items[] = ConditionItemDto::fromModel($item);
- }
- }
- return $dto;
- }
- }
|