nomadro/apps/api/services/ebook_svc/jobs/reconcile.py
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

24 lines
1019 B
Python

"""支付查单兜底任务。"""
from __future__ import annotations
from ebook_svc.services.store import store
from ebook_svc.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