diff --git a/backend/apps/generation/views.py b/backend/apps/generation/views.py index 640ef39..a421a5f 100644 --- a/backend/apps/generation/views.py +++ b/backend/apps/generation/views.py @@ -204,14 +204,18 @@ def video_generate_view(request): # Layer 2.5: 用户总消费额度 (skip if -1) from decimal import Decimal if user.spending_limit != Decimal('-1'): - total_spent = GenerationRecord.objects.filter( - user=user, - status__in=['completed', 'processing', 'queued'], + # 已完成的用 cost_amount,处理中/排队的用 frozen_amount(预估费用) + completed_cost = GenerationRecord.objects.filter( + user=user, status='completed', ).aggregate(total=Sum('cost_amount'))['total'] or Decimal('0') + pending_cost = GenerationRecord.objects.filter( + user=user, status__in=['processing', 'queued'], + ).aggregate(total=Sum('frozen_amount'))['total'] or Decimal('0') + total_spent = completed_cost + pending_cost if total_spent + estimated_cost > user.spending_limit: return Response({ 'error': 'spending_limit_exceeded', - 'message': f'您的总消费已达上限(¥{user.spending_limit}),请联系管理员', + 'message': f'余额不足,总额度 ¥{user.spending_limit},已消费 ¥{total_spent:.2f},剩余 ¥{(user.spending_limit - total_spent):.2f},本次预估 ¥{estimated_cost:.2f}', 'spending_limit': float(user.spending_limit), 'total_spent': float(total_spent), }, status=status.HTTP_429_TOO_MANY_REQUESTS) diff --git a/web/src/components/PromptInput.tsx b/web/src/components/PromptInput.tsx index e41cac9..3006140 100644 --- a/web/src/components/PromptInput.tsx +++ b/web/src/components/PromptInput.tsx @@ -616,13 +616,15 @@ export function PromptInput() {