targetId; // 神像类型(1=丰收之神,2=雨露之神,3=屠草之神,4=拭虫之神) $durationHours = $item->param2 > 0 ? $item->param2 : 24; // 持续时间(小时),默认24小时 $activationCount = $item->quantity > 0 ? $item->quantity : 1; // 激活次数,默认1次 // 验证神像类型是否有效 if (!in_array($shrineType, [1, 2, 3, 4])) { throw new Exception("无效的神像类型: {$shrineType}"); } // 验证用户是否存在 $farmUser = \App\Module\Farm\Models\FarmUser::where('user_id', $userId)->first(); if (!$farmUser) { throw new Exception("用户农场数据不存在,用户ID: {$userId}"); } // 循环激活神像(支持多次激活) for ($i = 0; $i < $activationCount; $i++) { // 使用BuffService激活神像 $buff = \App\Module\Farm\Services\BuffService::activateBuff($userId, $shrineType, $durationHours); if (!$buff) { throw new Exception("神像激活失败,神像类型: {$shrineType},用户ID: {$userId}"); } Log::info("神像奖励激活成功", [ 'userId' => $userId, 'shrineType' => $shrineType, 'shrineName' => \App\Module\Farm\Enums\BUFF_TYPE::getName($shrineType), 'durationHours' => $durationHours, 'activationIndex' => $i + 1, 'totalActivations' => $activationCount, 'expireTime' => $buff->expire_time ? $buff->expire_time->toDateTimeString() : null, 'sourceType' => $sourceType, 'sourceId' => $sourceId ]); } // 收集神像奖励到Response.Reward中 RewardCollectorService::addGodReward( $userId, $shrineType, $durationHours * 3600, // 转换为秒 $activationCount ); Log::info("神像奖励发放完成", [ 'userId' => $userId, 'shrineType' => $shrineType, 'shrineName' => \App\Module\Farm\Enums\BUFF_TYPE::getName($shrineType), 'durationHours' => $durationHours, 'totalActivations' => $activationCount, 'sourceType' => $sourceType, 'sourceId' => $sourceId ]); } catch (Exception $e) { Log::error("神像奖励发放失败", [ 'userId' => $userId, 'shrineType' => $item->targetId, 'durationHours' => $item->param2, 'quantity' => $item->quantity, 'sourceType' => $sourceType, 'sourceId' => $sourceId, 'error' => $e->getMessage() ]); throw new Exception("神像奖励发放失败: " . $e->getMessage()); } } }