|
|
@@ -74,9 +74,10 @@ async def create_order(
|
|
|
|
|
|
name_col = f"name_{lang}" if lang in ["en", "ru", "me"] else "name_en"
|
|
|
|
|
|
- mat_info = db.execute_query(f"SELECT {name_col}, price_per_cm3 FROM materials WHERE id = %s", (material_id,))
|
|
|
+ mat_info = db.execute_query(f"SELECT {name_col}, price_per_cm3, price_per_hour FROM materials WHERE id = %s", (material_id,))
|
|
|
mat_name = mat_info[0][name_col] if mat_info else "Unknown"
|
|
|
mat_price = mat_info[0]['price_per_cm3'] if mat_info else 0.0
|
|
|
+ hour_price = mat_info[0]['price_per_hour'] if mat_info and mat_info[0]['price_per_hour'] is not None else config.DEFAULT_PRINTER_HOUR_PRICE
|
|
|
|
|
|
file_sizes = []
|
|
|
if parsed_ids:
|
|
|
@@ -90,6 +91,7 @@ async def create_order(
|
|
|
original_params = json.dumps({
|
|
|
"material_name": mat_name,
|
|
|
"material_price": float(mat_price) if mat_price is not None else 0.0,
|
|
|
+ "printer_hour_price": float(hour_price),
|
|
|
"estimated_price": float(estimated_price) if estimated_price is not None else 0.0,
|
|
|
"quantity": quantity,
|
|
|
"color_name": color_name,
|
|
|
@@ -107,10 +109,10 @@ async def create_order(
|
|
|
})
|
|
|
|
|
|
order_query = """
|
|
|
- INSERT INTO orders (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, status, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, material_name, material_price, color_name, quantity, notes, original_params)
|
|
|
- VALUES (%s, %s, %s, %s, %s, %s, %s, %s, 'pending', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
|
|
+ INSERT INTO orders (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, status, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, material_name, material_price, printer_hour_price, color_name, quantity, notes, original_params)
|
|
|
+ VALUES (%s, %s, %s, %s, %s, %s, %s, %s, 'pending', %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
|
|
"""
|
|
|
- order_params = (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, mat_name, mat_price, color_name, quantity, notes, original_params)
|
|
|
+ order_params = (user_id, material_id, first_name, last_name, phone, email, shipping_address, model_link, is_company, company_name, company_pib, company_address, allow_portfolio, estimated_price, mat_name, mat_price, hour_price, color_name, quantity, notes, original_params)
|
|
|
|
|
|
try:
|
|
|
order_insert_id = db.execute_commit(order_query, order_params)
|
|
|
@@ -226,19 +228,15 @@ async def get_public_reviews():
|
|
|
|
|
|
@router.post("/estimate")
|
|
|
async def get_price_estimate(data: schemas.EstimateRequest):
|
|
|
- material = db.execute_query("SELECT price_per_cm3 FROM materials WHERE id = %s", (data.material_id,))
|
|
|
- price_per_cm3 = float(material[0]['price_per_cm3']) if material else 0.0
|
|
|
+ estimated_total, file_prices = pricing.calculate_estimated_price(
|
|
|
+ data.material_id,
|
|
|
+ data.file_sizes,
|
|
|
+ data.file_quantities,
|
|
|
+ return_details=True
|
|
|
+ )
|
|
|
|
|
|
- file_prices = []
|
|
|
- base_fee = 5.0
|
|
|
- for size in data.file_sizes:
|
|
|
- total_size_mb = size / (1024 * 1024)
|
|
|
- estimated_volume = total_size_mb * 8.0
|
|
|
- file_cost = base_fee + (estimated_volume * price_per_cm3)
|
|
|
- file_prices.append(round(file_cost, 2))
|
|
|
-
|
|
|
qts = data.file_quantities if data.file_quantities else [1]*len(data.file_sizes)
|
|
|
- return {"file_prices": file_prices, "total_estimate": round(sum(p * q for p, q in zip(file_prices, qts)), 2)}
|
|
|
+ return {"file_prices": file_prices, "total_estimate": estimated_total}
|
|
|
|
|
|
# --- ADMIN ORDER ENDPOINTS ---
|
|
|
|
|
|
@@ -363,12 +361,14 @@ async def update_order(
|
|
|
update_fields.append("material_id = %s")
|
|
|
params.append(data.material_id)
|
|
|
# Also update snapshot names and prices from handbook
|
|
|
- mat_info = db.execute_query("SELECT name_en, price_per_cm3 FROM materials WHERE id = %s", (data.material_id,))
|
|
|
+ mat_info = db.execute_query("SELECT name_en, price_per_cm3, price_per_hour FROM materials WHERE id = %s", (data.material_id,))
|
|
|
if mat_info:
|
|
|
update_fields.append("material_name = %s")
|
|
|
params.append(mat_info[0]['name_en'])
|
|
|
update_fields.append("material_price = %s")
|
|
|
params.append(mat_info[0]['price_per_cm3'])
|
|
|
+ update_fields.append("printer_hour_price = %s")
|
|
|
+ params.append(mat_info[0]['price_per_hour'] if mat_info[0]['price_per_hour'] is not None else config.DEFAULT_PRINTER_HOUR_PRICE)
|
|
|
elif data.material_name is not None:
|
|
|
update_fields.append("material_name = %s")
|
|
|
params.append(data.material_name)
|