RewardItemDto.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace App\Module\Game\Dtos;
  3. /**
  4. * 奖励项DTO
  5. */
  6. class RewardItemDto
  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 $rewardType;
  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 float
  54. */
  55. public float $weight;
  56. /**
  57. * 获得概率(百分比,0-100,NULL表示使用权重机制)
  58. *
  59. * @var float|null
  60. */
  61. public ?float $probability;
  62. /**
  63. * 最小数量(NULL表示使用quantity字段)
  64. *
  65. * @var int|null
  66. */
  67. public ?int $minQuantity;
  68. /**
  69. * 最大数量(NULL表示使用quantity字段)
  70. *
  71. * @var int|null
  72. */
  73. public ?int $maxQuantity;
  74. /**
  75. * 是否必中
  76. *
  77. * @var bool
  78. */
  79. public bool $isGuaranteed;
  80. /**
  81. * 额外数据
  82. *
  83. * @var array|null
  84. */
  85. public ?array $extraData;
  86. /**
  87. * 从模型创建DTO
  88. *
  89. * @param \App\Module\Game\Models\GameRewardItem $model
  90. * @return self
  91. */
  92. public static function fromModel($model): self
  93. {
  94. $dto = new self();
  95. $dto->id = $model->id;
  96. $dto->groupId = $model->group_id;
  97. $dto->rewardType = $model->reward_type;
  98. $dto->targetId = $model->target_id;
  99. $dto->param1 = $model->param1;
  100. $dto->param2 = $model->param2;
  101. $dto->quantity = $model->quantity;
  102. $dto->weight = $model->weight;
  103. $dto->probability = $model->probability;
  104. $dto->minQuantity = $model->min_quantity;
  105. $dto->maxQuantity = $model->max_quantity;
  106. $dto->isGuaranteed = (bool)$model->is_guaranteed;
  107. $dto->extraData = $model->extra_data;
  108. return $dto;
  109. }
  110. }