card.py 1.4 KB

12345678910111213141516171819202122232425262728
  1. """
  2. 卡密模型
  3. """
  4. from datetime import datetime
  5. from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey
  6. from app.database import Base
  7. from app.utils.timezone import beijing_now_naive
  8. class Card(Base):
  9. """卡密表"""
  10. __tablename__ = "cards"
  11. id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
  12. card_code = Column(String(50), unique=True, nullable=False, comment="卡密代码")
  13. software_code = Column(String(50), nullable=False, comment="软件特征码")
  14. days = Column(Integer, nullable=False, comment="天数")
  15. discount = Column(Integer, default=100, comment="折扣(100=原价)")
  16. user_id = Column(Integer, nullable=True, comment="激活用户ID")
  17. activated_at = Column(DateTime, nullable=True, comment="激活时间")
  18. expire_time = Column(DateTime, nullable=True, comment="到期时间")
  19. status = Column(Integer, default=0, comment="状态: 0-未激活, 1-已激活, 2-已过期")
  20. is_deleted = Column(Boolean, default=False, comment="是否删除: 0-否, 1-是")
  21. created_at = Column(DateTime, default=beijing_now_naive, comment="创建时间")
  22. updated_at = Column(DateTime, default=beijing_now_naive, onupdate=beijing_now_naive, comment="更新时间")
  23. def __repr__(self):
  24. return f"<Card(id={self.id}, card_code='{self.card_code}', status={self.status})>"