""" 用户-软件订阅关系模型(多软件共用一套用户表) 同一用户在不同软件下可有独立的卡密与到期时间。 """ from datetime import datetime from app.utils.timezone import beijing_now_naive from sqlalchemy import Column, Integer, DateTime, Boolean, UniqueConstraint, ForeignKey from app.database import Base class UserSoftwareSubscription(Base): """用户软件订阅表:user_id + software_id 唯一,存储该用户在该软件下的卡密与到期时间""" __tablename__ = "user_software_subscription" id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID") user_id = Column(Integer, ForeignKey("users.id"), nullable=False, comment="用户ID") software_id = Column(Integer, ForeignKey("software.id"), nullable=False, comment="软件ID") card_id = Column(Integer, nullable=True, comment="当前卡密ID") expire_time = Column(DateTime, nullable=True, comment="到期时间") is_deleted = Column(Boolean, default=False, comment="是否删除: 0-否, 1-是") created_at = Column(DateTime, default=beijing_now_naive, comment="创建时间") updated_at = Column(DateTime, default=beijing_now_naive, onupdate=beijing_now_naive, comment="更新时间") __table_args__ = (UniqueConstraint("user_id", "software_id", name="uq_user_software"),) def __repr__(self): return f""