args[0] ?? 'user_id'; $upgradeConfigKey = $this->args[1] ?? 'upgrade_config'; $userId = $data[$userIdKey] ?? null; $upgradeConfig = $this->validation->$upgradeConfigKey ?? null; if (!$userId) { $this->addError('用户ID不能为空'); return false; } if (!$upgradeConfig) { $this->addError('升级配置不存在,请先验证升级路径'); return false; } try { // 获取目标土地类型 $targetLandType = FarmLandType::find($upgradeConfig->to_type_id); if (!$targetLandType) { $this->addError('目标土地类型不存在'); return false; } // 如果不是特殊土地,直接通过验证 if (!$targetLandType->is_special) { return true; } // 获取用户农场信息 $farmUser = FarmUser::where('user_id', $userId)->first(); if (!$farmUser) { $this->addError('用户农场信息不存在'); return false; } // 获取用户当前特殊土地数量 $specialLandCount = FarmLand::where('user_id', $userId) ->whereIn('land_type', [ LAND_TYPE::GOLD->value, LAND_TYPE::BLUE->value, LAND_TYPE::PURPLE->value ]) ->count(); // 获取房屋配置 $houseConfig = $farmUser->houseConfig; if (!$houseConfig) { $this->addError('房屋配置不存在'); return false; } // 检查特殊土地数量限制 if ($specialLandCount >= $houseConfig->special_land_limit) { $this->addError("特殊土地数量已达上限({$houseConfig->special_land_limit}块),当前已有{$specialLandCount}块"); return false; } return true; } catch (\Exception $e) { Log::error('验证特殊土地数量限制时发生错误', [ 'user_id' => $userId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); $this->addError('验证特殊土地数量限制时发生错误: ' . $e->getMessage()); return false; } } }