|
|
@@ -745,6 +745,28 @@ async def simulate_calc(
|
|
|
if k.startswith("option_"):
|
|
|
option_ids.append(int(v))
|
|
|
|
|
|
+
|
|
|
+ # ---------------- 重新取模板与机型名 ----------------
|
|
|
+ row = db.execute(text("""
|
|
|
+ SELECT m.name,
|
|
|
+ t.estimate_packet
|
|
|
+ FROM machine_temp t
|
|
|
+ JOIN t_machine m ON t.machine_id = m.machine_id
|
|
|
+ WHERE t.machine_id = :mid
|
|
|
+ """), {"mid": machine_id}).fetchone()
|
|
|
+
|
|
|
+ if not row:
|
|
|
+ return HTMLResponse("机型模板不存在")
|
|
|
+ tpl = json.loads(row.estimate_packet)
|
|
|
+ # ---------------- 构造 valueId -> valueText 映射 ----------------
|
|
|
+ value_name_map = {}
|
|
|
+
|
|
|
+ for step in tpl["template"]:
|
|
|
+ for p in step["properties"]:
|
|
|
+ for v in p["values"]:
|
|
|
+ value_name_map[str(v["valueId"])] = v["valueText"]
|
|
|
+
|
|
|
+
|
|
|
# ---------------- 基准价 ----------------
|
|
|
|
|
|
base_row = db.execute(text("""
|
|
|
@@ -754,7 +776,14 @@ async def simulate_calc(
|
|
|
LIMIT 1
|
|
|
"""), {"mid": machine_id}).fetchone()
|
|
|
|
|
|
- base_price = float(base_row.base_price) if base_row else 1000.0
|
|
|
+
|
|
|
+ base_price_input = form.get("base_price")
|
|
|
+
|
|
|
+ if base_price_input and str(base_price_input).strip():
|
|
|
+ base_price = float(base_price_input)
|
|
|
+ else:
|
|
|
+ base_price = float(base_row.base_price) if base_row else 1
|
|
|
+ # base_price = float(base_row.base_price) if base_row else 1000.0
|
|
|
|
|
|
# ---------------- 读取选项扣减规则 ----------------
|
|
|
|
|
|
@@ -871,7 +900,8 @@ async def simulate_calc(
|
|
|
|
|
|
for it in items:
|
|
|
detail_rows.append({
|
|
|
- "option_name": it.option_id,
|
|
|
+ # "option_name": it.option_id,
|
|
|
+ "option_name": value_name_map.get(str(it.option_id), str(it.option_id)),
|
|
|
"factor": it.factor
|
|
|
})
|
|
|
|
|
|
@@ -929,7 +959,7 @@ async def simulate_calc(
|
|
|
WHERE t.machine_id = :mid
|
|
|
"""), {"mid": machine_id}).fetchone()
|
|
|
|
|
|
- import json
|
|
|
+ # import json
|
|
|
tpl = json.loads(row.estimate_packet)
|
|
|
|
|
|
return templates.TemplateResponse(
|
|
|
@@ -1229,3 +1259,8 @@ def calculate_price(db, base_price: float, selected_option_ids: list[int]):
|
|
|
"special_discount_applied": special_applied,
|
|
|
"details": details
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+# curl -sS -X POST "http://127.0.0.1:8002/api/product/bid" -H "Content-Type: application/json" -H "X-API-Key: dHiw0yduUhnpQRV9z30EGpJD8fAne1CJ" -d '{"task_id":2,"task_types":["bid"]}'
|