ConsumeItemDto.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Module\Game\Dtos;
  3. /**
  4. * 消耗项DTO
  5. */
  6. class ConsumeItemDto
  7. {
  8. /**
  9. * 消耗项ID
  10. *
  11. * @var int
  12. */
  13. public int $id;
  14. /**
  15. * 消耗组ID
  16. *
  17. * @var int
  18. */
  19. public int $groupId;
  20. /**
  21. * 消耗类型
  22. *
  23. * @var int
  24. */
  25. public int $consumeType;
  26. /**
  27. * 目标ID
  28. *
  29. * @var int
  30. */
  31. public int $targetId;
  32. /**
  33. * 参数1
  34. *
  35. * @var int
  36. */
  37. public int $param1;
  38. /**
  39. * 参数2
  40. *
  41. * @var int
  42. */
  43. public int $param2;
  44. /**
  45. * 数量
  46. *
  47. * @var int
  48. */
  49. public int $quantity;
  50. /**
  51. * 额外数据
  52. *
  53. * @var array|null
  54. */
  55. public ?array $extraData;
  56. /**
  57. * 从模型创建DTO
  58. *
  59. * @param \App\Module\Game\Models\GameConsumeItem $model
  60. * @return self
  61. */
  62. public static function fromModel($model): self
  63. {
  64. $dto = new self();
  65. $dto->id = $model->id;
  66. $dto->groupId = $model->group_id;
  67. $dto->consumeType = $model->consume_type;
  68. $dto->targetId = $model->target_id;
  69. $dto->param1 = $model->param1;
  70. $dto->param2 = $model->param2;
  71. $dto->quantity = $model->quantity;
  72. $dto->extraData = $model->extra_data;
  73. return $dto;
  74. }
  75. }