3D 定价表加载时拦截加总溢出

- 底价与加价项累加改用 checked_add 校验,配置阶段即失败
- 避免结算路径 saturating_add 在异常配置下静默少收
This commit is contained in:
2026-09-22 13:49:01 +08:00
parent 129e2234f3
commit 5049c27f3d
@@ -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(())
}