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(()) }