argument('pet_id'); $itemId = (int) $this->argument('item_id'); $amount = (int) $this->argument('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("物品ID: {$itemId}"); $this->info("数量: {$amount}"); $this->info("当前经验: {$pet->experience}"); $this->info("当前体力: {$pet->stamina}"); // 开启事务并使用宠物逻辑类进行喂养 DB::beginTransaction(); try { $petLogic = new PetLogic(); $feedResult = $petLogic->feedPet($petId, $itemId, $amount); DB::commit(); } catch (\Exception $e) { DB::rollBack(); throw $e; } // 刷新宠物数据 $pet->refresh(); $this->info("喂养成功!"); $this->info("新经验值: {$pet->experience}"); $this->info("新体力值: {$pet->stamina}"); $this->info("经验增加: " . ($feedResult['exp_gained'] ?? 0)); $this->info("体力增加: " . ($feedResult['stamina_gained'] ?? 0)); $this->info("请检查日志以确认宠物经验增加事件已正确触发和处理"); return 0; } catch (\Exception $e) { $this->error("测试失败: " . $e->getMessage()); Log::error('宠物喂养测试失败', [ 'pet_id' => $petId, 'item_id' => $itemId, 'amount' => $amount, 'error' => $e->getMessage() ]); return 1; } } }