user.py 1.4 KB

1234567891011121314151617181920212223242526272829
  1. """
  2. 用户模型
  3. """
  4. from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, SmallInteger
  5. from sqlalchemy.orm import relationship
  6. from app.database import Base
  7. class User(Base):
  8. """用户表"""
  9. __tablename__ = "users"
  10. id = Column(Integer, primary_key=True, index=True, comment="主键ID")
  11. username = Column(String(50), unique=True, nullable=False, index=True, comment="用户名")
  12. password = Column(String(255), nullable=False, comment="密码(加密)")
  13. email = Column(String(100), comment="邮箱")
  14. machine_code = Column(String(64), index=True, comment="机器码")
  15. card_id = Column(Integer, ForeignKey("cards.id"), comment="当前卡密ID")
  16. expire_time = Column(DateTime, index=True, comment="到期时间")
  17. last_login_time = Column(DateTime, comment="最后登录时间")
  18. last_login_ip = Column(String(50), comment="最后登录IP")
  19. status = Column(SmallInteger, default=1, index=True, comment="状态:1-正常,0-禁用")
  20. created_at = Column(DateTime, comment="创建时间")
  21. updated_at = Column(DateTime, comment="更新时间")
  22. # 关系
  23. card = relationship("Card", foreign_keys=[card_id], uselist=False) # 用户当前激活的卡密(一对一)
  24. recharge_records = relationship("RechargeRecord", back_populates="user")
  25. steam_accounts = relationship("SteamAccount", back_populates="user")