修改订单查询接口逻辑、前台页面增加刷新页面订单消失问题,调整后台支付账单页面数据问题

This commit is contained in:
2026-06-11 13:51:46 +08:00
parent cace26018a
commit 1b7b794164
4 changed files with 134 additions and 15 deletions
+24 -6
View File
@@ -448,6 +448,13 @@ async def get_payment_stats(
"""Return payment statistics for admin dashboard."""
from sqlalchemy import func
# Ensure by_status has all expected statuses with defaults
by_status = {
"pending": {"count": 0, "amount": 0.0},
"paid": {"count": 0, "amount": 0.0},
"cancelled": {"count": 0, "amount": 0.0},
}
# Status breakdown
status_result = await db.execute(
select(
@@ -456,12 +463,22 @@ async def get_payment_stats(
func.coalesce(func.sum(PaymentOrder.amount), 0).label("amount"),
).group_by(PaymentOrder.status)
)
by_status = {}
for row in status_result.all():
by_status[row.status] = {"count": row.count, "amount": round(float(row.amount), 2)}
if row.status in by_status:
by_status[row.status] = {
"count": row.count,
"amount": round(float(row.amount), 2)
}
else:
# Map any unexpected status to cancelled
by_status["cancelled"]["count"] += row.count
by_status["cancelled"]["amount"] += round(float(row.amount), 2)
# Today's stats
today_start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
# Today's stats (CST time zone)
now_cst = datetime.now(CST)
today_start = now_cst.replace(hour=0, minute=0, second=0, microsecond=0)
today_end = today_start + timedelta(days=1)
today_result = await db.execute(
select(
func.count().label("paid_count"),
@@ -469,6 +486,7 @@ async def get_payment_stats(
).where(
PaymentOrder.status == "paid",
PaymentOrder.paid_at >= today_start,
PaymentOrder.paid_at < today_end,
)
)
today_row = today_result.one()
@@ -495,7 +513,7 @@ async def get_payment_stats(
"amount": round(o.amount, 2),
"credits": round(o.credits, 2),
"payment_method": o.payment_method,
"status": o.status,
"status": o.status if o.status in ("pending", "paid", "cancelled") else "cancelled",
"trade_no": o.trade_no,
"paid_at": _iso(o.paid_at),
"created_at": _iso(o.created_at),
@@ -547,7 +565,7 @@ async def get_admin_payment_orders(
"amount": round(o.amount, 2),
"credits": round(o.credits, 2),
"payment_method": o.payment_method,
"status": o.status,
"status": o.status if o.status in ("pending", "paid", "cancelled") else "cancelled",
"trade_no": o.trade_no,
"paid_at": _iso(o.paid_at),
"created_at": _iso(o.created_at),