info('开始测试神像奖励收集功能...'); // 测试手动添加神像奖励 $this->testManualGodReward(); // 测试通过奖励组发放神像奖励 $this->testRewardGroupGodReward(); $this->info('神像奖励收集功能测试完成!'); return 0; } /** * 测试手动添加神像奖励 */ protected function testManualGodReward(): void { $this->info('测试手动添加神像奖励...'); // 清空收集器 RewardCollectorService::clearRewards(); // 手动添加神像奖励 RewardCollectorService::addGodReward(2, 86400, 1); // 雨露之神,24小时,1次 // 检查收集器中的数据 if (RewardCollectorService::hasRewards()) { $rewardData = RewardCollectorService::getRewards(); $this->line("收集器中的奖励数据:"); $this->line(" 物品奖励数量: " . count($rewardData['items'])); $this->line(" 代币奖励数量: " . count($rewardData['coins'])); $this->line(" 神像奖励数量: " . count($rewardData['gods'])); if (!empty($rewardData['gods'])) { $this->line("✓ 神像奖励收集成功!"); foreach ($rewardData['gods'] as $god) { $this->line(" 神像类型: {$god['type']}, 时间差值: {$god['diff']}秒, 数量: {$god['quantity']}"); } } else { $this->error("✗ 神像奖励收集失败!"); } } else { $this->error("✗ 收集器中没有任何奖励数据!"); } } /** * 测试通过奖励组发放神像奖励 */ protected function testRewardGroupGodReward(): void { $userId = (int) $this->argument('user_id'); $rewardGroupId = (int) $this->argument('reward_group_id'); $this->info("测试通过奖励组发放神像奖励..."); $this->line("用户ID: {$userId}"); $this->line("奖励组ID: {$rewardGroupId}"); try { // 开启事务 DB::beginTransaction(); // 清空之前的收集器数据 RewardCollectorService::clearRewards(); // 发放奖励 $result = RewardService::grantReward( $userId, $rewardGroupId, 'test_command', 1 ); if (!$result->success) { $this->error("✗ 奖励发放失败: " . $result->errorMessage); DB::rollBack(); return; } $this->line("✓ 奖励发放成功!"); // 检查收集器中的数据 if (RewardCollectorService::hasRewards()) { $rewardData = RewardCollectorService::getRewards(); $this->line("收集器中的奖励数据:"); $this->line(" 物品奖励数量: " . count($rewardData['items'])); $this->line(" 代币奖励数量: " . count($rewardData['coins'])); $this->line(" 神像奖励数量: " . count($rewardData['gods'])); if (!empty($rewardData['gods'])) { $this->line("✓ 神像奖励收集成功!"); foreach ($rewardData['gods'] as $god) { $this->line(" 神像类型: {$god['type']}, 时间差值: {$god['diff']}秒, 数量: {$god['quantity']}"); } } else { $this->warn("⚠ 没有收集到神像奖励数据(可能奖励组中没有神像奖励)"); } } else { $this->warn("⚠ 收集器中没有任何奖励数据!"); } // 提交事务 DB::commit(); } catch (\Exception $e) { DB::rollBack(); $this->error("✗ 测试失败: " . $e->getMessage()); $this->line("错误堆栈: " . $e->getTraceAsString()); } } }