card.py 1.4 KB

12345678910111213141516171819202122232425262728
  1. """
  2. 卡密模型
  3. """
  4. from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, SmallInteger, Numeric
  5. from sqlalchemy.orm import relationship
  6. from app.database import Base
  7. class Card(Base):
  8. """卡密表"""
  9. __tablename__ = "cards"
  10. id = Column(Integer, primary_key=True, index=True, comment="主键ID")
  11. card_code = Column(String(32), unique=True, nullable=False, index=True, comment="卡密代码")
  12. software_code = Column(String(50), nullable=False, index=True, comment="软件特征码")
  13. days = Column(Integer, nullable=False, comment="天数")
  14. discount = Column(Numeric(5, 2), default=1.00, comment="折扣")
  15. user_id = Column(Integer, ForeignKey("users.id"), index=True, comment="激活用户ID")
  16. activated_at = Column(DateTime, comment="激活时间")
  17. expire_time = Column(DateTime, index=True, comment="到期时间")
  18. status = Column(SmallInteger, default=0, index=True, comment="状态:0-未激活,1-已激活,2-已过期")
  19. is_deleted = Column(SmallInteger, default=0, index=True, comment="是否删除:0-否,1-是")
  20. created_at = Column(DateTime, comment="创建时间")
  21. updated_at = Column(DateTime, comment="更新时间")
  22. # 关系
  23. user = relationship("User", foreign_keys=[user_id]) # 激活该卡密的用户(多对一)
  24. recharge_records = relationship("RechargeRecord", back_populates="card")