1
This commit is contained in:
@@ -332,7 +332,37 @@ async def list_orders(
|
||||
for o in orders:
|
||||
await _check_and_expire_order(db, o)
|
||||
|
||||
return {"items": [PaymentOrderOut.model_validate(o) for o in orders], "total": total}
|
||||
# 开票模式:附带订单占用状态
|
||||
items = []
|
||||
if invoice_mode:
|
||||
# 收集当前页订单ID
|
||||
order_ids = [o.id for o in orders]
|
||||
# 查询这些订单是否已被占用
|
||||
from app.models.invoice import Invoice, InvoiceOrder
|
||||
occupied_map: dict[str, str] = {}
|
||||
if order_ids:
|
||||
occ_result = await db.execute(
|
||||
select(InvoiceOrder.order_id, Invoice.invoice_no)
|
||||
.join(Invoice, InvoiceOrder.invoice_id == Invoice.id)
|
||||
.where(
|
||||
InvoiceOrder.order_id.in_(order_ids),
|
||||
Invoice.status.in_(["processing", "success"]),
|
||||
)
|
||||
)
|
||||
for row in occ_result.all():
|
||||
occupied_map[row.order_id] = row.invoice_no
|
||||
for o in orders:
|
||||
item = PaymentOrderOut.model_validate(o)
|
||||
item_dict = item.model_dump()
|
||||
item_dict["is_occupied"] = o.id in occupied_map
|
||||
item_dict["occupied_by"] = occupied_map.get(o.id)
|
||||
items.append(item_dict)
|
||||
else:
|
||||
for o in orders:
|
||||
item = PaymentOrderOut.model_validate(o)
|
||||
items.append(item.model_dump())
|
||||
|
||||
return {"items": items, "total": total}
|
||||
|
||||
|
||||
@router.get("/orders/{order_no}", response_model=PaymentOrderOut)
|
||||
|
||||
Reference in New Issue
Block a user