| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Module\Game\Services;
- use App\Module\Game\Dtos\RewardGroupDto;
- use App\Module\Game\Dtos\RewardResultDto;
- use App\Module\Game\Logics\RewardLogic;
- /**
- * 奖励服务类
- *
- * 提供奖励相关的服务,对外接口
- */
- class RewardService
- {
- /**
- * 获取奖励组信息
- *
- * @param int|string $groupIdOrCode 奖励组ID或编码
- * @return RewardGroupDto|null 奖励组DTO,不存在时返回null
- */
- public static function getRewardGroup($groupIdOrCode): ?RewardGroupDto
- {
- $logic = new RewardLogic();
- return $logic->getRewardGroup($groupIdOrCode);
- }
- /**
- * 发放奖励
- *
- * @param int $userId 用户ID
- * @param int|string $groupIdOrCode 奖励组ID或编码
- * @param string $sourceType 来源类型(任务、活动、签到等)
- * @param int $sourceId 来源ID
- * @return RewardResultDto 奖励结果
- */
- public static function grantReward(int $userId, $groupIdOrCode, string $sourceType, int $sourceId): RewardResultDto
- {
- $logic = new RewardLogic();
- return $logic->grantReward($userId, $groupIdOrCode, $sourceType, $sourceId);
- }
- /**
- * 批量发放奖励
- *
- * @param array $userIds 用户ID数组
- * @param int|string $groupIdOrCode 奖励组ID或编码
- * @param string $sourceType 来源类型
- * @param int $sourceId 来源ID
- * @return array 奖励结果数组,键为用户ID,值为RewardResultDto
- */
- public static function batchGrantReward(array $userIds, $groupIdOrCode, string $sourceType, int $sourceId): array
- {
- $results = [];
- $logic = new RewardLogic();
- foreach ($userIds as $userId) {
- $results[$userId] = $logic->grantReward($userId, $groupIdOrCode, $sourceType, $sourceId);
- }
- return $results;
- }
- /**
- * 检查奖励组是否存在
- *
- * @param int|string $groupIdOrCode 奖励组ID或编码
- * @return bool 是否存在
- */
- public static function rewardGroupExists($groupIdOrCode): bool
- {
- return self::getRewardGroup($groupIdOrCode) !== null;
- }
- }
|