Files
shaguabijia-app-server/app/models/guide_video.py
T
zuochenyong ebacf01742 feat(新手引导): 支持十圈进度与逐圈发奖 (#200)
Co-authored-by: exinglang <exinglang@qq.com>
Reviewed-on: #200
Co-authored-by: zuochenyong <zuochenyong@wonderable.ai>
Co-committed-by: zuochenyong <zuochenyong@wonderable.ai>
2026-07-30 10:49:24 +08:00

58 lines
2.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""引导视频待播放计划、起播快照与逐圈结算状态。"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, UniqueConstraint, func
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base
class GuideVideoPlay(Base):
__tablename__ = "guide_video_play"
__table_args__ = (
UniqueConstraint("play_token", name="uq_guide_video_play_token"),
Index(
"uq_guide_video_play_user_scene_seq",
"user_id",
"scene",
"seq",
unique=True,
),
)
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
)
play_token: Mapped[str] = mapped_column(String(64), nullable=False)
scene: Mapped[str] = mapped_column(String(16), nullable=False, default="coupon")
# prepare 不占次数,seq=NULLstart 成功才写入 1-based seq。
seq: Mapped[int | None] = mapped_column(Integer, nullable=True)
video_url: Mapped[str | None] = mapped_column(String(512), nullable=True)
coin: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
duration_ms: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
config_version: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
settled_circles: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
# prepared / started / completed / legacy_completed / legacy_closed
status: Mapped[str] = mapped_column(String(24), nullable=False, default="prepared")
completed: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
prepared_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), server_default=func.now(), nullable=False
)
expires_at: Mapped[datetime | None] = mapped_column(
DateTime(timezone=True), index=True, nullable=True
)
started_at: Mapped[datetime | None] = mapped_column(
DateTime(timezone=True), index=True, nullable=True
)
granted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
def __repr__(self) -> str: # pragma: no cover
return (
f"<GuideVideoPlay user={self.user_id} scene={self.scene} seq={self.seq} "
f"{self.status} circles={self.settled_circles}>"
)