GodBuffDto.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Module\Farm\Dtos;
  3. use App\Module\Farm\Enums\BUFF_TYPE;
  4. use App\Module\Farm\Models\FarmGodBuff;
  5. /**
  6. * 神灵加持数据传输对象
  7. */
  8. class GodBuffDto
  9. {
  10. /**
  11. * 加持ID
  12. *
  13. * @var int
  14. */
  15. public $id;
  16. /**
  17. * 用户ID
  18. *
  19. * @var int
  20. */
  21. public $userId;
  22. /**
  23. * 加持类型
  24. *
  25. * @var int
  26. */
  27. public $buffType;
  28. /**
  29. * 加持类型名称
  30. *
  31. * @var string
  32. */
  33. public $buffTypeName;
  34. /**
  35. * 加持效果描述
  36. *
  37. * @var string
  38. */
  39. public $description;
  40. /**
  41. * 过期时间
  42. *
  43. * @var string
  44. */
  45. public $expireTime;
  46. /**
  47. * 创建时间
  48. *
  49. * @var string
  50. */
  51. public $createdAt;
  52. /**
  53. * 从模型创建DTO
  54. *
  55. * @param FarmGodBuff $buff
  56. * @return self
  57. */
  58. public static function fromModel(FarmGodBuff $buff): self
  59. {
  60. $dto = new self();
  61. $dto->id = $buff->id;
  62. $dto->userId = $buff->user_id;
  63. $dto->buffType = $buff->buff_type;
  64. $dto->buffTypeName = BUFF_TYPE::getName($buff->buff_type);
  65. $dto->description = BUFF_TYPE::getDescription($buff->buff_type);
  66. $dto->expireTime = $buff->expire_time->toDateTimeString();
  67. $dto->createdAt = $buff->created_at->toDateTimeString();
  68. return $dto;
  69. }
  70. /**
  71. * 转换为数组
  72. *
  73. * @return array
  74. */
  75. public function toArray(): array
  76. {
  77. return [
  78. 'id' => $this->id,
  79. 'user_id' => $this->userId,
  80. 'buff_type' => $this->buffType,
  81. 'buff_type_name' => $this->buffTypeName,
  82. 'description' => $this->description,
  83. 'expire_time' => $this->expireTime,
  84. 'created_at' => $this->createdAt,
  85. ];
  86. }
  87. }