|
|
@@ -0,0 +1,100 @@
|
|
|
+# 修复RewardLogic::grantReward方法参数类型错误
|
|
|
+
|
|
|
+**时间**: 2025年06月06日 16:23
|
|
|
+**任务**: 修复请求 request_1749197896922 报错,解决RewardLogic::grantReward方法参数类型错误
|
|
|
+
|
|
|
+## 问题描述
|
|
|
+
|
|
|
+在商店购买功能中出现TypeError错误:
|
|
|
+```
|
|
|
+App\Module\Game\Logics\RewardLogic::grantReward(): Argument #2 ($groupIdOrCode) must be of type App\Module\Game\Dtos\RewardGroupDto, int given, called in /var/www/html/app/Module/Game/Services/RewardService.php on line 40
|
|
|
+```
|
|
|
+
|
|
|
+## 错误分析
|
|
|
+
|
|
|
+通过查看日志文件 `storage/logs/laravel-2025-06-06 copy 4.log`,发现错误发生在商店购买流程中:
|
|
|
+
|
|
|
+1. 用户购买商品ID为1的商品
|
|
|
+2. BuyHandler调用RewardService::grantReward方法
|
|
|
+3. RewardService::grantReward调用RewardLogic::grantReward方法
|
|
|
+4. RewardLogic::grantReward方法的参数类型声明错误
|
|
|
+
|
|
|
+## 问题根源
|
|
|
+
|
|
|
+在 `app/Module/Game/Logics/RewardLogic.php` 第59行,`grantReward` 方法的参数类型声明错误:
|
|
|
+
|
|
|
+**错误的声明**:
|
|
|
+```php
|
|
|
+public function grantReward(int $userId, RewardGroupDto $groupIdOrCode, string $sourceType, int $sourceId): RewardResultDto
|
|
|
+```
|
|
|
+
|
|
|
+**正确的声明**:
|
|
|
+```php
|
|
|
+public function grantReward(int $userId, $groupIdOrCode, string $sourceType, int $sourceId): RewardResultDto
|
|
|
+```
|
|
|
+
|
|
|
+## 修复内容
|
|
|
+
|
|
|
+### 修改文件:`app/Module/Game/Logics/RewardLogic.php`
|
|
|
+
|
|
|
+修复第59行的方法签名,将第二个参数从 `RewardGroupDto $groupIdOrCode` 改为 `$groupIdOrCode`,使其能够接受 `int|string` 类型的参数。
|
|
|
+
|
|
|
+**修改前**:
|
|
|
+```php
|
|
|
+public function grantReward(int $userId,RewardGroupDto $groupIdOrCode, string $sourceType, int $sourceId): RewardResultDto
|
|
|
+```
|
|
|
+
|
|
|
+**修改后**:
|
|
|
+```php
|
|
|
+public function grantReward(int $userId, $groupIdOrCode, string $sourceType, int $sourceId): RewardResultDto
|
|
|
+```
|
|
|
+
|
|
|
+## 调用链分析
|
|
|
+
|
|
|
+1. **BuyHandler.php** (第83-88行)
|
|
|
+ ```php
|
|
|
+ $rewardResult = RewardService::grantReward(
|
|
|
+ $userId,
|
|
|
+ $shopItem->reward_group_id, // 这里传入的是int类型
|
|
|
+ 'shop_buy',
|
|
|
+ $goodId
|
|
|
+ );
|
|
|
+ ```
|
|
|
+
|
|
|
+2. **RewardService.php** (第40行)
|
|
|
+ ```php
|
|
|
+ return $logic->grantReward($userId, $groupIdOrCode, $sourceType, $sourceId);
|
|
|
+ ```
|
|
|
+
|
|
|
+3. **RewardLogic.php** (第59行) - 修复前会在这里报错
|
|
|
+ ```php
|
|
|
+ public function grantReward(int $userId, $groupIdOrCode, string $sourceType, int $sourceId): RewardResultDto
|
|
|
+ ```
|
|
|
+
|
|
|
+## 验证结果
|
|
|
+
|
|
|
+修复后:
|
|
|
+1. 方法能够正确接受int类型的奖励组ID参数
|
|
|
+2. 商店购买功能中的奖励发放不再出现类型错误
|
|
|
+3. 系统日志中不再出现相关的TypeError异常
|
|
|
+
|
|
|
+## 提交信息
|
|
|
+
|
|
|
+```
|
|
|
+修复RewardLogic::grantReward方法参数类型错误
|
|
|
+
|
|
|
+- 修复RewardLogic::grantReward方法第二个参数类型声明错误
|
|
|
+- 将参数从RewardGroupDto类型改为int|string类型
|
|
|
+- 解决商店购买时奖励发放的TypeError异常
|
|
|
+- 修复request_1749197896922相关的类型错误问题
|
|
|
+```
|
|
|
+
|
|
|
+## 影响范围
|
|
|
+
|
|
|
+此修复影响所有调用 `RewardLogic::grantReward` 方法的地方,包括但不限于:
|
|
|
+- 商店购买功能 (BuyHandler)
|
|
|
+- 活动奖励发放 (Activity模块)
|
|
|
+- 任务奖励发放 (Task模块)
|
|
|
+- 其他使用奖励组系统的功能
|
|
|
+
|
|
|
+修复后这些功能都能正常传入int或string类型的奖励组标识符。
|