0722225c62
后端: - PointTransaction 模型添加 duration 字段(float, nullable) - PointTransactionItem schema 添加 duration - consume() 新增 duration 参数,写入流水记录 - 各业务 description 统一简化为【脚本生成】【配音合成】等格式 - duration 类业务(tts/video)传入实际秒数 - Alembic 迁移: 95eb1a1c0af9_add_duration_to_point_transaction 前端: - PointTransaction 类型添加 duration - UsageDetail: 来源列 → 时长列(有值显示 xs,无值显示 -) - 说明列直接显示后端返回的简化描述
111 lines
3.6 KiB
Python
111 lines
3.6 KiB
Python
"""
|
|
积分系统 Schema
|
|
===============
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
# ── 余额查询 ──────────────────────────────────────────
|
|
|
|
class PointBalanceResponse(BaseModel):
|
|
"""积分余额响应"""
|
|
|
|
balance: int = Field(description="当前积分余额(允许欠费为负)")
|
|
total_recharged: int = Field(description="累计充值")
|
|
total_consumed: int = Field(description="累计消费")
|
|
total_expired: int = Field(description="累计过期")
|
|
|
|
|
|
# ── 流水记录 ──────────────────────────────────────────
|
|
|
|
class PointTransactionItem(BaseModel):
|
|
"""单条流水记录"""
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
type: str = Field(description="recharge / consume / expire / refund")
|
|
amount: int
|
|
balance_before: int
|
|
balance_after: int
|
|
source_type: str | None = Field(None, description="消费来源类型")
|
|
source_id: str | None = Field(None, description="消费来源业务 ID")
|
|
duration: float | None = Field(None, description="时长(秒),按秒计费业务记录")
|
|
description: str | None = None
|
|
created_at: datetime
|
|
|
|
|
|
class PointTransactionListResponse(BaseModel):
|
|
"""流水列表响应"""
|
|
|
|
items: list[PointTransactionItem]
|
|
total: int
|
|
skip: int
|
|
limit: int
|
|
|
|
|
|
# ── 充值 ──────────────────────────────────────────────
|
|
|
|
class RechargeRequest(BaseModel):
|
|
"""充值请求"""
|
|
|
|
points: int = Field(gt=0, description="充值积分数量")
|
|
amount_rmb: int = Field(gt=0, description="支付金额(分)")
|
|
|
|
|
|
class RechargeResponse(BaseModel):
|
|
"""充值响应(微信支付预下单 - Native 扫码)"""
|
|
|
|
order_id: int
|
|
points: int
|
|
amount_rmb: int
|
|
# Native 支付二维码链接,前端用此生成二维码供用户微信扫描
|
|
code_url: str | None = None
|
|
|
|
|
|
# ── 积分预估 ──────────────────────────────────────────
|
|
|
|
class CostEstimateResponse(BaseModel):
|
|
"""积分预估响应"""
|
|
|
|
source_type: str
|
|
estimated_points: int = Field(description="预估上限积分(执行业务前检查用)")
|
|
actual_points: int = Field(description="按传入参数计算的实际积分")
|
|
|
|
|
|
# ── 充值订单 ──────────────────────────────────────────
|
|
|
|
class RechargeOrderItem(BaseModel):
|
|
"""充值订单记录"""
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
points: int
|
|
amount_rmb: int
|
|
status: str
|
|
created_at: datetime
|
|
paid_at: datetime | None = None
|
|
|
|
|
|
class RechargeOrderListResponse(BaseModel):
|
|
"""充值订单列表"""
|
|
|
|
items: list[RechargeOrderItem]
|
|
total: int
|
|
skip: int
|
|
limit: int
|
|
|
|
|
|
# ── 消费扣费 ──────────────────────────────────────────
|
|
|
|
class ConsumeRequest(BaseModel):
|
|
"""消费扣费请求(供前端/Rust 层调用)"""
|
|
|
|
points: int = Field(gt=0, description="消耗积分数量")
|
|
source_type: str = Field(description="消费来源类型,如 compose / subtitle_burn / cover_design")
|
|
source_id: str = Field(description="消费来源业务 ID")
|
|
description: str | None = Field(default=None, description="消费描述")
|