Files
Pine f1147dced3 feat(pay): 微信支付V3子应用与算力充值
- app/pay 独立支付子应用(config/wxpay/models/repository/service/routers),便于后期拆分微服务
- 充值订单表 0026_compute_recharge;套餐支持折扣(discount)与上架开关(enabled),DB system_configs 优先、env 兜底
- 统一小程序支付:桌面端出小程序码→扫码进小程序确认页按 openid 发起 JSAPI→回调幂等到账(引擎 adjust_user_quota+镜像回写)
- 内嵌 wechatpayv3(含 async_),响应验签失败降级告警;新增 aiofiles 依赖

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-30 22:29:44 +08:00

40 lines
2.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""支付子应用 ORM:算力充值订单(落平台主库,alembic 统一迁移)。"""
from __future__ import annotations
from sqlalchemy import Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column
from ..infrastructure.db import Base
class ComputeRechargeOrder(Base):
"""算力充值订单(微信支付 V3)。
状态机:pending → paid(支付成功,本地终态)→ credited(引擎到账完成);
pending 超时未支付 → closed;到账异常 → failed(待人工/对账补单)。
"""
__tablename__ = "compute_recharge_orders"
id: Mapped[str] = mapped_column(String, primary_key=True) # cr_<hex>
order_no: Mapped[str] = mapped_column(String, unique=True, index=True) # CR_<ts>_<hex8>,微信 out_trade_no
user_id: Mapped[str] = mapped_column(String, default="", index=True) # 平台 users.id
username: Mapped[str] = mapped_column(String, default="", index=True) # 平台/引擎用户名(充值归集键)
engine_user_id: Mapped[int] = mapped_column(Integer, default=0) # 引擎用户 id(下单时解析缓存,0=待解析)
package_id: Mapped[str] = mapped_column(String, default="") # 套餐 id;空 = 自由金额
amount_fen: Mapped[int] = mapped_column(Integer, default=0) # 实付金额(分,微信口径)
quota_micro: Mapped[int] = mapped_column(Integer, default=0) # 到账微元 = amount_fen//100 * 1_000_000
bonus_quota_micro: Mapped[int] = mapped_column(Integer, default=0) # 套餐赠送微元
client_type: Mapped[str] = mapped_column(String, default="native") # native(扫码) | jsapi(小程序)
appid: Mapped[str] = mapped_column(String, default="") # 下单所用 appid(对账依据)
status: Mapped[str] = mapped_column(String, default="pending", index=True) # pending|paid|credited|closed|failed
prepay_id: Mapped[str] = mapped_column(String, default="") # 微信预支付单号(jsapi
transaction_id: Mapped[str] = mapped_column(String, default="", index=True) # 微信支付单号
code_url: Mapped[str] = mapped_column(String, default="") # Native 二维码内容
expires_at: Mapped[str] = mapped_column(String, default="") # 过期时刻(ISO,超时未付 → closed)
paid_at: Mapped[str] = mapped_column(String, default="")
credited_at: Mapped[str] = mapped_column(String, default="") # 引擎到账完成时刻
notify_payload: Mapped[str] = mapped_column(Text, default="") # 回调/查单原始报文(JSON 串,排查用)
created_at: Mapped[str] = mapped_column(String, default="", index=True)
updated_at: Mapped[str] = mapped_column(String, default="")