59 lines
2.4 KiB
Python
59 lines
2.4 KiB
Python
|
|
"""
|
||
|
|
游戏相关模型
|
||
|
|
"""
|
||
|
|
from sqlalchemy import Column, Integer, String, BigInteger, Enum, DateTime, Text, ForeignKey, func
|
||
|
|
from sqlalchemy.dialects.mysql import TINYINT
|
||
|
|
from sqlalchemy.orm import relationship
|
||
|
|
from enum import Enum as PyEnum
|
||
|
|
|
||
|
|
from .base import Base
|
||
|
|
|
||
|
|
|
||
|
|
class ChestStatus(PyEnum):
|
||
|
|
"""宝箱状态"""
|
||
|
|
BETTING = 0 # 可下注
|
||
|
|
LOCKED = 1 # 已封盘
|
||
|
|
SETTLING = 2 # 结算中
|
||
|
|
FINISHED = 3 # 已完成
|
||
|
|
REFUNDED = 4 # 已退款
|
||
|
|
|
||
|
|
|
||
|
|
class Chest(Base):
|
||
|
|
"""宝箱表"""
|
||
|
|
__tablename__ = "chests"
|
||
|
|
|
||
|
|
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
|
||
|
|
streamer_id = Column(Integer, nullable=False, index=True, comment="主播ID")
|
||
|
|
title = Column(String(200), nullable=False, comment="宝箱标题")
|
||
|
|
option_a = Column(String(100), nullable=False, comment="选项A")
|
||
|
|
option_b = Column(String(100), nullable=False, comment="选项B")
|
||
|
|
status = Column(Enum(ChestStatus, native_enum=False), default=ChestStatus.BETTING, nullable=False, comment="宝箱状态")
|
||
|
|
pool_a = Column(BigInteger, default=0, comment="A边奖池(分)")
|
||
|
|
pool_b = Column(BigInteger, default=0, comment="B边奖池(分)")
|
||
|
|
total_bets = Column(Integer, default=0, comment="总下注次数")
|
||
|
|
countdown_seconds = Column(Integer, default=300, comment="倒计时(秒)")
|
||
|
|
locked_at = Column(DateTime, comment="封盘时间")
|
||
|
|
settled_at = Column(DateTime, comment="结算时间")
|
||
|
|
result = Column(String(10), comment="结算结果")
|
||
|
|
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||
|
|
|
||
|
|
# 关联关系
|
||
|
|
bets = relationship("Bet", back_populates="chest", foreign_keys="Bet.chest_id")
|
||
|
|
|
||
|
|
|
||
|
|
class Bet(Base):
|
||
|
|
"""下注表"""
|
||
|
|
__tablename__ = "bets"
|
||
|
|
|
||
|
|
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
|
||
|
|
user_id = Column(Integer, nullable=False, index=True, comment="用户ID")
|
||
|
|
chest_id = Column(Integer, ForeignKey("chests.id"), nullable=False, index=True, comment="宝箱ID")
|
||
|
|
option = Column(String(1), nullable=False, comment="下注选项")
|
||
|
|
amount = Column(BigInteger, nullable=False, comment="下注金额(分)")
|
||
|
|
payout = Column(BigInteger, default=0, comment="获奖金额(分)")
|
||
|
|
status = Column(String(20), default="PENDING", comment="状态")
|
||
|
|
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||
|
|
|
||
|
|
# 关联关系
|
||
|
|
chest = relationship("Chest", back_populates="bets", foreign_keys=[chest_id])
|