diff --git a/video-gen-api/app/schemas/admin.py b/video-gen-api/app/schemas/admin.py index 95e58d1a..cdfcd3df 100644 --- a/video-gen-api/app/schemas/admin.py +++ b/video-gen-api/app/schemas/admin.py @@ -162,6 +162,9 @@ class AdminCreditRecordSummaryOut(BaseModel): total_recharge: float = 0.0 total_consume: float = 0.0 total_refund: float = 0.0 + # 净消耗 = 真实消费(预扣释放不算)- 退款,这才是真正的"消耗了多少积分"口径 + # 前端展示"总消耗积分"时应使用此字段,而不是 total_consume(含未退回的) + net_consume: float = 0.0 transaction_count: int = 0 generation_count: int = 0 generation_attempt_count: int = 0 diff --git a/video-gen-api/app/services/admin_credit_record_service.py b/video-gen-api/app/services/admin_credit_record_service.py index 1cbc7790..ee5f400e 100644 --- a/video-gen-api/app/services/admin_credit_record_service.py +++ b/video-gen-api/app/services/admin_credit_record_service.py @@ -320,10 +320,16 @@ async def list_admin_credit_records( if where_clause is not None: summary_query = summary_query.where(where_clause) s = (await db.execute(summary_query)).one() + _total_recharge = _round2(s[0]) + _total_consume = _round2(s[1]) + _total_refund = _round2(s[2]) + # 净消耗 = 真实消费 - 退款;如果退款超过消费(连续退了跨周期的),下限为 0 避免负数 + _net_consume = _round2(max(_total_consume - _total_refund, 0.0)) summary = { - "total_recharge": _round2(s[0]), - "total_consume": _round2(s[1]), - "total_refund": _round2(s[2]), + "total_recharge": _total_recharge, + "total_consume": _total_consume, + "total_refund": _total_refund, + "net_consume": _net_consume, "transaction_count": int(s[3] or 0), "generation_count": int(s[4] or 0), "generation_attempt_count": int(s[5] or 0), diff --git a/video-gen-app/src/pages/TeamManagementPage.tsx b/video-gen-app/src/pages/TeamManagementPage.tsx index 6d8538cb..b350cf93 100644 --- a/video-gen-app/src/pages/TeamManagementPage.tsx +++ b/video-gen-app/src/pages/TeamManagementPage.tsx @@ -540,9 +540,33 @@ const TeamManagementPage: React.FC = () => { } onClick={handleExportCredits}>导出 Excel - {/* 汇总统计 */} -