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