taskConditionService = $taskConditionService; } /** * 执行命令 * * @return int */ public function handle(): int { $userId = (int)$this->argument('user_id'); $expPerTime = (int)$this->option('exp'); $times = (int)$this->option('times'); $this->info("开始测试玫瑰之心任务"); $this->info("用户ID: {$userId}"); $this->info("每次经验: {$expPerTime}"); $this->info("测试次数: {$times}"); $this->line(''); try { // 检查用户是否有宠物 $pet = PetUser::where('user_id', $userId)->first(); if (!$pet) { $this->error("用户 {$userId} 没有宠物,无法测试"); return 1; } $this->info("找到宠物: ID={$pet->id}, 名称={$pet->name}, 当前经验={$pet->experience}"); $this->line(''); // 检查玫瑰之心任务 $roseHeartTask = Task::where('name', '玫瑰之心')->first(); if (!$roseHeartTask) { $this->error("玫瑰之心任务不存在"); return 1; } $this->info("找到玫瑰之心任务: ID={$roseHeartTask->id}"); $this->line(''); // 开始测试循环 for ($i = 1; $i <= $times; $i++) { $this->info("=== 第 {$i} 次测试 ==="); // 模拟宠物获得经验 $this->simulatePetExpGain($userId, $pet->id, $expPerTime, $i); // 检查任务状态 $this->checkTaskStatus($userId, $roseHeartTask->id); $this->line(''); // 暂停一下,便于观察 sleep(1); } $this->info("测试完成!"); return 0; } catch (\Exception $e) { $this->error("测试失败: " . $e->getMessage()); return 1; } } /** * 模拟宠物获得经验 * * @param int $userId 用户ID * @param int $petId 宠物ID * @param int $expAmount 经验值 * @param int $round 轮次 * @return void */ protected function simulatePetExpGain(int $userId, int $petId, int $expAmount, int $round): void { $this->info("模拟宠物获得 {$expAmount} 点经验..."); // 触发宠物经验增加事件 event(new PetExpGainedEvent( $userId, $petId, $expAmount, 'test_command', $round )); $this->info("✓ 宠物经验增加事件已触发"); } /** * 检查任务状态 * * @param int $userId 用户ID * @param int $taskId 任务ID * @return void */ protected function checkTaskStatus(int $userId, int $taskId): void { // 检查用户任务状态 $userTask = TaskUserTask::where('user_id', $userId) ->where('task_id', $taskId) ->first(); if (!$userTask) { $this->warn("⚠ 用户还没有接取玫瑰之心任务"); return; } $this->info("任务状态: {$userTask->status}"); $this->info("任务进度: {$userTask->progress}%"); if ($userTask->completed_at) { $this->info("✓ 任务完成时间: {$userTask->completed_at}"); } if ($userTask->rewarded_at) { $this->info("✓ 奖励领取时间: {$userTask->rewarded_at}"); } // 检查任务进度详情 $this->checkTaskProgress($userId, $taskId); } /** * 检查任务进度详情 * * @param int $userId 用户ID * @param int $taskId 任务ID * @return void */ protected function checkTaskProgress(int $userId, int $taskId): void { try { $progressData = DB::table('task_user_progress as tup') ->join('task_achievement_conditions as tac', 'tup.achievement_condition_id', '=', 'tac.id') ->join('task_conditions as tc', 'tac.condition_id', '=', 'tc.id') ->where('tup.user_id', $userId) ->where('tup.task_id', $taskId) ->select([ 'tc.name as condition_name', 'tup.current_value', 'tup.target_value', 'tac.operator' ]) ->first(); if ($progressData) { $this->info("条件: {$progressData->condition_name}"); $this->info("进度: {$progressData->current_value} / {$progressData->target_value} ({$progressData->operator})"); $percentage = round(($progressData->current_value / $progressData->target_value) * 100, 2); $this->info("完成度: {$percentage}%"); } else { $this->warn("⚠ 没有找到任务进度数据"); } } catch (\Exception $e) { $this->error("检查任务进度失败: " . $e->getMessage()); } } }