Jelajahi Sumber

付费订单修改

peng 2 tahun lalu
induk
melakukan
de1e575f14
1 mengubah file dengan 79 tambahan dan 24 penghapusan
  1. 79 24
      AdminController/dataSystemManagement/ServiceDataController.py

+ 79 - 24
AdminController/dataSystemManagement/ServiceDataController.py

@@ -76,9 +76,15 @@ class ServiceDataView(View):
                                                     service_type=store_meal_type).values('count', 'country', 'total',
                                                                                          'device_type', 'store_meal')
             all_order_qs = OrdersSummary.objects.filter(time__gte=start_time, time__lt=end_time).filter(
-                Q(query_type=0) | Q(query_type=1)).aggregate(total=Sum('total'), count=Sum('count'))
-            all_order_count = all_order_qs['count'] if all_order_qs['count'] else 0
-            all_order_total = all_order_qs['total'] if all_order_qs['total'] else 0
+                Q(query_type=0) | Q(query_type=1)).values('total', 'count')
+            all_order_count = 0
+            all_order_cny_total = 0
+            all_order_usd_total = 0
+            for item in all_order_qs:
+                all_order_count += item['count']
+                temp_total = eval(item['total'])
+                all_order_cny_total += temp_total.get('CNY', 0)
+                all_order_usd_total += temp_total.get('USD', 0)
             start_time = datetime.datetime.fromtimestamp(int(start_time))
             end_time = datetime.datetime.fromtimestamp(int(end_time))
             time_list = CommonService.cutting_time(start_time, end_time, time_unit)
@@ -89,8 +95,16 @@ class ServiceDataView(View):
                 order_temp_qs = order_qs.filter(time__gte=item[0], time__lt=item[1])
                 temp_count = order_temp_qs.aggregate(count=Sum('count'))['count']
                 temp_count = temp_count if temp_count else 0
+                temp_cny_total = 0
+                temp_usd_total = 0
+                for each in order_temp_qs:
+                    temp_total = eval(each['total'])
+                    temp_cny_total += temp_total.get('CNY', 0)
+                    temp_usd_total += temp_total.get('USD', 0)
                 order_dict = {
                     'count': temp_count,
+                    'cnyTotal': temp_cny_total,
+                    'usdTotal': temp_usd_total,
                     'startTime': item[0],
                     'endTime': item[1]
                 }
@@ -105,56 +119,78 @@ class ServiceDataView(View):
                 store_meal_temp_dict = eval(each['store_meal'])
                 for k, v in device_type_temp_dict.items():
                     if k in device_type_dict:
-                        device_type_dict[k]['数量'] += v['数量']
-                        device_type_dict[k]['销售额'] = round(device_type_dict[k]['销售额'] + v['销售额'], 2)
+                        for a, b in v.items():
+                            if a not in device_type_dict[k]:
+                                device_type_dict[k][a] = b
+                            else:
+                                device_type_dict[k][a] += b
                     else:
                         device_type_dict[k] = v
                 for k, v in country_temp_dict.items():
                     if k in country_dict:
-                        country_dict[k] += v
+                        for a, b in v.items():
+                            if a not in country_dict[k]:
+                                country_dict[k][a] = b
+                            else:
+                                country_dict[k][a] += b
                     else:
                         country_dict[k] = v
                 for k, v in store_meal_temp_dict.items():
                     if k in store_meal_dict:
-                        store_meal_dict[k]['数量'] += v['数量']
-                        store_meal_dict[k]['销售额'] = round(store_meal_dict[k]['销售额'] + v['销售额'], 2)
+                        for a, b in v.items():
+                            if a not in store_meal_dict[k]:
+                                store_meal_dict[k][a] = b
+                            else:
+                                store_meal_dict[k][a] += b
                     else:
                         store_meal_dict[k] = v
             # 设备类型订单统计
             device_type_list = []
             for k, v in device_type_dict.items():
                 type_rate = round(v['数量'] / all_order_count * 100, 2) if all_order_count else 0
-                total_rate = round(v['销售额'] / all_order_total * 100, 2) if all_order_total else 0
+                cny_total_rate = round(v.get('CNY', 0) / all_order_cny_total * 100, 2) if all_order_cny_total else 0
+                usd_total_rate = round(v.get('USD', 0) / all_order_usd_total * 100, 2) if all_order_usd_total else 0
                 device_temp_dict = {
                     'typeName': k,
                     'count': v['数量'],
                     'typeRate': type_rate,
-                    'totalMoney': v['销售额'],
-                    'totalRate': total_rate
+                    'cnyTotalMoney': v.get('CNY', 0),
+                    'usdTotalMoney': v.get('USD', 0),
+                    'cnyTotalRate': cny_total_rate,
+                    'usdTotalRate': usd_total_rate,
                 }
                 device_type_list.append(device_temp_dict)
 
             # 区域订单统计
             region_list = []
             for k, v in country_dict.items():
-                rate = round(v / all_order_count * 100, 2) if all_order_count else 0
+                rate = round(v['数量'] / all_order_count * 100, 2) if all_order_count else 0
+                cny_total_rate = round(v.get('CNY', 0) / all_order_cny_total * 100, 2) if all_order_cny_total else 0
+                usd_total_rate = round(v.get('USD', 0) / all_order_usd_total * 100, 2) if all_order_usd_total else 0
                 region_temp_dict = {
                     'countryName': k,
-                    'count': v,
-                    'rate': rate
+                    'count': v['数量'],
+                    'rate': rate,
+                    'cnyTotalMoney': v.get('CNY', 0),
+                    'usdTotalMoney': v.get('USD', 0),
+                    'cnyTotalRate': cny_total_rate,
+                    'usdTotalRate': usd_total_rate,
                 }
                 region_list.append(region_temp_dict)
 
             # 套餐订单统计
             store_meal_list = []
             for k, v in store_meal_dict.items():
-                total_rate = round(float(v['销售额']) / all_order_total * 100, 2) if all_order_total else 0
                 count_rate = round(v['数量'] / all_order_count * 100, 2) if all_order_count else 0
+                cny_total_rate = round(v.get('CNY', 0) / all_order_cny_total * 100, 2) if all_order_cny_total else 0
+                usd_total_rate = round(v.get('USD', 0) / all_order_usd_total * 100, 2) if all_order_usd_total else 0
                 store_temp_dict = {
                     'count': v['数量'],
                     'storeMealName': k,
-                    'storeMealTotal': v['销售额'],
-                    'totalRate': total_rate,
+                    'cnyTotalMoney': v.get('CNY', 0),
+                    'usdTotalMoney': v.get('USD', 0),
+                    'cnyTotalRate': cny_total_rate,
+                    'usdTotalRate': usd_total_rate,
                     'rate': count_rate
                 }
                 store_meal_list.append(store_temp_dict)
@@ -164,7 +200,8 @@ class ServiceDataView(View):
                 'deviceType': device_type_list,
                 'storeMeal': store_meal_list,
                 'allOrderCount': all_order_count,
-                'allOrderTotal': all_order_total
+                'allCnyOrderTotal': all_order_cny_total,
+                'allUsdOrderTotal': all_order_usd_total,
             }
             return response.json(0, res)
         except Exception as e:
@@ -481,7 +518,8 @@ class ServiceDataView(View):
             region_list = []
             device_type_list = []
             all_order_count = 0
-            all_order_total = 0
+            all_cny_order_total = 0
+            all_usd_order_total = 0
             store_meal_list = []
             for url in url_list:
                 url = url + request.path.replace('global/', '')
@@ -494,6 +532,8 @@ class ServiceDataView(View):
                         for each in order_list:
                             if each['startTime'] == item['startTime'] and each['endTime'] == item['endTime']:
                                 each['count'] += int(item['count'])
+                                each['cnyTotal'] = round(each['cnyTotal'] + item['cnyTotal'], 2)
+                                each['usdTotal'] = round(each['usdTotal'] + item['usdTotal'], 2)
                                 flag = 1
                                 break
                         if flag == 0:
@@ -504,6 +544,8 @@ class ServiceDataView(View):
                         for each in region_list:
                             if each['countryName'] == item['countryName']:
                                 each['count'] += int(item['count'])
+                                each['cnyTotalMoney'] = round(each['cnyTotalMoney'] + item['cnyTotalMoney'], 2)
+                                each['usdTotalMoney'] = round(each['usdTotalMoney'] + item['usdTotalMoney'], 2)
                                 flag = 1
                                 break
                         if flag == 0:
@@ -515,7 +557,8 @@ class ServiceDataView(View):
                         for each in device_type_list:
                             if each['typeName'] == item['typeName']:
                                 each['count'] += int(item['count'])
-                                item['totalMoney'] += item['totalMoney']
+                                each['cnyTotalMoney'] = round(each['cnyTotalMoney'] + item['cnyTotalMoney'], 2)
+                                each['usdTotalMoney'] = round(each['usdTotalMoney'] + item['usdTotalMoney'], 2)
                                 flag = 1
                                 break
                         if flag == 0:
@@ -527,23 +570,35 @@ class ServiceDataView(View):
                         for each in store_meal_list:
                             if each['storeMealName'] == item['storeMealName']:
                                 each['count'] += int(item['count'])
-                                each['storeMealTotal'] += item['storeMealTotal']
+                                each['cnyTotalMoney'] = round(each['cnyTotalMoney'] + item['cnyTotalMoney'], 2)
+                                each['usdTotalMoney'] = round(each['usdTotalMoney'] + item['usdTotalMoney'], 2)
                                 flag = 1
                                 break
                         if flag == 0:
                             store_meal_list.append(item)
 
-                    all_order_total += result['result']['allOrderTotal']
+                    all_cny_order_total += result['result']['allCnyOrderTotal']
+                    all_usd_order_total += result['result']['allUsdOrderTotal']
                     all_order_count += result['result']['allOrderCount']
                 else:
                     return response.json(result['result_code'], result['result'])
             for item in region_list:
                 item['rate'] = round(item['count'] / all_order_count * 100, 2) if all_order_count else 0
+                item['cnyTotalRate'] = round(item['cnyTotalMoney'] / all_cny_order_total * 100,
+                                             2) if all_cny_order_total else 0
+                item['usdTotalRate'] = round(item['usdTotalMoney'] / all_usd_order_total * 100,
+                                             2) if all_usd_order_total else 0
             for item in device_type_list:
                 item['typeRate'] = round(item['count'] / all_order_count * 100, 2) if all_order_count else 0
-                item['totalRate'] = round(item['totalMoney'] / all_order_total * 100, 2) if all_order_total else 0
+                item['cnyTotalRate'] = round(item['cnyTotalMoney'] / all_cny_order_total * 100,
+                                             2) if all_cny_order_total else 0
+                item['usdTotalRate'] = round(item['usdTotalMoney'] / all_usd_order_total * 100,
+                                             2) if all_usd_order_total else 0
             for item in store_meal_list:
-                item['totalRate'] = round(item['storeMealTotal'] / all_order_total * 100, 2) if all_order_total else 0
+                item['cnyTotalRate'] = round(item['cnyTotalMoney'] / all_cny_order_total * 100,
+                                             2) if all_cny_order_total else 0
+                item['usdTotalRate'] = round(item['usdTotalMoney'] / all_usd_order_total * 100,
+                                             2) if all_usd_order_total else 0
                 item['rate'] = round(item['count'] / all_order_count * 100, 2) if all_order_count else 0
             res = {
                 'orders': order_list,