""" 用户模型 """ from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, SmallInteger from sqlalchemy.orm import relationship from app.database import Base class User(Base): """用户表""" __tablename__ = "users" id = Column(Integer, primary_key=True, index=True, comment="主键ID") username = Column(String(50), unique=True, nullable=False, index=True, comment="用户名") password = Column(String(255), nullable=False, comment="密码(加密)") email = Column(String(100), comment="邮箱") machine_code = Column(String(64), index=True, comment="机器码") card_id = Column(Integer, ForeignKey("cards.id"), comment="当前卡密ID") expire_time = Column(DateTime, index=True, comment="到期时间") last_login_time = Column(DateTime, comment="最后登录时间") last_login_ip = Column(String(50), comment="最后登录IP") status = Column(SmallInteger, default=1, index=True, comment="状态:1-正常,0-禁用") is_deleted = Column(SmallInteger, default=0, index=True, comment="是否删除:0-否,1-是") created_at = Column(DateTime, comment="创建时间") updated_at = Column(DateTime, comment="更新时间") # 关系 card = relationship("Card", foreign_keys=[card_id], uselist=False) # 用户当前激活的卡密(一对一) recharge_records = relationship("RechargeRecord", back_populates="user") steam_accounts = relationship("SteamAccount", back_populates="user") sessions = relationship("Session", back_populates="user") # 用户的所有会话