|
@@ -89,14 +89,20 @@ class AgentCustomerView(View):
|
|
|
|
|
|
elif operation == 'getAgentSettleOrders':
|
|
|
return self.get_agent_settle_order(userID, request_dict, response)
|
|
|
+ elif operation == 'getDataStatistics':
|
|
|
+ return self.get_data_statistics(userID, response)
|
|
|
+
|
|
|
+ # 代理商提现功能
|
|
|
elif operation == 'getAgentAccountWithdraw':
|
|
|
return self.get_agent_account_withdraw(userID, request_dict, response)
|
|
|
elif operation == 'getCheckBalance':
|
|
|
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)
|
|
|
+ elif operation == 'getWithdrawalReview':
|
|
|
+ return self.get_withdrawal_review(request_dict, response)
|
|
|
+ elif operation == 'updateWithdrawalReview':
|
|
|
+ return self.update_withdrawal_review(userID, request_dict, response)
|
|
|
else:
|
|
|
return response.json(444, 'operation')
|
|
|
|
|
@@ -107,8 +113,8 @@ class AgentCustomerView(View):
|
|
|
@return:
|
|
|
"""
|
|
|
try:
|
|
|
- # 云存储套餐查询,只包括is_show=1的记录
|
|
|
- store_meals = Store_Meal.objects.filter(is_show=1).values('id', 'bucket__bucket').distinct()
|
|
|
+ # 云存储套餐查询,只包括is_show=0的记录
|
|
|
+ store_meals = Store_Meal.objects.filter(is_show=0).values('id', 'bucket__bucket').distinct()
|
|
|
|
|
|
# 联通套餐查询,只包括is_show=1且未被删除的记录
|
|
|
unicom_combos = UnicomCombo.objects.filter(is_show=1, is_del=False).values('id', 'combo_name').distinct()
|
|
@@ -192,18 +198,36 @@ class AgentCustomerView(View):
|
|
|
# 获取请求页的数据
|
|
|
packages_page = paginator.page(page)
|
|
|
# 准备响应数据,转换查询集为列表形式
|
|
|
- packages_list = list(packages_page.object_list.values(
|
|
|
- 'id', 'service_name', 'package_id', 'type',
|
|
|
- 'profit_type', 'cost', 'profit', 'status',
|
|
|
- 'created_time'
|
|
|
- ))
|
|
|
+ agents_list = []
|
|
|
+ for agent_info in packages_page:
|
|
|
+ package_name = agent_info.package_id
|
|
|
+ if agent_info.type == 1:
|
|
|
+ store_meals = Store_Meal.objects.filter(id=agent_info.package_id).values('bucket__bucket').first()
|
|
|
+ if store_meals:
|
|
|
+ package_name = store_meals['bucket__bucket']
|
|
|
+ else:
|
|
|
+ unicom_combos = UnicomCombo.objects.filter(id=agent_info.package_id).first()
|
|
|
+ if unicom_combos:
|
|
|
+ package_name = unicom_combos.combo_name
|
|
|
+ agents = {
|
|
|
+ 'id': agent_info.id,
|
|
|
+ 'service_name': agent_info.service_name,
|
|
|
+ 'package_name': package_name,
|
|
|
+ 'type': agent_info.type,
|
|
|
+ 'profit_type': agent_info.profit_type,
|
|
|
+ 'cost': agent_info.cost,
|
|
|
+ 'profit': agent_info.profit,
|
|
|
+ 'status': agent_info.status,
|
|
|
+ 'created_time': agent_info.created_time
|
|
|
+ }
|
|
|
+ agents_list.append(agents)
|
|
|
# 返回分页数据
|
|
|
return response.json(0, {
|
|
|
'page': page,
|
|
|
'page_size': page_size,
|
|
|
'total': paginator.count,
|
|
|
'num_pages': paginator.num_pages,
|
|
|
- 'list': packages_list
|
|
|
+ 'list': agents_list
|
|
|
})
|
|
|
except Exception as e:
|
|
|
# 出错时返回错误信息
|
|
@@ -234,7 +258,7 @@ class AgentCustomerView(View):
|
|
|
if not all([package_id, service_name]):
|
|
|
return response.json(444)
|
|
|
if package_type == 1:
|
|
|
- query_set = Store_Meal.objects.filter(is_show=1, id=package_id)
|
|
|
+ query_set = Store_Meal.objects.filter(is_show=0, id=package_id)
|
|
|
elif package_type == 2:
|
|
|
query_set = UnicomCombo.objects.filter(is_show=1, is_del=False, id=package_id)
|
|
|
else:
|
|
@@ -330,25 +354,49 @@ class AgentCustomerView(View):
|
|
|
# 接收分页参数
|
|
|
page = int(request_dict.get('page', 1))
|
|
|
page_size = int(request_dict.get('page_size', 10))
|
|
|
+ search_query = request_dict.get('search_query', '')
|
|
|
+ user_id = request_dict.get('user_id', None)
|
|
|
+ phone = request_dict.get('phone', None)
|
|
|
+ userEmail = request_dict.get('userEmail', None)
|
|
|
|
|
|
- # 查询AgentCustomerInfo表以获取代理商基本信息
|
|
|
- agent_infos = AgentCustomerInfo.objects.filter(status=1).values(
|
|
|
- 'id', 'user_id', 'company_name'
|
|
|
- ).order_by('id')
|
|
|
try:
|
|
|
- # 使用Paginator进行分页处理
|
|
|
+ # 基础查询条件
|
|
|
+ agent_infos_query = AgentCustomerInfo.objects.filter(status=1)
|
|
|
+
|
|
|
+ # 精确查询条件
|
|
|
+ if user_id:
|
|
|
+ agent_infos_query = agent_infos_query.filter(user_id=user_id)
|
|
|
+
|
|
|
+ # 获取所有符合条件的AgentCustomerInfo记录
|
|
|
+ agent_infos = agent_infos_query.values('id', 'user_id', 'company_name').order_by('id')
|
|
|
+
|
|
|
+ # 对结果进行分页
|
|
|
paginator = Paginator(agent_infos, page_size)
|
|
|
- # 获取请求页的数据
|
|
|
packages_page = paginator.page(page)
|
|
|
+
|
|
|
# 准备最终的代理商列表
|
|
|
agents_list = []
|
|
|
for agent_info in packages_page:
|
|
|
- # 查询Device_User表获取用户信息
|
|
|
- user_info = Device_User.objects.filter(userID=agent_info['user_id']).values('phone',
|
|
|
- 'userEmail').first()
|
|
|
- # 查询AgentCustomerCard表获取卡信息
|
|
|
- card_info = AgentCustomerCard.objects.filter(ac_id=agent_info['id']).values('name', 'card_no',
|
|
|
- 'card_address').first()
|
|
|
+ # 模糊查询
|
|
|
+ if search_query:
|
|
|
+ card_info_query = AgentCustomerCard.objects.filter(ac_id=agent_info['id'],
|
|
|
+ name__icontains=search_query)
|
|
|
+ if not card_info_query.exists() and search_query not in agent_info['company_name']:
|
|
|
+ continue
|
|
|
+ else:
|
|
|
+ card_info_query = AgentCustomerCard.objects.filter(ac_id=agent_info['id'])
|
|
|
+
|
|
|
+ # 获取卡信息
|
|
|
+ card_info = card_info_query.values('name', 'card_no', 'card_address').first()
|
|
|
+
|
|
|
+ # 获取用户信息,根据需要进行精确查询
|
|
|
+ user_info_query = Device_User.objects.filter(userID=agent_info['user_id'])
|
|
|
+ if phone:
|
|
|
+ user_info_query = user_info_query.filter(phone=phone)
|
|
|
+ if userEmail:
|
|
|
+ user_info_query = user_info_query.filter(userEmail=userEmail)
|
|
|
+
|
|
|
+ user_info = user_info_query.values('phone', 'userEmail').first()
|
|
|
|
|
|
# 组合信息
|
|
|
agent_record = {
|
|
@@ -362,8 +410,15 @@ class AgentCustomerView(View):
|
|
|
'card_address': card_info.get('card_address') if card_info else None,
|
|
|
}
|
|
|
agents_list.append(agent_record)
|
|
|
- return response.json(0, {'page': page, 'page_size': page_size, 'total': paginator.count,
|
|
|
- 'num_pages': paginator.num_pages, 'list': agents_list})
|
|
|
+
|
|
|
+ # 返回分页后的结果
|
|
|
+ return response.json(0, {
|
|
|
+ 'page': page,
|
|
|
+ 'page_size': page_size,
|
|
|
+ 'total': paginator.count,
|
|
|
+ 'num_pages': paginator.num_pages,
|
|
|
+ 'list': agents_list
|
|
|
+ })
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
@@ -471,6 +526,7 @@ class AgentCustomerView(View):
|
|
|
|
|
|
status = request_dict.get('status', None)
|
|
|
time_str = request_dict.get('time', None)
|
|
|
+ package_type = request_dict.get('package_type', None)
|
|
|
startTime = int(request_dict.get('start_time', 1))
|
|
|
endTime = int(request_dict.get('end_time', 0))
|
|
|
|
|
@@ -498,6 +554,9 @@ class AgentCustomerView(View):
|
|
|
if startTime < endTime:
|
|
|
agent_device_orders_qs = agent_device_orders_qs.filter(created_time__gte=startTime,
|
|
|
created_time__lte=endTime)
|
|
|
+ if package_type:
|
|
|
+ csp_ids = list(AgentCloudServicePackage.objects.filter(type=int(package_type)).values_list('id', flat=True))
|
|
|
+ agent_device_orders_qs = agent_device_orders_qs.filter(csp_id__in=csp_ids)
|
|
|
|
|
|
# 计算利润总额和订单总数
|
|
|
total_profit = agent_device_orders_qs.aggregate(Sum('profit'))['profit__sum'] or 0
|
|
@@ -605,7 +664,7 @@ class AgentCustomerView(View):
|
|
|
|
|
|
try:
|
|
|
# 计算冻结金额
|
|
|
- frozen_amount_qs = AgentAccountWithdraw.objects.filter(ac_id=ac_id)
|
|
|
+ frozen_amount_qs = AgentAccountWithdraw.objects.filter(ac_id=ac_id, status__in=[1,2,3])
|
|
|
frozen_amount = frozen_amount_qs.aggregate(total=Sum('amount'))['total'] or Decimal('0.00')
|
|
|
|
|
|
# 计算余额:已结算 - (退款+已打款)
|
|
@@ -742,7 +801,7 @@ class AgentCustomerView(View):
|
|
|
total_profit = incomes_all - expense_all
|
|
|
|
|
|
# 冻结余额
|
|
|
- frozen_amount_qs = AgentAccountWithdraw.objects.filter(ac_id=ac_id)
|
|
|
+ frozen_amount_qs = AgentAccountWithdraw.objects.filter(ac_id=ac_id, status__in=[1,2,3])
|
|
|
frozen_amount = frozen_amount_qs.aggregate(total=Sum('amount'))['total'] or Decimal('0.00')
|
|
|
|
|
|
# 可提现余额 = 总余额 - 冻结金额
|
|
@@ -762,4 +821,88 @@ class AgentCustomerView(View):
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
|
|
|
+ def get_withdrawal_review(self, request_dict, response):
|
|
|
+ """
|
|
|
+ 后台用户提现申请审核列表
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @param request_dict company_name: 公司名称
|
|
|
+ @param request_dict status: 审核状态
|
|
|
+ @param response: 响应对象
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ company_name = request_dict.get('company_name', None)
|
|
|
+ status = request_dict.get('status', None)
|
|
|
+ page = int(request_dict.get('page', 1)) # 默认为第一页
|
|
|
+ page_size = int(request_dict.get('page_size', 10)) # 默认每页10条记录
|
|
|
+ try:
|
|
|
+ agent_account_withdraw_qs = AgentAccountWithdraw.objects.filter().order_by('updated_time')
|
|
|
+ if company_name:
|
|
|
+ agent_customer_info = AgentCustomerInfo.objects.filter(company_name=company_name).first()
|
|
|
+ ac_id = agent_customer_info.id
|
|
|
+ agent_account_withdraw_qs = agent_account_withdraw_qs.filter(ac_id=ac_id)
|
|
|
+
|
|
|
+ if status:
|
|
|
+ agent_account_withdraw_qs = agent_account_withdraw_qs.filter(status=status)
|
|
|
|
|
|
+ # 提现id 公司名 审核状态 提现金额 余额
|
|
|
+ paginator = Paginator(agent_account_withdraw_qs, page_size)
|
|
|
+ current_page = paginator.get_page(page)
|
|
|
+
|
|
|
+ review_list = []
|
|
|
+
|
|
|
+ for review in current_page:
|
|
|
+ ac_id = review.ac_id
|
|
|
+ agent_customer_info = AgentCustomerInfo.objects.filter(id=ac_id).first()
|
|
|
+ company_name = agent_customer_info.company_name
|
|
|
+ review_list.append({
|
|
|
+ "id": review.id,
|
|
|
+ "company_name": company_name,
|
|
|
+ "status": review.status,
|
|
|
+ "amount": review.amount,
|
|
|
+ "remark": review.remark,
|
|
|
+ })
|
|
|
+
|
|
|
+ response_data = {
|
|
|
+ 'list': review_list,
|
|
|
+ 'total': paginator.count,
|
|
|
+ 'page': current_page.number,
|
|
|
+ 'page_size': page_size,
|
|
|
+ 'num_pages': paginator.num_pages,
|
|
|
+ }
|
|
|
+ return response.json(0, response_data)
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ def update_withdrawal_review(self, userID, request_dict, response):
|
|
|
+ """
|
|
|
+ 后台提现审核
|
|
|
+ @param request_dict: 请求参数
|
|
|
+ @param request_dict id: 提现单id
|
|
|
+ @param request_dict status: 提现单状态
|
|
|
+ @param request_dict remark: 提现单备注
|
|
|
+ @param response: 响应对象
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ id = request_dict.get('id', None)
|
|
|
+ status = request_dict.get('status', None)
|
|
|
+ remark = request_dict.get('remark', "")
|
|
|
+
|
|
|
+ if not all([id, status]):
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ try:
|
|
|
+ agent_account_withdraw = AgentAccountWithdraw.objects.get(pk=id)
|
|
|
+ agent_account_withdraw.status = status
|
|
|
+ agent_account_withdraw.remark = remark
|
|
|
+ agent_account_withdraw.save()
|
|
|
+ if int(status) == 4:
|
|
|
+ AgentAccount.objects.create(ac_id=agent_account_withdraw.ac_id,
|
|
|
+ amount=agent_account_withdraw.amount,
|
|
|
+ status=3,
|
|
|
+ created_time = int(time.time()),
|
|
|
+ updated_time = int(time.time()),
|
|
|
+ remark = f"{userID}修改为已提现")
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ except Exception as e:
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|