|
@@ -698,10 +698,15 @@ class AgentCustomerView(View):
|
|
@return:
|
|
@return:
|
|
"""
|
|
"""
|
|
agent_customer_info = AgentCustomerInfo.objects.filter(user_id=userID).first()
|
|
agent_customer_info = AgentCustomerInfo.objects.filter(user_id=userID).first()
|
|
- if not agent_customer_info:
|
|
|
|
- return response.json(104, 'Agent customer not found')
|
|
|
|
|
|
+ if agent_customer_info is None:
|
|
|
|
+ agent_device_orders_qs = AgentDeviceOrder.objects.filter(is_del=False)
|
|
|
|
+ agent_device_qs = AgentDevice.objects.filter()
|
|
|
|
+ else:
|
|
|
|
+ ac_id = agent_customer_info.id
|
|
|
|
+ print(ac_id)
|
|
|
|
+ agent_device_orders_qs = AgentDeviceOrder.objects.filter(ac_id=ac_id, is_del=False)
|
|
|
|
+ agent_device_qs = AgentDevice.objects.filter(ac_id=ac_id)
|
|
|
|
|
|
- ac_id = agent_customer_info.id
|
|
|
|
now = datetime.now()
|
|
now = datetime.now()
|
|
today_start = datetime(now.year, now.month, now.day)
|
|
today_start = datetime(now.year, now.month, now.day)
|
|
yesterday_start = today_start - timedelta(days=1)
|
|
yesterday_start = today_start - timedelta(days=1)
|
|
@@ -710,23 +715,22 @@ class AgentCustomerView(View):
|
|
try:
|
|
try:
|
|
# 总利润
|
|
# 总利润
|
|
total_profit_all = \
|
|
total_profit_all = \
|
|
- AgentDeviceOrder.objects.filter(ac_id=ac_id, status__in=[1, 2], is_del=False).aggregate(
|
|
|
|
|
|
+ agent_device_orders_qs.filter(status__in=[1, 2], is_del=False).aggregate(
|
|
total=Sum('profit'))[
|
|
total=Sum('profit'))[
|
|
'total'] or Decimal('0.00')
|
|
'total'] or Decimal('0.00')
|
|
total_profit_no = \
|
|
total_profit_no = \
|
|
- AgentDeviceOrder.objects.filter(ac_id=ac_id, status=1, is_del=False).aggregate(total=Sum('profit'))[
|
|
|
|
|
|
+ agent_device_orders_qs.filter(status=1, is_del=False).aggregate(total=Sum('profit'))[
|
|
'total'] or Decimal('0.00')
|
|
'total'] or Decimal('0.00')
|
|
total_profit_yes = \
|
|
total_profit_yes = \
|
|
- AgentDeviceOrder.objects.filter(ac_id=ac_id, status=2, is_del=False).aggregate(total=Sum('profit'))[
|
|
|
|
|
|
+ agent_device_orders_qs.filter(status=2, is_del=False).aggregate(total=Sum('profit'))[
|
|
'total'] or Decimal('0.00')
|
|
'total'] or Decimal('0.00')
|
|
|
|
|
|
# 总营业额
|
|
# 总营业额
|
|
- profit_amount_all = AgentDeviceOrder.objects.filter(ac_id=ac_id, status__in=[1, 2], is_del=False).aggregate(
|
|
|
|
|
|
+ profit_amount_all = agent_device_orders_qs.filter(status__in=[1, 2], is_del=False).aggregate(
|
|
total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
|
|
|
|
# 今日总营业额
|
|
# 今日总营业额
|
|
- profit_amount_today_all = AgentDeviceOrder.objects.filter(
|
|
|
|
- ac_id=ac_id,
|
|
|
|
|
|
+ profit_amount_today_all = agent_device_orders_qs.filter(
|
|
status__in=[1, 2],
|
|
status__in=[1, 2],
|
|
is_del=False,
|
|
is_del=False,
|
|
created_time__gte=int(today_start.timestamp()),
|
|
created_time__gte=int(today_start.timestamp()),
|
|
@@ -734,8 +738,7 @@ class AgentCustomerView(View):
|
|
).aggregate(total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
).aggregate(total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
|
|
|
|
# 昨日总营业额
|
|
# 昨日总营业额
|
|
- profit_amount_yesterday_all = AgentDeviceOrder.objects.filter(
|
|
|
|
- ac_id=ac_id,
|
|
|
|
|
|
+ profit_amount_yesterday_all = agent_device_orders_qs.filter(
|
|
status__in=[1, 2],
|
|
status__in=[1, 2],
|
|
is_del=False,
|
|
is_del=False,
|
|
created_time__gte=int(yesterday_start.timestamp()),
|
|
created_time__gte=int(yesterday_start.timestamp()),
|
|
@@ -743,19 +746,19 @@ class AgentCustomerView(View):
|
|
).aggregate(total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
).aggregate(total=Sum('profit_amount'))['total'] or Decimal('0.00')
|
|
|
|
|
|
# 激活设备数
|
|
# 激活设备数
|
|
- active_device_count_today = AgentDevice.objects.filter(
|
|
|
|
- ac_id=ac_id, status=1,
|
|
|
|
|
|
+ active_device_count_today = agent_device_qs.filter(
|
|
|
|
+ status=1,
|
|
created_time__gte=int(today_start.timestamp()),
|
|
created_time__gte=int(today_start.timestamp()),
|
|
created_time__lt=int(tomorrow_start.timestamp())
|
|
created_time__lt=int(tomorrow_start.timestamp())
|
|
).count()
|
|
).count()
|
|
- active_device_count_yesterday = AgentDevice.objects.filter(
|
|
|
|
- ac_id=ac_id, status=1,
|
|
|
|
|
|
+ active_device_count_yesterday = agent_device_qs.filter(
|
|
|
|
+ status=1,
|
|
created_time__gte=int(yesterday_start.timestamp()),
|
|
created_time__gte=int(yesterday_start.timestamp()),
|
|
created_time__lt=int(today_start.timestamp())
|
|
created_time__lt=int(today_start.timestamp())
|
|
).count()
|
|
).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()
|
|
|
|
|
|
+ active_device_count = agent_device_qs.filter(status=1).count()
|
|
|
|
+ inactive_device_count = agent_device_qs.filter(status=0).count()
|
|
|
|
|
|
return response.json(0, {
|
|
return response.json(0, {
|
|
'total_profit_all': total_profit_all,
|
|
'total_profit_all': total_profit_all,
|