getLandId(); $userId = $this->user_id; // 验证土地是否存在且属于当前用户 // 获取用户所有土地 $landInfo = LandService::getUserLand($userId,$landId); if (!$landInfo) { throw new LogicException("土地不存在或不属于当前用户1"); } // 获取可用的升级路径 $upgradePaths = LandService::getAvailableUpgradePaths($userId, $landId); if (empty($upgradePaths)) { throw new LogicException("当前没有可用的升级路径"); } // 记录日志,帮助调试 Log::info('获取到的升级路径', [ 'user_id' => $userId, 'land_id' => $landId, 'paths_count' => count($upgradePaths), 'first_path' => $upgradePaths[0] ?? null ]); // 选择第一个可用的升级路径 $upgradePath = $upgradePaths[0]; $targetType = $upgradePath['to_type_id']; // 升级土地 $result = LandService::upgradeLand($userId, $landId, $targetType); if (!$result) { throw new LogicException("升级土地失败"); } Log::info('用户土地升级成功', [ 'user_id' => $userId, 'land_id' => $landId, 'old_type' => $landInfo->landType, 'new_type' => $targetType ]); } catch (LogicException $e) { // 设置错误响应 $this->response->setCode(400); $this->response->setMsg($e->getMessage()); Log::warning('用户土地升级失败', [ 'user_id' => $this->user_id, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); } return $response; } }