| 12345678910111213141516171819202122232425262728 |
- <?php
- namespace App\Module\Game\Logics\Reward;
- use App\Module\Game\Dtos\RewardItemDto;
- class Item
- {
- /**
- * 处理奖励项数量(支持随机数量)
- */
- public static function processQuantity(RewardItemDto $item): RewardItemDto
- {
- $processedItem = clone $item;
- // 检查是否有数量范围设置
- if ($item->minQuantity !== null && $item->maxQuantity !== null) {
- $minQty = max(1, $item->minQuantity);
- $maxQty = max($minQty, $item->maxQuantity);
- $processedItem->quantity = mt_rand($minQty, $maxQty);
- } else {
- $processedItem->quantity = max(1, $item->quantity);
- }
- return $processedItem;
- }
- }
|