From dc417365de5a0ee4020468819b91634c70010d3c Mon Sep 17 00:00:00 2001 From: wsb1224 Date: Fri, 3 Jul 2026 21:48:31 +0800 Subject: [PATCH] =?UTF-8?q?7-3=20=E6=88=90=E6=9C=AC=E5=8D=95=E4=BB=B7?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BA=A7=E5=93=81=E5=AE=9A=E4=BB=B7=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=8D=95=E4=BB=B7(base=5Funit=5Fprice)=E5=B9=B6?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=8D=95=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端enrich_items_from_db返回base_unit_price和pricing_unit - formula_detail支持面积/重量/件等多种定价类型 - 前端成本单价列显示如¥150/㎡而非一件总价¥6000 Co-Authored-By: Claude Sonnet 4.6 --- backend/app/services/order_service.py | 15 ++++++++++++--- frontend/web-admin/src/views/OrdersPage.vue | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/app/services/order_service.py b/backend/app/services/order_service.py index 945528e..02c4461 100644 --- a/backend/app/services/order_service.py +++ b/backend/app/services/order_service.py @@ -308,15 +308,24 @@ class OrderService: rule = rules_map[item.product_id] item_dict["formula_expr"] = getattr(rule, "formula_expr", None) item_dict["formula_note"] = getattr(rule, "formula_note", None) + item_dict["base_unit_price"] = float(rule.base_unit_price or 0) + item_dict["pricing_unit"] = getattr(rule, "pricing_unit", None) # 构建人类可读的计算过程 if not item_dict.get("formula_detail"): try: + unit_price = float(rule.base_unit_price or 0) + pricing_type = getattr(rule, "pricing_type", "area") or "area" + pricing_unit = getattr(rule, "pricing_unit", "㎡") or "㎡" + qty = float(item.quantity or 0) length = float(getattr(item, "length_m", 0) or 0) width = float(getattr(item, "width_m", 0) or 0) - unit_price = float(rule.base_unit_price or 0) - if length and width and unit_price: + if pricing_type == "area" and length and width and unit_price: area = length * width - item_dict["formula_detail"] = f"{length}m × {width}m × ¥{unit_price}/㎡ = ¥{area * unit_price:.2f}" + item_dict["formula_detail"] = f"{length}m × {width}m × ¥{unit_price}/{pricing_unit} = ¥{area * unit_price:.2f}" + elif pricing_type in ("kg", "weight_g") and qty and unit_price: + item_dict["formula_detail"] = f"{qty}{pricing_unit} × ¥{unit_price}/{pricing_unit} = ¥{qty * unit_price:.2f}" + elif unit_price: + item_dict["formula_detail"] = f"{qty}{pricing_unit} × ¥{unit_price}/{pricing_unit} = ¥{qty * unit_price:.2f}" except Exception: pass diff --git a/frontend/web-admin/src/views/OrdersPage.vue b/frontend/web-admin/src/views/OrdersPage.vue index 61e0645..9e0b913 100644 --- a/frontend/web-admin/src/views/OrdersPage.vue +++ b/frontend/web-admin/src/views/OrdersPage.vue @@ -334,7 +334,7 @@ {{ item.demand_specification || "-" }} {{ item.unit || '-' }} {{ computeTotalDemand(item) || item.quantity }} - ¥{{ Number(item.cost_price || 0).toFixed(2) }} + ¥{{ Number(item.base_unit_price || item.cost_price || 0).toFixed(2) }}{{ item.pricing_unit ? '/' + item.pricing_unit : '' }} {{ item.formula_detail || `${item.quantity} × ¥${Number(item.cost_price || 0).toFixed(2)}` }}