91 lines
4.1 KiB
Python
91 lines
4.1 KiB
Python
# app/models/wechat_payment.py
|
|
from sqlalchemy import Column, Integer, String, DateTime, DECIMAL, JSON
|
|
from sqlalchemy.sql import func
|
|
from pydantic import BaseModel, Field
|
|
from typing import Optional, Dict, Any, List
|
|
from datetime import datetime
|
|
from .database import Base
|
|
|
|
class WechatPaymentRecordDB(Base):
|
|
"""微信支付记录表"""
|
|
__tablename__ = "wechat_payment_records"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
out_trade_no = Column(String(32), nullable=False, index=True, comment='商户订单号')
|
|
transaction_id = Column(String(64), index=True, comment='微信支付交易号')
|
|
trade_state = Column(String(32), comment='交易状态')
|
|
trade_state_desc = Column(String(256), comment='交易状态描述')
|
|
success_time = Column(DateTime(timezone=True), comment='支付成功时间')
|
|
total_amount = Column(DECIMAL(10, 2), comment='订单总金额')
|
|
payer_total = Column(DECIMAL(10, 2), comment='用户实际支付金额')
|
|
currency = Column(String(16), default='CNY', comment='货币类型')
|
|
payer_openid = Column(String(128), comment='支付者openid')
|
|
attach = Column(String(128), comment='附加数据')
|
|
bank_type = Column(String(32), comment='付款银行类型')
|
|
promotion_detail = Column(JSON, comment='优惠信息')
|
|
raw_data = Column(JSON, comment='原始返回数据')
|
|
create_time = Column(DateTime(timezone=True), server_default=func.now(), comment='创建时间')
|
|
update_time = Column(DateTime(timezone=True), onupdate=func.now(), comment='更新时间')
|
|
|
|
# Pydantic 模型
|
|
class WechatPaymentRecordInfo(BaseModel):
|
|
id: int
|
|
out_trade_no: str
|
|
transaction_id: Optional[str] = None
|
|
trade_state: Optional[str] = None
|
|
trade_state_desc: Optional[str] = None
|
|
success_time: Optional[datetime] = None
|
|
total_amount: Optional[float] = None
|
|
payer_total: Optional[float] = None
|
|
currency: str = 'CNY'
|
|
payer_openid: Optional[str] = None
|
|
attach: Optional[str] = None
|
|
bank_type: Optional[str] = None
|
|
promotion_detail: Optional[List[Dict[str, Any]]] = None
|
|
raw_data: Optional[Dict[str, Any]] = None
|
|
create_time: datetime
|
|
update_time: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
class WechatRefundRecordDB(Base):
|
|
"""微信退款记录表"""
|
|
__tablename__ = "wechat_refund_records"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
out_trade_no = Column(String(32), nullable=False, index=True, comment='商户订单号')
|
|
out_refund_no = Column(String(64), nullable=False, index=True, comment='商户退款单号')
|
|
refund_id = Column(String(64), index=True, comment='微信退款单号')
|
|
transaction_id = Column(String(64), index=True, comment='微信支付交易号')
|
|
refund_status = Column(String(32), comment='退款状态')
|
|
success_time = Column(DateTime(timezone=True), comment='退款成功时间')
|
|
refund_amount = Column(DECIMAL(10, 2), comment='退款金额')
|
|
total_amount = Column(DECIMAL(10, 2), comment='订单总金额')
|
|
user_received_account = Column(String(256), comment='退款入账账户')
|
|
currency = Column(String(16), default='CNY', comment='货币类型')
|
|
refund_reason = Column(String(256), comment='退款原因')
|
|
raw_data = Column(JSON, comment='原始返回数据')
|
|
create_time = Column(DateTime(timezone=True), server_default=func.now(), comment='创建时间')
|
|
update_time = Column(DateTime(timezone=True), onupdate=func.now(), comment='更新时间')
|
|
|
|
# Pydantic 模型
|
|
class WechatRefundRecordInfo(BaseModel):
|
|
id: int
|
|
out_trade_no: str
|
|
out_refund_no: str
|
|
refund_id: Optional[str] = None
|
|
transaction_id: Optional[str] = None
|
|
refund_status: Optional[str] = None
|
|
success_time: Optional[datetime] = None
|
|
refund_amount: Optional[float] = None
|
|
total_amount: Optional[float] = None
|
|
user_received_account: Optional[str] = None
|
|
currency: str = 'CNY'
|
|
refund_reason: Optional[str] = None
|
|
raw_data: Optional[Dict[str, Any]] = None
|
|
create_time: datetime
|
|
update_time: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True |