| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Module\Game\Logics\RewardProcessors;
- use App\Module\Game\Dtos\RewardItemDto;
- use Exception;
- use Illuminate\Support\Facades\Log;
- /**
- * 账户种类奖励处理器
- *
- * 处理账户种类(FUND_CONFIG)类型的奖励发放
- */
- class FundConfigRewardProcessor
- {
- /**
- * 处理账户种类奖励(FUND_CONFIG)
- *
- * @param int $userId 用户ID
- * @param RewardItemDto $item 奖励项
- * @param string $sourceType 来源类型
- * @param int $sourceId 来源ID
- * @return void
- * @throws Exception
- */
- public static function process(int $userId, RewardItemDto $item, string $sourceType, int $sourceId): void
- {
- try {
- // 使用Fund模块的User类来处理资金变更
- // target_id 是 fund_config 表的 id(账户种类ID)
- $result = \App\Module\Fund\Logic\User::handle(
- $userId,
- $item->targetId, // fund_config_id
- $item->quantity, // 金额
- \App\Module\Fund\Enums\LOG_TYPE::TRADE, // 日志类型为贸易
- $sourceId, // 关联ID,使用来源ID
- "奖励发放:账户种类奖励 - {$sourceType}#{$sourceId}"
- );
- if (is_string($result)) {
- throw new Exception("账户种类奖励发放失败: " . $result);
- }
- Log::info("账户种类奖励发放成功", [
- 'userId' => $userId,
- 'fundConfigId' => $item->targetId,
- 'amount' => $item->quantity,
- 'sourceType' => $sourceType,
- 'sourceId' => $sourceId
- ]);
- } catch (Exception $e) {
- Log::error("账户种类奖励发放失败", [
- 'userId' => $userId,
- 'fundConfigId' => $item->targetId,
- 'amount' => $item->quantity,
- 'sourceType' => $sourceType,
- 'sourceId' => $sourceId,
- 'error' => $e->getMessage()
- ]);
- throw new Exception("账户种类奖励发放失败: " . $e->getMessage());
- }
- }
- }
|