"""看激励视频发奖记录(穿山甲 S2S 回调)。 每条 = 穿山甲一次发奖回调。`trans_id`(穿山甲交易号)唯一,做幂等键:穿山甲会重试回调, 同号只发一次金币。`reward_date`(北京时间日期串)给"每日上限"计数用——按日期串等值查, 不在 SQL 里做跨时区 date 比较(SQLite 上不可靠)。审计 / 对账时整张表可逐笔回溯。 """ from __future__ import annotations from datetime import datetime from sqlalchemy import DateTime, ForeignKey, Integer, String, func from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base class AdRewardRecord(Base): __tablename__ = "ad_reward_record" id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) # 穿山甲交易号,幂等键(同号回调不重复发奖) trans_id: Mapped[str] = mapped_column(String(64), unique=True, index=True, nullable=False) user_id: Mapped[int] = mapped_column( Integer, ForeignKey("user.id"), index=True, nullable=False ) # 实发金币(capped 时为 0) coin: Mapped[int] = mapped_column(Integer, nullable=False, default=0) # granted(已发) / capped(当日超限未发) status: Mapped[str] = mapped_column(String(16), nullable=False, default="granted") # 北京时间日期串 'YYYY-MM-DD',按它等值统计当日发奖次数 reward_date: Mapped[str] = mapped_column(String(10), index=True, nullable=False) # 穿山甲上报的奖励名(参考,不作发奖依据) reward_name: Mapped[str | None] = mapped_column(String(64), nullable=True) # 回调原始参数,审计排查用 raw: Mapped[str | None] = mapped_column(String(1024), nullable=True) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), index=True, nullable=False ) def __repr__(self) -> str: # pragma: no cover return f""