| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Module\Game\Dtos;
- /**
- * 神像变更临时数据传输对象
- *
- * 用于存储和传输神像变更的临时数据
- */
- class GodChangeTempDto
- {
- /**
- * 神像类型
- *
- * @var int
- */
- public int $godType;
- /**
- * 神像状态(是否激活)
- *
- * @var bool
- */
- public bool $status;
- /**
- * 过期时间戳
- *
- * @var int|null
- */
- public ?int $expireTime;
- /**
- * 持续时间(秒)
- *
- * @var int
- */
- public int $duration;
- /**
- * 更新时间戳
- *
- * @var int
- */
- public int $updatedAt;
- /**
- * 构造函数
- *
- * @param int $godType 神像类型
- * @param bool $status 神像状态
- * @param int|null $expireTime 过期时间戳
- * @param int $duration 持续时间(秒)
- * @param int $updatedAt 更新时间戳
- */
- public function __construct(
- int $godType,
- bool $status,
- ?int $expireTime,
- int $duration,
- int $updatedAt
- ) {
- $this->godType = $godType;
- $this->status = $status;
- $this->expireTime = $expireTime;
- $this->duration = $duration;
- $this->updatedAt = $updatedAt;
- }
- /**
- * 从数组创建DTO对象
- *
- * @param array $data 数组数据
- * @return self
- */
- public static function fromArray(array $data): self
- {
- return new self(
- $data['god_type'],
- $data['status'],
- $data['expire_time'] ?? null,
- $data['duration'],
- $data['updated_at']
- );
- }
- /**
- * 转换为数组
- *
- * @return array
- */
- public function toArray(): array
- {
- return [
- 'god_type' => $this->godType,
- 'status' => $this->status,
- 'expire_time' => $this->expireTime,
- 'duration' => $this->duration,
- 'updated_at' => $this->updatedAt,
- ];
- }
- }
|