时间: 2025年06月11日 19:38:40 CST
任务: 查看日志,修复种植后不增长种植积分的问题;修复后使用 php artisan debug:reproduce-error 68982255命令进行复现
状态: ✅ 已完成
通过查看日志文件 storage/logs/laravel-2025-06-11.log,发现种植操作成功但没有种植积分增长的相关日志。
通过复现错误请求,发现了两个关键问题:
PointServiceProvider 没有在 config/app.php 中注册PlantingPointsListener 没有被注册PlantingPointsListener 中传递给 PointService 构造函数的参数类型不正确POINT_TYPE::PLANTING_POINTS 枚举,但构造函数期望 int 类型Argument #2 ($pointId) must be of type int, App\Module\Point\Enums\POINT_TYPE given在 config/app.php 中添加Point模块的服务提供者:
// Farm 模块
\App\Module\Farm\Providers\FarmServiceProvider::class,
// Point 模块
\App\Module\Point\Providers\PointServiceProvider::class,
// Shop 模块
\App\Module\Shop\Providers\ShopServiceProvider::class,
在 app/Module/Point/Listeners/PlantingPointsListener.php 中修复参数类型:
// 修复前
$pointService = new PointService($userId, POINT_TYPE::PLANTING_POINTS);
// 修复后
$pointService = new PointService($userId, POINT_TYPE::PLANTING_POINTS->valueInt());
使用命令 php artisan debug:reproduce-error 68982268 进行测试:
crop_planted_331crop_planted_332SELECT * FROM kku_point WHERE user_id = 10002 AND point_id = 1;
结果:用户积分余额为2,正确记录了两次种植操作。
SELECT * FROM kku_point_logs WHERE user_id = 10002 AND point_id = 1 ORDER BY id DESC LIMIT 2;
结果:
在 storage/logs/laravel-2025-06-11.log 中可以看到:
[2025-06-11T19:43:03.312004+08:00] laravel.INFO: 种植点数增加成功
{"user_id":10002,"crop_id":331,"land_id":59,"amount":1,"operate_id":"crop_planted_331","balance_after":1}
[2025-06-11T19:43:58.695321+08:00] laravel.INFO: 种植点数增加成功
{"user_id":10002,"crop_id":332,"land_id":59,"amount":1,"operate_id":"crop_planted_332","balance_after":2}
CropPlantedEvent 事件Farm模块种植操作 → CropPlantedEvent → PlantingPointsListener → Point模块增加积分
$pointService = new PointService($userId, POINT_TYPE::PLANTING_POINTS->valueInt());
$result = $pointService->increase($amount, LOG_TYPE::PLANTING_REWARD, $operateId, $remark);
提交信息: 修复种植后不增长种植积分的问题
修改文件:
config/app.php: 注册Point模块服务提供者app/Module/Point/Listeners/PlantingPointsListener.php: 修复参数类型错误Git操作:
git add config/app.php app/Module/Point/Listeners/PlantingPointsListener.php
git commit -m "修复种植后不增长种植积分的问题"
git push
成功修复了种植后不增长种植积分的问题,主要解决了:
现在每次种植操作都会自动增加1点种植积分,并生成详细的日志记录,功能完全正常。