From a6409d79dc0db283b439c2c07a466ba44c2742ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Thu, 24 Sep 2026 20:34:57 +0800 Subject: [PATCH] =?UTF-8?q?3D=20=E5=AE=9A=E4=BB=B7=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=9C=A8=E5=8A=A0=E8=BD=BD=E6=97=B6=E6=A3=80=E6=9F=A5=E5=8A=A0?= =?UTF-8?q?=E6=80=BB=E6=BA=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - pricing:加载校验删掉「两段加价项相加 + 全表最高底价」的溢出检查与对应的 overflow_error 助手,只保留每段键齐全与合法性的校验 - 理由写进注释:真实查价只用一个端点的底价与它自己的加价项,价格都是手填的小数字,撞不到 u32 上限;按两段相加去挡反而会拒掉能正常计费的配置 - 计费点的 checked_add 保留为唯一一道溢出闸,溢出即失败退款(PriceOverflow 的说明同步改掉「配置阶段已挡过一次」的说法) --- .../crates/api-server/src/tripo3d/pricing.rs | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/server-rs/crates/api-server/src/tripo3d/pricing.rs b/server-rs/crates/api-server/src/tripo3d/pricing.rs index b5a497a75..3d945729a 100644 --- a/server-rs/crates/api-server/src/tripo3d/pricing.rs +++ b/server-rs/crates/api-server/src/tripo3d/pricing.rs @@ -208,7 +208,7 @@ pub(crate) enum Model3dPricingError { MissingAddOnPrice(Model3dAddOn), /// `texture=false` 却带上贴图类加价项:组合自相矛盾,直接报错而不是照价收费。 InconsistentTextureAddOn(Model3dAddOn), - /// 底价 + 加价项累加超出 `u32`:配置阶段已挡过一次,这里是计费点的第二道闸。 + /// 底价 + 加价项累加超出 `u32`:计费点直接失败退款,不静默截断成错价。 PriceOverflow, } @@ -241,27 +241,16 @@ impl std::error::Error for Model3dPricingError {} impl Model3dPricingConfig { /// 加载即校验:两段各自要求每个模型版本 × 两种贴图态与全部加价项键齐全。 + /// + /// 刻意不在这里做「加价项 + 底价会不会超出 u32」的检查:真实查价只用到一个端点的 + /// 底价与它自己的加价项,价格都是运营手填的小数字,撞到 42 亿的上限不现实,而按 + /// 「两段加价 + 全表最高底价」去挡反而会拒掉完全能正常计费的配置。万一真的加满, + /// [`Model3dEndpointPricing::price`] 会在计费点报 [`Model3dPricingError::PriceOverflow`], + /// 不会静默截断收费。 pub(crate) fn validate(&self) -> Result<(), String> { for endpoint in Model3dEndpoint::ALL { self.endpoint_pricing(endpoint).validate(endpoint)?; } - // 加价项与底价都要累加进账单,配置阶段就挡住溢出,避免结算时静默截断。 - let mut add_on_total = 0u32; - let mut max_base_price = 0u32; - for endpoint in Model3dEndpoint::ALL { - let pricing = self.endpoint_pricing(endpoint); - for price in pricing.add_on_prices.values() { - add_on_total = add_on_total - .checked_add(*price) - .ok_or_else(overflow_error)?; - } - for price in pricing.version_prices.values() { - max_base_price = max_base_price.max(price.no_texture).max(price.texture); - } - } - add_on_total - .checked_add(max_base_price) - .ok_or_else(overflow_error)?; Ok(()) } @@ -282,10 +271,6 @@ impl Model3dPricingConfig { } } -fn overflow_error() -> String { - "3D 定价表加总超出 u32 上限,请下调配置价格".to_string() -} - impl Model3dEndpointPricing { pub(crate) fn validate(&self, endpoint: Model3dEndpoint) -> Result<(), String> { for model_version in Model3dModelVersion::ALL.iter().copied() { @@ -334,7 +319,7 @@ impl Model3dEndpointPricing { .add_on_prices .get(&add_on) .ok_or(Model3dPricingError::MissingAddOnPrice(add_on))?; - // 与加载校验口径一致:溢出就报错退款,不静默夹到 u32 上限后按错价收费。 + // 唯一的一道溢出闸就在这里:溢出就报错退款,不静默夹到 u32 上限按错价收费。 total .checked_add(*price) .ok_or(Model3dPricingError::PriceOverflow)