Item.php 753 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Module\Game\Logics\Reward;
  3. use App\Module\Game\Dtos\RewardItemDto;
  4. class Item
  5. {
  6. /**
  7. * 处理奖励项数量(支持随机数量)
  8. */
  9. public static function processQuantity(RewardItemDto $item): RewardItemDto
  10. {
  11. $processedItem = clone $item;
  12. // 检查是否有数量范围设置
  13. if ($item->minQuantity !== null && $item->maxQuantity !== null) {
  14. $minQty = max(1, $item->minQuantity);
  15. $maxQty = max($minQty, $item->maxQuantity);
  16. $processedItem->quantity = mt_rand($minQty, $maxQty);
  17. } else {
  18. $processedItem->quantity = max(1, $item->quantity);
  19. }
  20. return $processedItem;
  21. }
  22. }