"""信息流广告奖励记录。 点位 2:比价等待 / 领券信息流广告。每展示满 10 秒累计一份奖励,视频完成后一次性入账。 """ from __future__ import annotations from datetime import datetime from sqlalchemy import DateTime, ForeignKey, Integer, String, UniqueConstraint, func from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base class AdFeedRewardRecord(Base): __tablename__ = "ad_feed_reward_record" __table_args__ = ( UniqueConstraint("client_event_id", name="uq_ad_feed_reward_client_event"), ) id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True) client_event_id: Mapped[str] = mapped_column(String(64), nullable=False) ad_session_id: Mapped[str | None] = mapped_column(String(64), index=True, nullable=True) user_id: Mapped[int] = mapped_column( Integer, ForeignKey("user.id"), index=True, nullable=False ) reward_date: Mapped[str] = mapped_column(String(10), index=True, nullable=False) duration_seconds: Mapped[int] = mapped_column(Integer, nullable=False, default=0) unit_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0) ecpm_raw: Mapped[str] = mapped_column(String(32), nullable=False) adn: Mapped[str | None] = mapped_column(String(32), nullable=True) slot_id: Mapped[str | None] = mapped_column(String(64), nullable=True) # 广告类型:feed(信息流) / draw(Draw 信息流)。比价与领券共用同一 Draw 代码位,靠 feed_scene # 区分收益;ad_type 区分广告形态。旧数据(未升级客户端)为 NULL,一律视为 feed,保持向后兼容。 ad_type: Mapped[str | None] = mapped_column(String(16), nullable=True, default="feed") # 点位场景:comparison(比价等待) / coupon(领券) / welfare(福利页)。比价与领券共用同一信息流 # 代码位,slot_id/our_code_id 分不出,只能客户端各调用点显式打标;NULL=历史/未升级客户端=未分类。 feed_scene: Mapped[str | None] = mapped_column(String(16), nullable=True) # 本次比价 trace_id(仅 comparison 场景由客户端带上):把这场广告金币归属到对应比价记录, # 比价记录页按 trace_id 聚合本场实发金币显示「比价赚 N 金币」。领券/福利/旧客户端 = NULL。 trace_id: Mapped[str | None] = mapped_column(String(64), index=True, nullable=True) # 来源(广告收益报表用):我们的应用环境 prod/test + 我们配置的代码位 104xxx,由客户端 feed-reward 上报带上。旧数据为 NULL。 app_env: Mapped[str | None] = mapped_column(String(16), nullable=True) our_code_id: Mapped[str | None] = mapped_column(String(64), nullable=True) coin: Mapped[int] = mapped_column(Integer, nullable=False, default=0) status: Mapped[str] = mapped_column(String(16), nullable=False, default="granted") 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"" )