GodChangeTempDto.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Module\Game\Dtos;
  3. /**
  4. * 神像变更临时数据传输对象
  5. *
  6. * 用于存储和传输神像变更的临时数据
  7. */
  8. class GodChangeTempDto
  9. {
  10. /**
  11. * 神像类型
  12. *
  13. * @var int
  14. */
  15. public int $godType;
  16. /**
  17. * 神像状态(是否激活)
  18. *
  19. * @var bool
  20. */
  21. public bool $status;
  22. /**
  23. * 过期时间戳
  24. *
  25. * @var int|null
  26. */
  27. public ?int $expireTime;
  28. /**
  29. * 持续时间(秒)
  30. *
  31. * @var int
  32. */
  33. public int $duration;
  34. /**
  35. * 更新时间戳
  36. *
  37. * @var int
  38. */
  39. public int $updatedAt;
  40. /**
  41. * 构造函数
  42. *
  43. * @param int $godType 神像类型
  44. * @param bool $status 神像状态
  45. * @param int|null $expireTime 过期时间戳
  46. * @param int $duration 持续时间(秒)
  47. * @param int $updatedAt 更新时间戳
  48. */
  49. public function __construct(
  50. int $godType,
  51. bool $status,
  52. ?int $expireTime,
  53. int $duration,
  54. int $updatedAt
  55. ) {
  56. $this->godType = $godType;
  57. $this->status = $status;
  58. $this->expireTime = $expireTime;
  59. $this->duration = $duration;
  60. $this->updatedAt = $updatedAt;
  61. }
  62. /**
  63. * 从数组创建DTO对象
  64. *
  65. * @param array $data 数组数据
  66. * @return self
  67. */
  68. public static function fromArray(array $data): self
  69. {
  70. return new self(
  71. $data['god_type'],
  72. $data['status'],
  73. $data['expire_time'] ?? null,
  74. $data['duration'],
  75. $data['updated_at']
  76. );
  77. }
  78. /**
  79. * 转换为数组
  80. *
  81. * @return array
  82. */
  83. public function toArray(): array
  84. {
  85. return [
  86. 'god_type' => $this->godType,
  87. 'status' => $this->status,
  88. 'expire_time' => $this->expireTime,
  89. 'duration' => $this->duration,
  90. 'updated_at' => $this->updatedAt,
  91. ];
  92. }
  93. }