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>
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""签到记录表。
|
|
|
|
每次签到一行,(user_id, signin_date) 唯一,天然防一天签两次。
|
|
|
|
2026-07 下线 `signin_boost_record`(签到膨胀):膨胀按固定 3000 金币补发、与广告实际收益
|
|
脱钩,产品确认非设计内口径。签到弹窗的「看广告膨胀」改走 reward_video(按 eCPM 发,记在
|
|
`ad_reward_record`)。历史发币流水 `coin_transaction.biz_type='signin_boost'` 保留不动。
|
|
- cycle_day: 1..7,7 天循环里今天落在第几档,决定发多少金币;断签后重置回 1
|
|
(周期长度 = rewards.SIGNIN_CYCLE_LEN,2026-06 由 14 天改 7 天一轮)。
|
|
- streak: 连续签到天数(不封顶),用于"已连续签到 N 天"展示;断签后重置回 1。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import date, datetime
|
|
|
|
from sqlalchemy import Date, DateTime, ForeignKey, Integer, 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}>"
|
|
)
|
|
|
|
|