option('user-id'); $this->info("开始测试奖励系统功能,用户ID: {$userId}"); try { // 创建测试奖励组 $this->createTestRewardGroup(); // 测试物品奖励发放 $this->testItemReward($userId); // 测试账户种类奖励发放 $this->testFundConfigReward($userId); // 测试币种奖励发放 $this->testCurrencyReward($userId); // 测试宠物经验奖励发放 $this->testPetExpReward($userId); // 测试宠物体力奖励发放 $this->testPetEnergyReward($userId); // 测试其他类型奖励发放 $this->testOtherReward($userId); $this->info('奖励系统功能测试完成!'); return 0; } catch (Exception $e) { $this->error('测试失败: ' . $e->getMessage()); return 1; } } /** * 创建测试奖励组 */ protected function createTestRewardGroup(): void { $this->info('创建测试奖励组...'); // 检查是否已存在测试奖励组 $existingGroup = GameRewardGroup::where('code', 'TEST_REWARD_GROUP')->first(); if ($existingGroup) { $this->line('测试奖励组已存在,跳过创建'); return; } DB::transaction(function () { // 创建奖励组 $group = GameRewardGroup::create([ 'name' => '测试奖励组', 'code' => 'TEST_REWARD_GROUP', 'description' => '用于测试奖励系统的奖励组', 'is_random' => false, 'random_count' => 1, 'is_active' => true ]); // 创建物品奖励项 GameRewardItem::create([ 'group_id' => $group->id, 'reward_type' => REWARD_TYPE::ITEM->value, 'target_id' => 1001, // 假设物品ID为1001 'param1' => 0, 'param2' => 0, 'quantity' => 10, 'weight' => 1.0, 'is_guaranteed' => true, 'extra_data' => [] ]); // 创建账户种类奖励项 GameRewardItem::create([ 'group_id' => $group->id, 'reward_type' => REWARD_TYPE::FUND_CONFIG->value, 'target_id' => 1, // 假设账户种类ID为1 'param1' => 0, 'param2' => 0, 'quantity' => 100, 'weight' => 1.0, 'is_guaranteed' => true, 'extra_data' => [] ]); $this->line('✓ 测试奖励组创建完成'); }); } /** * 测试物品奖励发放 */ protected function testItemReward(int $userId): void { $this->info('测试物品奖励发放...'); try { DB::transaction(function () use ($userId) { $result = RewardService::grantReward( $userId, 'TEST_REWARD_GROUP', 'test_command', // 来源类型:测试命令 time() // 来源ID:当前时间戳作为唯一标识 ); if ($result->success) { $this->line('✓ 奖励发放成功'); $this->line(' 发放的奖励项数量: ' . count($result->items)); $this->line(' 来源类型: ' . $result->sourceType); $this->line(' 来源ID: ' . $result->sourceId); foreach ($result->items as $item) { $this->line(" 奖励类型: {$item->rewardType}, 目标ID: {$item->targetId}, 数量: {$item->quantity}"); } } else { $this->error('✗ 奖励发放失败: ' . $result->errorMessage); } }); } catch (Exception $e) { $this->error('✗ 奖励发放异常: ' . $e->getMessage()); } } /** * 测试账户种类奖励发放 */ protected function testFundConfigReward(int $userId): void { $this->info('测试账户种类奖励发放...'); $this->line('注意:此测试需要确保用户账户已创建且fund_config表中有对应记录'); // 实际测试代码可以在这里实现 } /** * 测试币种奖励发放 */ protected function testCurrencyReward(int $userId): void { $this->info('测试币种奖励发放...'); $this->line('注意:此测试需要确保fund_currency和fund_config表中有对应记录'); // 实际测试代码可以在这里实现 } /** * 测试宠物经验奖励发放 */ protected function testPetExpReward(int $userId): void { $this->info('测试宠物经验奖励发放...'); $this->line('注意:此测试需要确保用户有宠物'); // 实际测试代码可以在这里实现 } /** * 测试宠物体力奖励发放 */ protected function testPetEnergyReward(int $userId): void { $this->info('测试宠物体力奖励发放...'); $this->line('注意:此测试需要确保用户有宠物'); // 实际测试代码可以在这里实现 } /** * 测试其他类型奖励发放 */ protected function testOtherReward(int $userId): void { $this->info('测试其他类型奖励发放...'); $this->line('其他类型奖励目前只记录日志,不执行具体操作'); // 实际测试代码可以在这里实现 } }