feat: 新增后端支付模块,支持微信和支付宝
- 新增api/payment/支付服务(微信、支付宝) - 新增api/routers/payment.py支付路由 - 更新database/models.py支付相关模型 - 新增数据库迁移文件(订单表、用户订阅字段) - 更新main.py、requirements.txt、.env.production Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -27,12 +27,14 @@ class User(Base):
|
||||
nickname = Column(String, nullable=False)
|
||||
avatar_url = Column(String, nullable=True)
|
||||
subscription_type = Column(String, default="free") # free, premium
|
||||
subscription_expires_at = Column(DateTime(timezone=True), nullable=True) # 订阅到期时间
|
||||
created_at = Column(DateTime(timezone=True), default=utc_now)
|
||||
|
||||
# Relationships
|
||||
conversations = relationship("Conversation", back_populates="user")
|
||||
chapters = relationship("Chapter", back_populates="user")
|
||||
books = relationship("Book", back_populates="user")
|
||||
orders = relationship("Order", back_populates="user", cascade="all, delete-orphan")
|
||||
memoir_state = relationship("MemoirState", back_populates="user", uselist=False, cascade="all, delete-orphan")
|
||||
refresh_tokens = relationship("RefreshToken", back_populates="user", cascade="all, delete-orphan")
|
||||
|
||||
@@ -158,3 +160,24 @@ class SmsVerificationCode(Base):
|
||||
verified_at = Column(DateTime(timezone=True), nullable=True) # 验证时间
|
||||
ip_address = Column(String, nullable=True) # 请求IP地址
|
||||
|
||||
|
||||
class Order(Base):
|
||||
"""支付订单表"""
|
||||
__tablename__ = "orders"
|
||||
|
||||
id = Column(String, primary_key=True) # 内部订单号
|
||||
user_id = Column(String, ForeignKey("users.id"), nullable=False, index=True)
|
||||
plan_id = Column(String, nullable=False) # 套餐 ID(free / premium)
|
||||
plan_name = Column(String, nullable=False) # 套餐名称
|
||||
amount = Column(Integer, nullable=False) # 金额(单位:分)
|
||||
currency = Column(String, default="CNY")
|
||||
payment_method = Column(String, nullable=False) # wechat / alipay
|
||||
status = Column(String, default="pending") # pending / paid / failed / cancelled / refunded
|
||||
trade_no = Column(String, nullable=True, index=True) # 第三方交易号(微信/支付宝)
|
||||
paid_at = Column(DateTime(timezone=True), nullable=True) # 支付完成时间
|
||||
created_at = Column(DateTime(timezone=True), default=utc_now)
|
||||
expired_at = Column(DateTime(timezone=True), nullable=True) # 订单超时时间
|
||||
|
||||
# Relationships
|
||||
user = relationship("User", back_populates="orders")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user