| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Module\Game\Services;
- use App\Module\Game\Logics\DeductCollectorLogic;
- /**
- * 扣除数据收集服务
- *
- * 用于收集本次请求中的所有扣除数据,包括物品扣除和代币扣除
- * 通过静态变量实现,确保在单次请求中能够累积所有扣除信息
- */
- class DeductCollectorService
- {
- /**
- * 添加物品扣除
- *
- * @param int $userId 用户ID
- * @param int $itemId 物品ID
- * @param int $instanceId 物品实例ID
- * @param int $quantity 扣除数量
- * @return void
- */
- public static function addItemDeduct(int $userId, int $itemId, int $instanceId, int $quantity): void
- {
- DeductCollectorLogic::addItemDeduct($userId, $itemId, $instanceId, $quantity);
- }
- /**
- * 添加代币扣除
- *
- * @param int $userId 用户ID
- * @param int $coinType 代币类型
- * @param int $quantity 扣除数量
- * @return void
- */
- public static function addCoinDeduct(int $userId, int $coinType, int $quantity): void
- {
- DeductCollectorLogic::addCoinDeduct($userId, $coinType, $quantity);
- }
- /**
- * 获取本次请求的所有扣除数据
- *
- * @param int|null $userId 用户ID,如果为null则返回所有用户的数据
- * @return array 扣除数据数组,包含items和coins
- */
- public static function getDeducts(?int $userId = null): array
- {
- return DeductCollectorLogic::getDeducts($userId);
- }
- /**
- * 清空本次请求的扣除数据
- *
- * @return void
- */
- public static function clearDeducts(): void
- {
- DeductCollectorLogic::clearDeducts();
- }
- /**
- * 检查是否有扣除数据
- *
- * @param int|null $userId 用户ID,如果为null则检查所有用户
- * @return bool
- */
- public static function hasDeducts(?int $userId = null): bool
- {
- return DeductCollectorLogic::hasDeducts($userId);
- }
- /**
- * 获取物品扣除数据
- *
- * @param int|null $userId 用户ID,如果为null则返回所有用户的数据
- * @return array
- */
- public static function getItemDeducts(?int $userId = null): array
- {
- return DeductCollectorLogic::getItemDeducts($userId);
- }
- /**
- * 获取代币扣除数据
- *
- * @param int|null $userId 用户ID,如果为null则返回所有用户的数据
- * @return array
- */
- public static function getCoinDeducts(?int $userId = null): array
- {
- return DeductCollectorLogic::getCoinDeducts($userId);
- }
- }
|