argument('pet_id'); $expAmount = (int) $this->argument('exp_amount'); try { // 检查宠物是否存在 $pet = PetUser::find($petId); if (!$pet) { $this->error("宠物ID {$petId} 不存在"); return 1; } $this->info("开始测试宠物经验增加事件..."); $this->info("宠物ID: {$petId}"); $this->info("用户ID: {$pet->user_id}"); $this->info("当前经验: {$pet->experience}"); $this->info("增加经验: {$expAmount}"); // 使用宠物逻辑类增加经验(奖励方式) $petLogic = new PetLogic(); $levelUpOccurred = $petLogic->addExperienceReward($petId, $expAmount, 'test_command', null); // 刷新宠物数据 $pet->refresh(); $this->info("经验增加成功!"); $this->info("新经验值: {$pet->experience}"); $this->info("是否升级: " . ($levelUpOccurred ? '是' : '否')); $this->info("请检查日志以确认事件已正确触发和处理"); return 0; } catch (\Exception $e) { $this->error("测试失败: " . $e->getMessage()); Log::error('宠物经验增加测试失败', [ 'pet_id' => $petId, 'exp_amount' => $expAmount, 'error' => $e->getMessage() ]); return 1; } } }