From 5049c27f3df5bbcf2f41e3431bd309af41ce075e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Tue, 22 Sep 2026 13:49:01 +0800 Subject: [PATCH] =?UTF-8?q?3D=20=E5=AE=9A=E4=BB=B7=E8=A1=A8=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=97=B6=E6=8B=A6=E6=88=AA=E5=8A=A0=E6=80=BB=E6=BA=A2?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 底价与加价项累加改用 checked_add 校验,配置阶段即失败 - 避免结算路径 saturating_add 在异常配置下静默少收 --- .../crates/api-server/src/tripo3d/pricing.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server-rs/crates/api-server/src/tripo3d/pricing.rs b/server-rs/crates/api-server/src/tripo3d/pricing.rs index e40a1aa93..e3c808074 100644 --- a/server-rs/crates/api-server/src/tripo3d/pricing.rs +++ b/server-rs/crates/api-server/src/tripo3d/pricing.rs @@ -202,6 +202,24 @@ impl Model3dPricingConfig { return Err(format!("缺少 add-on {add_on:?} 的价格")); } } + // 加价项与底价都要累加进账单,配置阶段就挡住溢出,避免结算时静默截断。 + let add_on_total = self + .add_on_prices + .values() + .try_fold(0u32, |total, price| total.checked_add(*price)); + let max_base_price = self + .base_prices + .values() + .flat_map(|prices| prices.values()) + .flat_map(|price| [price.no_texture, price.texture]) + .max() + .unwrap_or(0); + if add_on_total + .and_then(|total| total.checked_add(max_base_price)) + .is_none() + { + return Err("3D 定价表加总超出 u32 上限,请下调配置价格".to_string()); + } Ok(()) }