fix: 采购价格上限按数量计算总价 (#181)

This commit is contained in:
chengma
2026-08-12 14:43:18 +08:00
parent 8c7be7bd07
commit 253be7cb61
24 changed files with 203 additions and 106 deletions
+9 -4
View File
@@ -37,7 +37,7 @@ class PurchaseTarget:
goods_url: str
options: Mapping[str, str]
quantity: int
max_price_cent: int
max_price_cent: int # 人民币订单总价上限,单位分
@dataclass(frozen=True)
@@ -386,7 +386,7 @@ class PurchaseTaskService:
):
raise PddPurchaseError(
"PURCHASE_TASK_INVALID",
"人民币价格上限必须是大于 0 的整数分",
"人民币订单总价上限必须是大于 0 的整数分",
step="purchase_prepare",
)
return PurchaseTarget(
@@ -450,11 +450,16 @@ class PurchaseTaskService:
"无法读取稳定的当前人民币价格,已停止演练",
step="purchase_verify_quantity_price",
)
if state.price_cent > target.max_price_cent:
# 商品页或规格面板可能显示单价,也可能随数量显示小计;只有最终确认页
# 的金额具有稳定的订单总价语义,因此总价保护只在确认页执行。
if (
state.page_kind == "order_confirmation"
and state.price_cent > target.max_price_cent
):
raise PddPurchaseError(
"PURCHASE_PRICE_EXCEEDED",
(
f"当前价格 {state.price_cent} 分超过上限 "
f"当前订单总价 {state.price_cent} 分超过订单总价上限 "
f"{target.max_price_cent} 分,已停止演练"
),
step="purchase_verify_quantity_price",