nomadro/apps/ebook/wemini/backend/app/jobs/reconcile.py
eric d93a355fd5 Migrate navmini/ebook/nomadweb into apps/ as same-origin portal subpaths.
Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 03:30:34 -05:00

24 lines
1007 B
Python

"""支付查单兜底任务。"""
from __future__ import annotations
from app.services.store import store
from app.services.wxpay import query_order
async def reconcile_pending_orders() -> None:
"""推送丢失时,周期 query_order 查单补发货。"""
pending = store.list_pending_orders()
for order in pending:
try:
data = await query_order(order["openid"], order["out_trade_no"])
text = str(data).lower()
if "not pay" in text or "unpaid" in text or data.get("errcode") not in (0, None, "0"):
if data.get("errcode") not in (0, None, "0"):
continue
if any(k in text for k in ["success", "paid", "已支付", '"status": 1', "order_state\":1"]):
wx_id = str(data.get("wx_order_id") or data.get("order_id") or order["out_trade_no"])
store.mark_delivered(order["out_trade_no"], wx_order_id=wx_id, raw_notify=str(data))
except Exception:
continue