356d6e52b9
签到加成(boost): - 新增 signin_boost_record 表(user+date 唯一)+ POST /api/v1/signin/boost - signin 状态/结算逻辑调整 信息流广告结算: - 新增 ad_feed_reward_record 表(client_event_id 幂等)+ POST /api/v1/ad/feed-reward - ad_feed_reward 模型/repo、ad schema、按 ecpm/时长结算金币 金币数值:core/rewards.py 数值调整、config_schema/admin config 适配 迁移 coin_reward_phase1(down_revision pstat3growth);测试 + API/DB 文档同步 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
"""签到记录表。
|
|
|
|
每次签到一行,(user_id, signin_date) 唯一,天然防一天签两次。
|
|
- cycle_day: 1..14,14 天循环里今天落在第几档,决定发多少金币;断签后重置回 1。
|
|
- streak: 连续签到天数(不封顶),用于"已连续签到 N 天"展示;断签后重置回 1。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date, datetime
|
|
|
|
from sqlalchemy import Date, DateTime, ForeignKey, Integer, String, UniqueConstraint, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class SigninRecord(Base):
|
|
__tablename__ = "signin_record"
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "signin_date", name="uq_signin_user_date"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("user.id"), index=True, nullable=False
|
|
)
|
|
# 签到日期(北京时间的 date)
|
|
signin_date: Mapped[date] = mapped_column(Date, nullable=False)
|
|
cycle_day: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
streak: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
coin_awarded: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False
|
|
)
|
|
|
|
def __repr__(self) -> str: # pragma: no cover
|
|
return (
|
|
f"<SigninRecord user_id={self.user_id} date={self.signin_date} "
|
|
f"day={self.cycle_day} streak={self.streak}>"
|
|
)
|
|
|
|
|
|
class SigninBoostRecord(Base):
|
|
"""签到后看广告膨胀记录。
|
|
|
|
一天最多膨胀一次,补发金额等于当天签到原始奖励。独立表用于防并发重复补发,
|
|
后续接入真实 S2S 广告 session 时可把 ad_ref_id 回填为广告会话/交易号。
|
|
"""
|
|
|
|
__tablename__ = "signin_boost_record"
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "signin_date", name="uq_signin_boost_user_date"),
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
|
user_id: Mapped[int] = mapped_column(
|
|
Integer, ForeignKey("user.id"), index=True, nullable=False
|
|
)
|
|
signin_date: Mapped[date] = mapped_column(Date, nullable=False)
|
|
coin_awarded: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
ad_ref_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False
|
|
)
|
|
|
|
def __repr__(self) -> str: # pragma: no cover
|
|
return f"<SigninBoostRecord user_id={self.user_id} date={self.signin_date} coin={self.coin_awarded}>"
|