42 lines
1.9 KiB
Python
42 lines
1.9 KiB
Python
"""萤火虫时刻模型"""
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import String, Integer, Boolean, DateTime, ForeignKey, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class FlashEvent(Base):
|
|
"""全服随机萤火虫事件"""
|
|
__tablename__ = "flash_events"
|
|
|
|
id: Mapped[str] = mapped_column(String(36), primary_key=True)
|
|
type: Mapped[str] = mapped_column(String(20), default="firefly") # firefly / meteor
|
|
start_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
end_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
target_clicks: Mapped[int] = mapped_column(Integer, default=100) # 全服目标点击数
|
|
total_clicks: Mapped[int] = mapped_column(Integer, default=0)
|
|
reached: Mapped[bool] = mapped_column(Boolean, default=False)
|
|
leaf_seed: Mapped[str] = mapped_column(String(16), nullable=False) # 限定纪念叶种子
|
|
leaf_variant: Mapped[str] = mapped_column(String(40), nullable=False) # 永不复刻的变体标识
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.utcnow())
|
|
|
|
|
|
class FlashParticipation(Base):
|
|
"""用户参与记录(集气点击 + 获得的叶子)"""
|
|
__tablename__ = "flash_participations"
|
|
__table_args__ = (
|
|
UniqueConstraint("event_id", "user_id", name="uq_flash_participation"),
|
|
)
|
|
|
|
id: Mapped[str] = mapped_column(String(36), primary_key=True)
|
|
event_id: Mapped[str] = mapped_column(String(36), ForeignKey("flash_events.id", ondelete="CASCADE"))
|
|
user_id: Mapped[str] = mapped_column(String(36), ForeignKey("users.id", ondelete="CASCADE"))
|
|
clicks: Mapped[int] = mapped_column(Integer, default=0)
|
|
earned: Mapped[bool] = mapped_column(Boolean, default=False) # 是否达标获得限定叶
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.utcnow())
|
|
|
|
user = relationship("User", foreign_keys=[user_id])
|