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