| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace App\Module\Farm\Dtos;
- use App\Module\Farm\Enums\BUFF_TYPE;
- use App\Module\Farm\Models\FarmGodBuff;
- /**
- * 神灵加持数据传输对象
- */
- class GodBuffDto
- {
- /**
- * 加持ID
- *
- * @var int
- */
- public $id;
- /**
- * 用户ID
- *
- * @var int
- */
- public $userId;
- /**
- * 加持类型
- *
- * @var int
- */
- public $buffType;
- /**
- * 加持类型名称
- *
- * @var string
- */
- public $buffTypeName;
- /**
- * 加持效果描述
- *
- * @var string
- */
- public $description;
- /**
- * 过期时间
- *
- * @var string
- */
- public $expireTime;
- /**
- * 创建时间
- *
- * @var string
- */
- public $createdAt;
- /**
- * 从模型创建DTO
- *
- * @param FarmGodBuff $buff
- * @return self
- */
- public static function fromModel(FarmGodBuff $buff): self
- {
- $dto = new self();
- $dto->id = $buff->id;
- $dto->userId = $buff->user_id;
- $dto->buffType = $buff->buff_type;
- $dto->buffTypeName = BUFF_TYPE::getName($buff->buff_type);
- $dto->description = BUFF_TYPE::getDescription($buff->buff_type);
- $dto->expireTime = $buff->expire_time->toDateTimeString();
- $dto->createdAt = $buff->created_at->toDateTimeString();
-
- return $dto;
- }
- /**
- * 转换为数组
- *
- * @return array
- */
- public function toArray(): array
- {
- return [
- 'id' => $this->id,
- 'user_id' => $this->userId,
- 'buff_type' => $this->buffType,
- 'buff_type_name' => $this->buffTypeName,
- 'description' => $this->description,
- 'expire_time' => $this->expireTime,
- 'created_at' => $this->createdAt,
- ];
- }
- }
|