|
@@ -86,6 +86,8 @@ class AgentCustomerView(View):
|
|
return self.batch_rebind_customer_packages(userID, request_dict, response)
|
|
return self.batch_rebind_customer_packages(userID, request_dict, response)
|
|
elif operation == 'getAgentServicePackageList':
|
|
elif operation == 'getAgentServicePackageList':
|
|
return self.get_agent_service_package_list(response)
|
|
return self.get_agent_service_package_list(response)
|
|
|
|
+ elif operation == 'getDataStatistics':
|
|
|
|
+ return self.get_data_statistics(userID, response)
|
|
else:
|
|
else:
|
|
return response.json(444, 'operation')
|
|
return response.json(444, 'operation')
|
|
|
|
|
|
@@ -441,3 +443,86 @@ class AgentCustomerView(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
# 出错时返回错误信息
|
|
# 出错时返回错误信息
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+
|
|
|
|
+ def get_data_statistics(self, userID, response):
|
|
|
|
+ """
|
|
|
|
+ 首页总览
|
|
|
|
+ @param userID: userID
|
|
|
|
+ @param response: 响应对象
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
|
|
+ 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
|
|
|
|
+ now = datetime.now()
|
|
|
|
+ today_start = datetime(now.year, now.month, now.day)
|
|
|
|
+ yesterday_start = today_start - timedelta(days=1)
|
|
|
|
+ tomorrow_start = today_start + timedelta(days=1)
|
|
|
|
+
|
|
|
|
+ try:
|
|
|
|
+ # 总利润
|
|
|
|
+ total_profit_all = \
|
|
|
|
+ AgentDeviceOrder.objects.filter(ac_id=ac_id, status__in=[1, 2], is_del=False).aggregate(
|
|
|
|
+ total=Sum('profit'))[
|
|
|
|
+ 'total'] or Decimal('0.00')
|
|
|
|
+ total_profit_no = \
|
|
|
|
+ AgentDeviceOrder.objects.filter(ac_id=ac_id, status=1, is_del=False).aggregate(total=Sum('profit'))[
|
|
|
|
+ 'total'] or Decimal('0.00')
|
|
|
|
+ total_profit_yes = \
|
|
|
|
+ AgentDeviceOrder.objects.filter(ac_id=ac_id, status=2, is_del=False).aggregate(total=Sum('profit'))[
|
|
|
|
+ 'total'] or Decimal('0.00')
|
|
|
|
+
|
|
|
|
+ # 总营业额
|
|
|
|
+ profit_amount_all = AgentDeviceOrder.objects.filter(ac_id=ac_id, status__in=[1, 2], is_del=False).aggregate(
|
|
|
|
+ total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
|
|
+
|
|
|
|
+ # 今日总营业额
|
|
|
|
+ profit_amount_today_all = AgentDeviceOrder.objects.filter(
|
|
|
|
+ ac_id=ac_id,
|
|
|
|
+ status__in=[1, 2],
|
|
|
|
+ is_del=False,
|
|
|
|
+ created_time__gte=int(today_start.timestamp()),
|
|
|
|
+ created_time__lt=int(tomorrow_start.timestamp())
|
|
|
|
+ ).aggregate(total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
|
|
+
|
|
|
|
+ # 昨日总营业额
|
|
|
|
+ profit_amount_yesterday_all = AgentDeviceOrder.objects.filter(
|
|
|
|
+ ac_id=ac_id,
|
|
|
|
+ status__in=[1, 2],
|
|
|
|
+ is_del=False,
|
|
|
|
+ created_time__gte=int(yesterday_start.timestamp()),
|
|
|
|
+ created_time__lt=int(today_start.timestamp())
|
|
|
|
+ ).aggregate(total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
|
|
+
|
|
|
|
+ # 激活设备数
|
|
|
|
+ active_device_count_today = AgentDevice.objects.filter(
|
|
|
|
+ ac_id=ac_id, status=1,
|
|
|
|
+ created_time__gte=int(today_start.timestamp()),
|
|
|
|
+ created_time__lt=int(tomorrow_start.timestamp())
|
|
|
|
+ ).count()
|
|
|
|
+ active_device_count_yesterday = AgentDevice.objects.filter(
|
|
|
|
+ ac_id=ac_id, status=1,
|
|
|
|
+ created_time__gte=int(yesterday_start.timestamp()),
|
|
|
|
+ created_time__lt=int(today_start.timestamp())
|
|
|
|
+ ).count()
|
|
|
|
+ # 总设备数
|
|
|
|
+ active_device_count = AgentDevice.objects.filter(ac_id=ac_id, status=1).count()
|
|
|
|
+ inactive_device_count = AgentDevice.objects.filter(ac_id=ac_id, status=0).count()
|
|
|
|
+
|
|
|
|
+ return response.json(0, {
|
|
|
|
+ 'total_profit_all': total_profit_all,
|
|
|
|
+ 'total_profit_no': total_profit_no,
|
|
|
|
+ 'total_profit_yes': total_profit_yes,
|
|
|
|
+ 'profit_amount_all': profit_amount_all,
|
|
|
|
+ 'profit_amount_today_all': profit_amount_today_all,
|
|
|
|
+ 'profit_amount_yesterday_all': profit_amount_yesterday_all,
|
|
|
|
+ 'active_device_count_today': active_device_count_today,
|
|
|
|
+ 'active_device_count_yesterday': active_device_count_yesterday,
|
|
|
|
+ 'active_device_count': active_device_count,
|
|
|
|
+ 'inactive_device_count': inactive_device_count,
|
|
|
|
+ 'all_device_count': active_device_count + inactive_device_count
|
|
|
|
+ })
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|