recharge_record_his.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """
  2. 充值记录历史模型
  3. 用于记录充值记录的变更历史,支持审计和追溯
  4. """
  5. from datetime import datetime
  6. from app.utils.timezone import beijing_now_naive
  7. from sqlalchemy import Column, Integer, String, DateTime, Text
  8. from app.database import Base
  9. class RechargeRecordHis(Base):
  10. """
  11. 充值记录历史表
  12. 用于记录 recharge_records 表的变更历史,支持:
  13. - 记录每次充值操作的详细信息
  14. - 追踪充值金额、天数变化
  15. - 安全审计和异常检测
  16. """
  17. __tablename__ = "recharge_records_his"
  18. id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
  19. user_id = Column(Integer, nullable=False, comment="用户ID")
  20. card_id = Column(Integer, nullable=False, comment="卡密ID")
  21. software_code = Column(String(50), nullable=False, comment="软件特征码")
  22. days = Column(Integer, nullable=False, comment="充值天数")
  23. expire_time_before = Column(DateTime, nullable=True, comment="充值前到期时间")
  24. expire_time_after = Column(DateTime, nullable=True, comment="充值后到期时间")
  25. created_at = Column(DateTime, default=beijing_now_naive, comment="创建时间")
  26. # 历史记录字段
  27. action_type = Column(String(20), nullable=False, comment="操作类型: INSERT/UPDATE/DELETE")
  28. changed_fields = Column(Text, nullable=True, comment="变更字段(JSON格式)")
  29. operator = Column(String(100), nullable=True, comment="操作者: system/user_id")
  30. record_id = Column(Integer, nullable=False, comment="原始记录ID")
  31. created_at_his = Column(DateTime, default=beijing_now_naive, comment="历史记录创建时间")
  32. def __repr__(self):
  33. return f"<RechargeRecordHis(id={self.id}, user_id={self.user_id}, action_type='{self.action_type}', created_at={self.created_at})>"