73970087ff
Co-authored-by: guke <guke@wonderable.ai> Co-authored-by: 左辰勇 <exinglang@gmail.com> Reviewed-on: #154 Co-authored-by: zuochenyong <zuochenyong@wonderable.ai> Co-committed-by: zuochenyong <zuochenyong@wonderable.ai>
64 lines
3.6 KiB
Python
64 lines
3.6 KiB
Python
"""看激励视频发奖记录(穿山甲 S2S 回调)。
|
|
|
|
每条 = 穿山甲/GroMore 一次服务端激励回调。`trans_id`(交易号)唯一,做幂等键:
|
|
穿山甲会重试回调,同号只处理一次。`reward_scene` 区分福利页激励视频、签到膨胀等
|
|
不同奖励场景,避免统计和每日上限互相污染。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class AdRewardRecord(Base):
|
|
__tablename__ = "ad_reward_record"
|
|
__table_args__ = (
|
|
# 「本轮膨胀累计发了多少」= SUM(coin) WHERE user_id=? AND boost_round_id=? AND status='granted'
|
|
Index("ix_ad_reward_user_boost_round", "user_id", "boost_round_id"),
|
|
)
|
|
|
|
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(当日超限未发) / ecpm_missing(缺 eCPM 未发)
|
|
status: Mapped[str] = mapped_column(String(16), nullable=False, default="granted")
|
|
# reward_video(福利页看视频) / signin_boost(签到膨胀)
|
|
reward_scene: Mapped[str] = mapped_column(String(32), nullable=False, default="reward_video")
|
|
# 客户端生成并通过 extra 透传的广告会话 id
|
|
ad_session_id: Mapped[str | None] = mapped_column(String(64), index=True, nullable=True)
|
|
# 客户端生成并通过 extra 透传的「膨胀轮」id:一轮 = 用户点「去膨胀」到点「放弃赚钱」之间连看的
|
|
# 若干条广告。纯标签,不影响发多少/发不发,只用于把同一轮的发奖记录求和成弹窗要显示的累计值。
|
|
# 轮次边界完全由客户端定(它才知道用户点了放弃);老客户端/extra 丢失时为 NULL → 累计值返 null。
|
|
boost_round_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
# 本次发奖采用的 eCPM 原始值(回调自带或按 ad_session_id 匹配的客户端上报)
|
|
ecpm_raw: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
|
# 来源(广告收益报表用):我们的应用环境 prod/test + 我们配置的代码位 104xxx。
|
|
# S2S 回调本身不带这俩,发奖时按 ad_session_id 匹配 ad_ecpm_record 回填(查不到为 NULL)。
|
|
app_env: Mapped[str | None] = mapped_column(String(16), nullable=True)
|
|
our_code_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
# 北京时间日期串 '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"<AdRewardRecord trans_id={self.trans_id} user_id={self.user_id} "
|
|
f"scene={self.reward_scene} {self.status} coin={self.coin}>"
|
|
)
|