|
@@ -17,7 +17,7 @@ from django.core.paginator import Paginator
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
from AgentModel.models import AgentCustomerInfo, AgentCustomerCard, AgentCustomerPackage, AgentCloudServicePackage, \
|
|
|
- AgentDeviceOrder, AgentAccountWithdraw, AgentDevice
|
|
|
+ AgentDeviceOrder, AgentAccountWithdraw, AgentDevice, AgentAccount
|
|
|
from Model.models import UnicomCombo, Store_Meal, Device_User
|
|
|
|
|
|
from Object.ResponseObject import ResponseObject
|
|
@@ -606,9 +606,12 @@ class AgentCustomerView(View):
|
|
|
frozen_amount_qs = AgentAccountWithdraw.objects.filter(ac_id=ac_id)
|
|
|
frozen_amount = frozen_amount_qs.aggregate(total=Sum('amount'))['total'] or Decimal('0.00')
|
|
|
|
|
|
- # 计算总余额:已结算且未删除的订单的利润总和
|
|
|
- total_profit_qs = AgentDeviceOrder.objects.filter(ac_id=ac_id, status=2, is_del=False)
|
|
|
- total_profit = total_profit_qs.aggregate(total=Sum('profit'))['total'] or Decimal('0.00')
|
|
|
+ # 计算余额:已结算 - (退款+已打款)
|
|
|
+ incomes_qs = AgentAccount.objects.filter(ac_id=ac_id, status=1)
|
|
|
+ expense_qs = AgentAccount.objects.filter(ac_id=ac_id, status__in=[2,3])
|
|
|
+ incomes_all = incomes_qs.aggregate(total=Sum('amount'))['total'] or Decimal('0.00')
|
|
|
+ expense_all = expense_qs.aggregate(total=Sum('amount'))['total'] or Decimal('0.00')
|
|
|
+ total_profit = incomes_all - expense_all
|
|
|
|
|
|
# 可用余额 = 总余额 - 冻结金额
|
|
|
available_balance = total_profit - frozen_amount
|