c6eba97b43
后端: - 简化积分服务: 删除 freeze/settle/refund, 保留 consume/recharge/expire - 计费配置化: config/points-config.yaml 驱动 fixed/duration/free 三种模式 - TTS 时长探测: app/utils/audio_utils.py (httpx + mutagen 纯 Python) - Python 层扣费: script(5)/polish(1)/title(1)/voice_clone(200)/tts(按秒)/video(按秒) - 字幕 free_services: caption/auto_align 不扣费 - 新增 POST /points/consume 端点(402余额预检) - 新增 check_balance + /points/cost 返回 sufficient/balance/required - 新增 expire_batches 定时回收, 接入 scheduler main(每5分钟) - 删除废弃 tts_handler.py - Alembic 迁移: 删除 frozen/total_refunded 字段 - 同步 requirements.lock 添加 mutagen 前端: - Rust/IPC 层扣费: compose(5)/subtitle_burn(2)/cover_design(2) - 字幕打轴改异步: 走 scheduler subtitle handler - 对口型传 duration: VideoGeneration 传 actualDuration - 创建 pointStore: 全局余额 + fetchBalance + 充值弹窗控制 - 402 欠费弹 RechargeModal: VideoGeneration/SubtitleBurning/CoverDesign - 修复 VoiceDubbing.tsx 类型错误 (alignResult never) - 同步 PointBalance 类型(删除 frozen/available/totalRefunded) Refs: 积分消耗集成收尾
56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
"""
|
|
用户积分汇总表
|
|
==============
|
|
|
|
记录用户当前可用积分及累计统计。
|
|
|
|
设计说明:
|
|
- 余额是实时计算的聚合值,查询时不需要 JOIN batches
|
|
- 每次充值/消费/过期都同步更新此表
|
|
- SELECT ... FOR UPDATE 锁定此表行,防止并发超扣
|
|
"""
|
|
|
|
import uuid
|
|
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.models.base import BaseModelBigInt
|
|
|
|
|
|
class UserPoint(BaseModelBigInt):
|
|
"""用户积分汇总"""
|
|
|
|
__tablename__ = "mjk_user_points"
|
|
|
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
unique=True,
|
|
nullable=False,
|
|
comment="用户 ID",
|
|
)
|
|
|
|
balance: Mapped[int] = mapped_column(
|
|
default=0,
|
|
nullable=False,
|
|
comment="当前积分余额(允许欠费为负)",
|
|
)
|
|
|
|
total_recharged: Mapped[int] = mapped_column(
|
|
default=0,
|
|
nullable=False,
|
|
comment="累计充值积分",
|
|
)
|
|
|
|
total_consumed: Mapped[int] = mapped_column(
|
|
default=0,
|
|
nullable=False,
|
|
comment="累计消费积分",
|
|
)
|
|
|
|
total_expired: Mapped[int] = mapped_column(
|
|
default=0,
|
|
nullable=False,
|
|
comment="累计过期积分",
|
|
)
|