|
@@ -95,6 +95,8 @@ class AgentCustomerView(View):
|
|
|
return self.get_check_balance(userID, response)
|
|
|
elif operation == 'getDataStatistics':
|
|
|
return self.get_data_statistics(userID, response)
|
|
|
+ elif operation == 'agentApplyWithdraw':
|
|
|
+ return self.agent_apply_withdraw(userID, request_dict, response)
|
|
|
else:
|
|
|
return response.json(444, 'operation')
|
|
|
|
|
@@ -711,3 +713,53 @@ class AgentCustomerView(View):
|
|
|
})
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ def agent_apply_withdraw(self, userID, request_dict, response):
|
|
|
+ """
|
|
|
+ 用户提现申请
|
|
|
+ @param userID: userID
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @param request_dict amount: 金额
|
|
|
+ @param response: 响应对象
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ amount = Decimal(request_dict.get('amount', '0.00'))
|
|
|
+
|
|
|
+ if amount == Decimal('0.00'):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ agent_customer_info = AgentCustomerInfo.objects.filter(user_id=userID).first()
|
|
|
+ if not agent_customer_info:
|
|
|
+ return response.json(104, 'Agent customer not found')
|
|
|
+
|
|
|
+ ac_id = agent_customer_info.id
|
|
|
+ try:
|
|
|
+ # 计算余额:已结算 - (退款+已打款)
|
|
|
+ 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
|
|
|
+
|
|
|
+ # 冻结余额
|
|
|
+ frozen_amount_qs = AgentAccountWithdraw.objects.filter(ac_id=ac_id)
|
|
|
+ frozen_amount = frozen_amount_qs.aggregate(total=Sum('amount'))['total'] or Decimal('0.00')
|
|
|
+
|
|
|
+ # 可提现余额 = 总余额 - 冻结金额
|
|
|
+ available_balance = total_profit - frozen_amount
|
|
|
+
|
|
|
+ if amount < available_balance:
|
|
|
+ return response.json(173, '余额不足,无法提现')
|
|
|
+
|
|
|
+ # 提交提现申请
|
|
|
+ acc = AgentCustomerCard.objects.filter(ac_id=ac_id).first()
|
|
|
+ AgentAccountWithdraw.objects.create(ac_id=ac_id, status=1, card_id=acc.id, amount=amount,
|
|
|
+ created_time=int(time.time()), updated_time=int(time.time()))
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+
|
|
|
+
|