where('id', $item->targetId) ->first(); if (!$pet) { throw new Exception("找不到ID为 {$item->targetId} 的宠物"); } // 使用宠物逻辑类来增加体力 $petLogic = new \App\Module\Pet\Logic\PetLogic(); $reflection = new ReflectionClass($petLogic); $method = $reflection->getMethod('addStamina'); $method->setAccessible(true); $actualGained = $method->invoke($petLogic, $item->targetId, $item->quantity); Log::info("宠物体力奖励发放成功", [ 'userId' => $userId, 'petId' => $item->targetId, 'staminaAmount' => $item->quantity, 'actualGained' => $actualGained, 'sourceType' => $sourceType, 'sourceId' => $sourceId ]); } catch (Exception $e) { Log::error("宠物体力奖励发放失败", [ 'userId' => $userId, 'petId' => $item->targetId, 'staminaAmount' => $item->quantity, 'sourceType' => $sourceType, 'sourceId' => $sourceId, 'error' => $e->getMessage() ]); throw new Exception("宠物体力奖励发放失败: " . $e->getMessage()); } } }