Files
meijiaka-zy/python-api/app/models/point_transaction.py
T
小鱼开发 0722225c62 feat(points): 积分流水表支持时长显示,说明字段简化
后端:
- PointTransaction 模型添加 duration 字段(float, nullable)
- PointTransactionItem schema 添加 duration
- consume() 新增 duration 参数,写入流水记录
- 各业务 description 统一简化为【脚本生成】【配音合成】等格式
- duration 类业务(tts/video)传入实际秒数
- Alembic 迁移: 95eb1a1c0af9_add_duration_to_point_transaction

前端:
- PointTransaction 类型添加 duration
- UsageDetail: 来源列 → 时长列(有值显示 xs,无值显示 -)
- 说明列直接显示后端返回的简化描述
2026-05-09 17:08:50 +08:00

86 lines
2.0 KiB
Python

"""
积分流水表
==========
记录每一笔积分变动,用于审计和对账。
变动类型:
- recharge:充值
- consume:消费(AI 调用)
- expire:过期
- refund:返还(预扣后失败或实际少于预估)
"""
import uuid
from sqlalchemy import BigInteger, String, Text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import BaseModelBigInt
class PointTransaction(BaseModelBigInt):
"""积分流水"""
__tablename__ = "mjk_point_transactions"
user_id: Mapped[uuid.UUID] = mapped_column(
UUID(as_uuid=True),
nullable=False,
comment="用户 ID",
)
type: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment="变动类型:recharge / consume / expire / refund",
)
amount: Mapped[int] = mapped_column(
default=0,
nullable=False,
comment="变动数量(正数)",
)
balance_before: Mapped[int] = mapped_column(
default=0,
nullable=False,
comment="变动前总余额",
)
balance_after: Mapped[int] = mapped_column(
default=0,
nullable=False,
comment="变动后总余额",
)
source_type: Mapped[str | None] = mapped_column(
String(32),
nullable=True,
comment="消费来源类型:script / polish / voice_clone / tts / video",
)
source_id: Mapped[str | None] = mapped_column(
String(64),
nullable=True,
comment="关联的任务 ID 或订单 ID",
)
batch_id: Mapped[int | None] = mapped_column(
BigInteger,
nullable=True,
comment="关联的积分批次 ID(消费时记录从哪个批次扣)",
)
duration: Mapped[float | None] = mapped_column(
nullable=True,
comment="时长(秒),按秒计费业务记录",
)
description: Mapped[str | None] = mapped_column(
Text,
nullable=True,
comment="描述",
)