فهرست منبع

数据系统销售额查询区分美元、人民币

peng 2 سال پیش
والد
کامیت
d027dab54b

+ 113 - 35
AdminController/dataSystemManagement/HomeDataController.py

@@ -122,30 +122,76 @@ class HomeDataView(View):
             order_qs = OrdersSummary.objects.filter(time__gte=start_time_stamp,
                                                     time__lt=end_time_stamp,
                                                     query_type=0).values('total')
-            order_total = order_qs.aggregate(total=Sum('total'))['total']
-            order_total = round(order_total, 2) if order_total else 0
+            cny_total = 0
+            usd_total = 0
+            for item in order_qs:
+                temp_total = eval(item['total'])
+                cny_total = round(cny_total + temp_total.get('CNY', 0), 2)
+                usd_total = round(usd_total + temp_total.get('USD', 0), 2)
+            order_total = {'cnyTotal': cny_total, 'usdTotal': usd_total}
             # 昨日云存订单销售额
-            vod_order_total = order_qs.filter(service_type=0).aggregate(total=Sum('total'))['total']
-            vod_order_total = round(vod_order_total, 2) if vod_order_total else 0
+            vod_order_total = order_qs.filter(service_type=0)
+            vod_cny_total = 0
+            vod_usd_total = 0
+            for item in vod_order_total:
+                temp_total = eval(item['total'])
+                vod_cny_total = round(vod_cny_total + temp_total.get('CNY', 0), 2)
+                vod_usd_total = round(vod_usd_total + temp_total.get('USD', 0), 2)
+            vod_order_total = {'cnyTotal': vod_cny_total, 'usdTotal': vod_usd_total}
             # 昨日AI订单销售额
-            ai_order_total = order_qs.filter(service_type=1).aggregate(total=Sum('total'))['total']
-            ai_order_total = round(ai_order_total, 2) if ai_order_total else 0
+            ai_order_total = order_qs.filter(service_type=1)
+            ai_cny_total = 0
+            ai_usd_total = 0
+            for item in ai_order_total:
+                temp_total = eval(item['total'])
+                ai_cny_total = round(ai_cny_total + temp_total.get('CNY', 0), 2)
+                ai_usd_total = round(ai_usd_total + temp_total.get('USD', 0), 2)
+            ai_order_total = {'cnyTotal': ai_cny_total, 'usdTotal': ai_usd_total}
             # 昨日联通订单销售额
-            unicom_order_total = order_qs.filter(service_type=2).aggregate(total=Sum('total'))['total']
-            unicom_order_total = round(unicom_order_total, 2) if unicom_order_total else 0
+            unicom_order_total = order_qs.filter(service_type=2)
+            unicom_cny_total = 0
+            unicom_usd_total = 0
+            for item in unicom_order_total:
+                temp_total = eval(item['total'])
+                unicom_cny_total = round(unicom_cny_total + temp_total.get('CNY', 0), 2)
+                unicom_usd_total = round(unicom_usd_total + temp_total.get('USD', 0), 2)
+            unicom_order_total = {'cnyTotal': unicom_cny_total, 'usdTotal': unicom_usd_total}
             # 所有订单销售额
             order_all_qs = OrdersSummary.objects.filter(time__lte=start_time_stamp, query_type=0).values('total')
-            order_all_total = order_all_qs.aggregate(total=Sum('total'))['total']
-            order_all_total = round(order_all_total, 2) if order_all_total else 0
+            cny_all_total = 0
+            usd_all_total = 0
+            for item in order_all_qs:
+                temp_total = eval(item['total'])
+                cny_all_total = round(cny_all_total + temp_total.get('CNY', 0), 2)
+                usd_all_total = round(usd_all_total + temp_total.get('USD', 0), 2)
+            order_all_total = {'cnyTotal': cny_all_total, 'usdTotal': usd_all_total}
             # 所有云存订单销售额
-            vod_order_all_total = order_all_qs.filter(service_type=0).aggregate(total=Sum('total'))['total']
-            vod_order_all_total = round(vod_order_all_total, 2) if vod_order_all_total else 0
+            vod_order_all_total = order_all_qs.filter(service_type=0)
+            vod_cny_all_total = 0
+            vod_usd_all_total = 0
+            for item in vod_order_all_total:
+                temp_total = eval(item['total'])
+                vod_cny_all_total = round(vod_cny_all_total + temp_total.get('CNY', 0), 2)
+                vod_usd_all_total = round(vod_usd_all_total + temp_total.get('USD', 0), 2)
+            vod_order_all_total = {'cnyTotal': vod_cny_all_total, 'usdTotal': vod_usd_all_total}
             # 所有AI订单销售额
-            ai_order_all_total = order_all_qs.filter(service_type=1).aggregate(total=Sum('total'))['total']
-            ai_order_all_total = round(ai_order_all_total, 2) if ai_order_all_total else 0
+            ai_order_all_total = order_all_qs.filter(service_type=1)
+            ai_cny_all_total = 0
+            ai_usd_all_total = 0
+            for item in ai_order_all_total:
+                temp_total = eval(item['total'])
+                ai_cny_all_total = round(ai_cny_all_total + temp_total.get('CNY', 0), 2)
+                ai_usd_all_total = round(ai_usd_all_total + temp_total.get('USD', 0), 2)
+            ai_order_all_total = {'cnyTotal': ai_cny_all_total, 'usdTotal': ai_usd_all_total}
             # 所有联通订单销售额
-            unicom_order_all_total = order_all_qs.filter(service_type=2).aggregate(total=Sum('total'))['total']
-            unicom_order_all_total = round(unicom_order_all_total, 2) if unicom_order_all_total else 0
+            unicom_order_all_total = order_all_qs.filter(service_type=2)
+            unicom_cny_all_total = 0
+            unicom_usd_all_total = 0
+            for item in unicom_order_all_total:
+                temp_total = eval(item['total'])
+                unicom_cny_all_total = round(unicom_cny_all_total + temp_total.get('CNY', 0), 2)
+                unicom_usd_all_total = round(unicom_usd_all_total + temp_total.get('USD', 0), 2)
+            unicom_order_all_total = {'cnyTotal': unicom_cny_all_total, 'usdTotal': unicom_usd_all_total}
             res = {
                 'userIncreaseCount': user_increase_count,
                 'userActiveCount': user_active_count,
@@ -192,9 +238,16 @@ class HomeDataView(View):
             time_list = CommonService.cutting_time(start_time, end_time, time_unit)
             order_list = []
             for item in time_list:
-                total = order_qs.filter(time__gte=item[0], time__lt=item[1]).aggregate(total=Sum('total'))['total']
+                temp_order_qs = order_qs.filter(time__gte=item[0], time__lt=item[1])
+                cny_total = 0
+                usd_total = 0
+                for each in temp_order_qs:
+                    temp_total = eval(each['total'])
+                    cny_total += temp_total.get('CNY', 0)
+                    usd_total += temp_total.get('USD', 0)
                 res = {
-                    'total': round(total, 2) if total else 0,
+                    'cnyTotal': cny_total,
+                    'usdTotal': usd_total,
                     'startTime': item[0],
                     'endTime': item[1]
                 }
@@ -223,14 +276,14 @@ class HomeDataView(View):
             device_increase_count = 0
             device_active_count = 0
             device_all_count = 0
-            order_total = 0
-            vod_order_total = 0
-            ai_order_total = 0
-            unicom_order_total = 0
-            order_all_total = 0
-            vod_order_all_total = 0
-            ai_order_all_total = 0
-            unicom_order_all_total = 0
+            order_total = {'cnyTotal': 0, 'usdTotal': 0}
+            vod_order_total = {'cnyTotal': 0, 'usdTotal': 0}
+            ai_order_total = {'cnyTotal': 0, 'usdTotal': 0}
+            unicom_order_total = {'cnyTotal': 0, 'usdTotal': 0}
+            order_all_total = {'cnyTotal': 0, 'usdTotal': 0}
+            vod_order_all_total = {'cnyTotal': 0, 'usdTotal': 0}
+            ai_order_all_total = {'cnyTotal': 0, 'usdTotal': 0}
+            unicom_order_all_total = {'cnyTotal': 0, 'usdTotal': 0}
             user_increase_temp_list = []
             user_increase_list = []
             user_increase_other_dict = {'count': 0, 'countryName': '其他', 'rate': 0}
@@ -248,14 +301,38 @@ class HomeDataView(View):
                     device_increase_count += result['result']['deviceIncreaseCount']
                     device_active_count += result['result']['deviceActiveCount']
                     device_all_count += result['result']['deviceAllCount']
-                    order_total += result['result']['orderTotal']
-                    vod_order_total += result['result']['vodOrderTotal']
-                    ai_order_total += result['result']['aiOrderTotal']
-                    unicom_order_total += result['result']['unicomOrderTotal']
-                    order_all_total += result['result']['orderAllTotal']
-                    vod_order_all_total += result['result']['vodOrderAllTotal']
-                    ai_order_all_total += result['result']['aiOrderAllTotal']
-                    unicom_order_all_total += result['result']['unicomOrderAllTotal']
+                    order_total['cnyTotal'] = round(
+                        order_total['cnyTotal'] + result['result']['orderTotal']['cnyTotal'], 2)
+                    order_total['usdTotal'] = round(
+                        order_total['usdTotal'] + result['result']['orderTotal']['usdTotal'], 2)
+                    vod_order_total['cnyTotal'] = round(
+                        vod_order_total['cnyTotal'] + result['result']['vodOrderTotal']['cnyTotal'], 2)
+                    vod_order_total['usdTotal'] = round(
+                        vod_order_total['usdTotal'] + result['result']['vodOrderTotal']['usdTotal'], 2)
+                    ai_order_total['cnyTotal'] = round(
+                        ai_order_total['cnyTotal'] + result['result']['aiOrderTotal']['cnyTotal'], 2)
+                    ai_order_total['usdTotal'] = round(
+                        ai_order_total['usdTotal'] + result['result']['aiOrderTotal']['usdTotal'], 2)
+                    unicom_order_total['cnyTotal'] = round(
+                        unicom_order_total['cnyTotal'] + result['result']['unicomOrderTotal']['cnyTotal'], 2)
+                    unicom_order_total['usdTotal'] = round(
+                        unicom_order_total['usdTotal'] + result['result']['unicomOrderTotal']['usdTotal'], 2)
+                    order_all_total['cnyTotal'] = round(
+                        order_all_total['cnyTotal'] + result['result']['orderAllTotal']['cnyTotal'], 2)
+                    order_all_total['usdTotal'] = round(
+                        order_all_total['usdTotal'] + result['result']['orderAllTotal']['usdTotal'], 2)
+                    vod_order_all_total['cnyTotal'] = round(
+                        vod_order_all_total['cnyTotal'] + result['result']['vodOrderAllTotal']['cnyTotal'], 2)
+                    vod_order_all_total['usdTotal'] = round(
+                        vod_order_all_total['usdTotal'] + result['result']['vodOrderAllTotal']['usdTotal'], 2)
+                    ai_order_all_total['cnyTotal'] = round(
+                        ai_order_all_total['cnyTotal'] + result['result']['aiOrderAllTotal']['cnyTotal'], 2)
+                    ai_order_all_total['usdTotal'] = round(
+                        ai_order_all_total['usdTotal'] + result['result']['aiOrderAllTotal']['usdTotal'], 2)
+                    unicom_order_all_total['cnyTotal'] = round(
+                        unicom_order_all_total['cnyTotal'] + result['result']['unicomOrderAllTotal']['cnyTotal'], 2)
+                    unicom_order_all_total['usdTotal'] = round(
+                        unicom_order_all_total['usdTotal'] + result['result']['unicomOrderAllTotal']['usdTotal'], 2)
                     for item in result['result']['userIncreaseRegion']:
                         flag = 0
                         for each in user_increase_temp_list:
@@ -354,7 +431,8 @@ class HomeDataView(View):
                         flag = 0
                         for each in order_list:
                             if item['startTime'] == each['startTime'] and item['endTime'] == each['endTime']:
-                                each['total'] += item['total']
+                                each['cnyTotal'] = round(each['cnyTotal'] + item['cnyTotal'], 2)
+                                each['usdTotal'] = round(each['usdTotal'] + item['usdTotal'], 2)
                                 flag = 1
                                 break
                         if flag == 0:

+ 235 - 51
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:
@@ -299,11 +336,18 @@ class ServiceDataView(View):
             return response.json(444, {'error param': 'startTime or endTime or timeUnit or storeMealType'})
         try:
             order_qs = OrdersSummary.objects.filter(time__gte=start_time, time__lt=end_time, query_type=2,
-                                                    service_type=store_meal_type).values('count', 'country',
+                                                    service_type=store_meal_type).values('count', 'country', 'total',
                                                                                          'device_type')
             all_order_qs = OrdersSummary.objects.filter(time__gte=start_time, time__lt=end_time).filter(
-                Q(query_type=0) | Q(query_type=1)).aggregate(count=Sum('count'))
-            all_order_count = all_order_qs['count'] if all_order_qs['count'] 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)
@@ -314,8 +358,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]
                 }
@@ -328,34 +380,54 @@ class ServiceDataView(View):
                 device_type_temp_dict = eval(each['device_type'])
                 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 device_type_temp_dict.items():
                     if k in device_type_dict:
-                        device_type_dict[k] += v
+                        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
 
             # 设备类型订单统计
             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
+                type_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
                 device_temp_qs = {
                     'typeName': k,
-                    'count': v,
+                    'count': v['数量'],
+                    'cnyTotalRate': cny_total_rate,
+                    'usdTotalRate': usd_total_rate,
                     'typeRate': type_rate,
+                    'cnyTotalMoney': v.get('CNY', 0),
+                    'usdTotalMoney': v.get('USD', 0),
                 }
                 device_type_list.append(device_temp_qs)
 
             # 区域订单统计
             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)
 
@@ -363,7 +435,9 @@ class ServiceDataView(View):
                 'orders': order_list,
                 'regions': region_list,
                 'deviceType': device_type_list,
-                'allOrderCount': all_order_count
+                'allOrderCount': all_order_count,
+                'allOrderUsdTotal': all_order_usd_total,
+                'allOrderCnyTotal': all_order_cny_total,
             }
             return response.json(0, res)
         except Exception as e:
@@ -389,14 +463,20 @@ class ServiceDataView(View):
             return response.json(444, {'error param': 'startTime or endTime or timeUnit or storeMealType'})
         try:
             order_qs = OrdersSummary.objects.filter(time__gte=start_time, time__lt=end_time, query_type=3,
-                                                    service_type=store_meal_type).values('count', 'country',
+                                                    service_type=store_meal_type).values('count', 'country', 'total',
                                                                                          'device_type')
             repeat_pay_order_count = order_qs.aggregate(count=Sum('count'))['count']
             repeat_pay_order_count = repeat_pay_order_count if repeat_pay_order_count else 0
             all_order_qs = OrdersSummary.objects.filter(time__gte=start_time, time__lt=end_time).filter(
-                Q(query_type=0) | Q(query_type=1)).aggregate(count=Sum('count'))
-            all_order_count = all_order_qs['count'] if all_order_qs['count'] 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)
             # 订单复购率
             repeat_rate = round(repeat_pay_order_count / all_order_count * 100, 2) if all_order_count else 0
             start_time = datetime.datetime.fromtimestamp(int(start_time))
@@ -408,8 +488,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]
                 }
@@ -421,34 +509,54 @@ class ServiceDataView(View):
                 device_type_temp_dict = eval(each['device_type'])
                 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 device_type_temp_dict.items():
                     if k in device_type_dict:
-                        device_type_dict[k] += v
+                        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
 
             # 设备类型订单统计
             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
+                type_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
                 device_temp_qs = {
                     'typeName': k,
-                    'count': v,
+                    'count': v['数量'],
                     'typeRate': type_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_qs)
 
             # 区域订单统计
             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)
             res = {
@@ -457,7 +565,10 @@ class ServiceDataView(View):
                 'deviceType': device_type_list,
                 'repeatRate': repeat_rate,
                 'repeatOrderCount': repeat_pay_order_count,
-                'allOrderCount': all_order_count
+                'allOrderCount': all_order_count,
+                'allOrderCnyTotal': all_order_cny_total,
+                'allOrderUsdTotal': all_order_usd_total,
+
             }
             return response.json(0, res)
         except Exception as e:
@@ -481,7 +592,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 +606,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'] += item['cnyTotal']
+                                each['usdTotal'] += item['usdTotal']
                                 flag = 1
                                 break
                         if flag == 0:
@@ -504,6 +618,8 @@ class ServiceDataView(View):
                         for each in region_list:
                             if each['countryName'] == item['countryName']:
                                 each['count'] += int(item['count'])
+                                each['cnyTotalMoney'] += item['cnyTotalMoney']
+                                each['usdTotalMoney'] += item['usdTotalMoney']
                                 flag = 1
                                 break
                         if flag == 0:
@@ -515,7 +631,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'] += item['cnyTotalMoney']
+                                each['usdTotalMoney'] += item['usdTotalMoney']
                                 flag = 1
                                 break
                         if flag == 0:
@@ -527,23 +644,44 @@ 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'] += item['cnyTotalMoney']
+                                each['usdTotalMoney'] += item['usdTotalMoney']
                                 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 order_list:
+                item['cnyTotal'] = round(item['cnyTotal'], 2)
+                item['usdTotal'] = round(item['usdTotal'], 2)
             for item in region_list:
                 item['rate'] = round(item['count'] / all_order_count * 100, 2) if all_order_count else 0
+                item['cnyTotalMoney'] = round(item['cnyTotalMoney'], 2)
+                item['usdTotalMoney'] = round(item['usdTotalMoney'], 2)
+                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['cnyTotalMoney'] = round(item['cnyTotalMoney'], 2)
+                item['usdTotalMoney'] = round(item['usdTotalMoney'], 2)
+                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['cnyTotalMoney'] = round(item['cnyTotalMoney'], 2)
+                item['usdTotalMoney'] = round(item['usdTotalMoney'], 2)
                 item['rate'] = round(item['count'] / all_order_count * 100, 2) if all_order_count else 0
             res = {
                 'orders': order_list,
@@ -628,8 +766,6 @@ class ServiceDataView(View):
                 'orders': order_list,
                 'regions': CommonService.list_sort(region_list),
                 'deviceType': CommonService.list_sort(device_type_list),
-                'newDeviceCount': new_device_count,
-                'allOrderCount': all_order_count,
                 'inversionRate': inversion_rate
             }
             return response.json(0, res)
@@ -654,6 +790,8 @@ class ServiceDataView(View):
             region_list = []
             device_type_list = []
             all_order_count = 0
+            all_usd_order_total = 0
+            all_cny_order_total = 0
             for url in url_list:
                 url = url + request.path.replace('global/', '')
                 res = requests.get(url=url, params=request_dict, headers=headers)
@@ -665,6 +803,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'] += item['cnyTotal']
+                                each['usdTotal'] += item['usdTotal']
                                 flag = 1
                                 break
                         if flag == 0:
@@ -675,6 +815,8 @@ class ServiceDataView(View):
                         for each in region_list:
                             if each['countryName'] == item['countryName']:
                                 each['count'] += int(item['count'])
+                                each['cnyTotalMoney'] += item['cnyTotalMoney']
+                                each['usdTotalMoney'] += item['usdTotalMoney']
                                 flag = 1
                                 break
                         if flag == 0:
@@ -686,16 +828,35 @@ class ServiceDataView(View):
                         for each in device_type_list:
                             if each['typeName'] == item['typeName']:
                                 each['count'] += int(item['count'])
+                                each['cnyTotalMoney'] += item['cnyTotalMoney']
+                                each['usdTotalMoney'] += item['usdTotalMoney']
                                 flag = 1
                                 break
                         if flag == 0:
                             device_type_list.append(item)
                     all_order_count += result['result']['allOrderCount']
+                    all_cny_order_total += result['result']['allOrderCnyTotal']
+                    all_usd_order_total += result['result']['allOrderUsdTotal']
                 else:
                     return response.json(result['result_code'], result['result'])
+            for item in order_list:
+                item['cnyTotal'] = round(item['cnyTotal'], 2)
+                item['usdTotal'] = round(item['usdTotal'], 2)
             for item in region_list:
+                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['cnyTotalMoney'] = round(item['cnyTotalMoney'], 2)
+                item['usdTotalMoney'] = round(item['usdTotalMoney'], 2)
                 item['rate'] = round(item['count'] / all_order_count * 100, 2) if all_order_count else 0
             for item in device_type_list:
+                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['cnyTotalMoney'] = round(item['cnyTotalMoney'], 2)
+                item['usdTotalMoney'] = round(item['usdTotalMoney'], 2)
                 item['typeRate'] = round(item['count'] / all_order_count * 100, 2) if all_order_count else 0
             res = {
                 'orders': order_list,
@@ -725,6 +886,8 @@ class ServiceDataView(View):
             repeat_order_count = 0
             device_type_list = []
             all_order_count = 0
+            all_usd_order_total = 0
+            all_cny_order_total = 0
             for url in url_list:
                 url = url + request.path.replace('global/', '')
                 res = requests.get(url=url, params=request_dict, headers=headers)
@@ -736,6 +899,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'] += item['cnyTotal']
+                                each['usdTotal'] += item['usdTotal']
                                 flag = 1
                                 break
                         if flag == 0:
@@ -746,6 +911,8 @@ class ServiceDataView(View):
                         for each in region_list:
                             if each['countryName'] == item['countryName']:
                                 each['count'] += int(item['count'])
+                                each['cnyTotalMoney'] += item['cnyTotalMoney']
+                                each['usdTotalMoney'] += item['usdTotalMoney']
                                 flag = 1
                                 break
                         if flag == 0:
@@ -757,6 +924,8 @@ class ServiceDataView(View):
                         for each in device_type_list:
                             if each['typeName'] == item['typeName']:
                                 each['count'] += int(item['count'])
+                                each['cnyTotalMoney'] += item['cnyTotalMoney']
+                                each['usdTotalMoney'] += item['usdTotalMoney']
                                 flag = 1
                                 break
                         if flag == 0:
@@ -765,20 +934,35 @@ class ServiceDataView(View):
                     # 处理订单复购率
                     repeat_order_count += result['result']['repeatOrderCount']
                     all_order_count += result['result']['allOrderCount']
+                    all_usd_order_total += result['result']['allOrderUsdTotal']
+                    all_cny_order_total += result['result']['allOrderCnyTotal']
                 else:
                     return response.json(result['result_code'], result['result'])
             repeat_rate = round(repeat_order_count / all_order_count * 100, 2) if all_order_count else 0
+            for item in order_list:
+                item['cnyTotal'] = round(item['cnyTotal'], 2)
+                item['usdTotal'] = round(item['usdTotal'], 2)
             for item in device_type_list:
+                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['cnyTotalMoney'] = round(item['cnyTotalMoney'], 2)
+                item['usdTotalMoney'] = round(item['usdTotalMoney'], 2)
                 item['typeRate'] = round(item['count'] / all_order_count * 100, 2) if all_order_count else 0
             for item in region_list:
+                item['cnyTotalMoney'] = round(item['cnyTotalMoney'], 2)
+                item['usdTotalMoney'] = round(item['usdTotalMoney'], 2)
+                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,
                 'regions': CommonService.list_sort(region_list),
                 'deviceType': CommonService.list_sort(device_type_list),
                 'repeatRate': repeat_rate,
-                'repeatOrderCount': repeat_order_count,
-                'allOrderCount': all_order_count
             }
             return response.json(0, res)
         except Exception as e:

+ 88 - 27
Controller/Cron/CronTaskController.py

@@ -462,7 +462,7 @@ class CronCollectDataView(View):
             order_qs = Order_Model.objects.filter(addTime__gte=start_time, addTime__lt=end_time,
                                                   status=1).values('UID', 'order_type',
                                                                    'store_meal_name', 'price',
-                                                                   'addTime').order_by(
+                                                                   'addTime', 'currency').order_by(
                 'addTime')
             uid_list = []
             all_order_qs = Order_Model.objects.filter(addTime__lt=start_time, status=1).values('UID')
@@ -484,6 +484,7 @@ class CronCollectDataView(View):
                 for item in order_qs:
                     is_pay = 0
                     price = float(item['price'])
+                    currency = item['currency']
                     uid_set_qs = UidSetModel.objects.filter(uid=item['UID']).values('tb_country')
                     country_id = uid_set_qs[0]['tb_country'] if uid_set_qs.exists() else 0
                     country_name = country_dict.get(country_id, '未知国家')
@@ -514,62 +515,112 @@ class CronCollectDataView(View):
                         if pay_order_summary_qs.exists():
                             pay_order_summary = pay_order_summary_qs.first()
                             pay_order_summary.count += 1
-                            pay_order_summary.total = str(round(float(pay_order_summary.total) + price, 2))
+                            temp_total = eval(pay_order_summary.total)
+                            if currency not in temp_total:
+                                temp_total[currency] = price
+                            else:
+                                temp_total[currency] = round(temp_total[currency] + price, 2)
+                            pay_order_summary.total = temp_total
                             country_temp_dict = eval(pay_order_summary.country)
                             if country_name in country_temp_dict:
-                                country_temp_dict[country_name] += 1
+                                country_temp_dict[country_name]['数量'] += 1
+                                if currency not in country_temp_dict[country_name]:
+                                    country_temp_dict[country_name][currency] = price
+                                else:
+                                    country_temp_dict[country_name][currency] = round(
+                                        country_temp_dict[country_name][currency] + price, 2)
                             else:
-                                country_temp_dict[country_name] = 1
+                                country_temp_dict[country_name] = {'数量': 1, currency: price}
                             pay_order_summary.country = country_temp_dict
                             device_type_temp_dict = eval(pay_order_summary.device_type)
                             if device_type_name in device_type_temp_dict:
-                                device_type_temp_dict[device_type_name] += 1
+                                device_type_temp_dict[device_type_name]['数量'] += 1
+                                if currency not in device_type_temp_dict[device_type_name]:
+                                    device_type_temp_dict[device_type_name][currency] = price
+                                else:
+                                    device_type_temp_dict[device_type_name][currency] = round(
+                                        device_type_temp_dict[device_type_name][currency] + price, 2)
                             else:
-                                device_type_temp_dict[device_type_name] = 1
+                                device_type_temp_dict[device_type_name] = {'数量': 1, currency: price}
                             pay_order_summary.device_type = device_type_temp_dict
                             store_meal_temp_dict = eval(pay_order_summary.store_meal)
                             if store_meal_name in store_meal_temp_dict:
-                                store_meal_temp_dict[store_meal_name] += 1
+                                store_meal_temp_dict[store_meal_name]['数量'] += 1
+                                if currency not in store_meal_temp_dict[store_meal_name]:
+                                    store_meal_temp_dict[store_meal_name][currency] = price
+                                else:
+                                    store_meal_temp_dict[store_meal_name][currency] = round(
+                                        store_meal_temp_dict[store_meal_name][currency] + price, 2)
                             else:
-                                store_meal_temp_dict[store_meal_name] = 1
+                                store_meal_temp_dict[store_meal_name] = {'数量': 1, currency: price}
                             pay_order_summary.store_meal = store_meal_temp_dict
                             pay_order_summary.save()
                         else:
+                            final_total = {currency: price}
                             country_temp_dict = {
-                                country_name: 1
+                                country_name: {
+                                    '数量': 1,
+                                    currency: price
+                                }
                             }
                             device_type_temp_dict = {
-                                device_type_name: 1
+                                device_type_name: {
+                                    '数量': 1,
+                                    currency: price
+                                }
                             }
                             store_meal_temp_dict = {
-                                store_meal_name: 1
+                                store_meal_name: {
+                                    '数量': 1,
+                                    currency: price
+                                }
                             }
                             OrdersSummary.objects.create(time=add_time_stamp, count=1, query_type=query_type,
-                                                         service_type=order_type, total=price,
+                                                         service_type=order_type, total=final_total,
                                                          country=country_temp_dict,
                                                          device_type=device_type_temp_dict,
                                                          store_meal=store_meal_temp_dict)
                     if order_summary_qs.exists():
                         order_summary = order_summary_qs.first()
                         order_summary.count += 1
-                        order_summary.total = str(round(float(order_summary.total) + price, 2))
+                        temp_total = eval(order_summary.total)
+                        if currency not in temp_total:
+                            temp_total[currency] = price
+                        else:
+                            temp_total[currency] = round(temp_total[currency] + price, 2)
+                        order_summary.total = temp_total
                         country_temp_dict = eval(order_summary.country)
                         if country_name in country_temp_dict:
-                            country_temp_dict[country_name] += 1
+                            if is_pay == 0:
+                                country_temp_dict[country_name]['数量'] += 1
+                                if currency not in country_temp_dict[country_name]:
+                                    country_temp_dict[country_name][currency] = price
+                                else:
+                                    country_temp_dict[country_name][currency] = round(
+                                        country_temp_dict[country_name][currency] + price, 2)
+                            else:
+                                country_temp_dict[country_name] += 1
                         else:
-                            country_temp_dict[country_name] = 1
+                            if is_pay == 0:
+                                country_temp_dict[country_name] = {'数量': 1, currency: price}
+                            else:
+                                country_temp_dict[country_name] = 1
                         order_summary.country = country_temp_dict
                         device_type_temp_dict = eval(order_summary.device_type)
                         if device_type_name in device_type_temp_dict:
                             if is_pay == 0:
                                 device_type_temp_dict[device_type_name]['数量'] += 1
-                                device_type_temp_dict[device_type_name]['销售额'] = round(
-                                    device_type_temp_dict[device_type_name]['销售额'] + price, 2)
+                                if currency not in device_type_temp_dict[device_type_name]:
+                                    device_type_temp_dict[device_type_name][currency] = price
+                                else:
+
+                                    device_type_temp_dict[device_type_name][currency] = round(
+                                        device_type_temp_dict[device_type_name][currency] + price, 2)
                             else:
                                 device_type_temp_dict[device_type_name] += 1
                         else:
                             if is_pay == 0:
-                                device_type_temp_dict[device_type_name] = {'数量': 1, '销售额': price}
+                                device_type_temp_dict[device_type_name] = {'数量': 1, currency: price}
                             else:
                                 device_type_temp_dict[device_type_name] = 1
                         order_summary.device_type = device_type_temp_dict
@@ -577,32 +628,39 @@ class CronCollectDataView(View):
                         if store_meal_name in store_meal_temp_dict:
                             if is_pay == 0:
                                 store_meal_temp_dict[store_meal_name]['数量'] += 1
-                                store_meal_temp_dict[store_meal_name]['销售额'] = round(
-                                    store_meal_temp_dict[store_meal_name]['销售额'] + price, 2)
+                                if currency not in store_meal_temp_dict[store_meal_name]:
+                                    store_meal_temp_dict[store_meal_name][currency] = price
+                                else:
+                                    store_meal_temp_dict[store_meal_name][currency] = round(
+                                        store_meal_temp_dict[store_meal_name][currency] + price, 2)
                             else:
                                 store_meal_temp_dict[store_meal_name] += 1
                         else:
                             if is_pay == 0:
-                                store_meal_temp_dict[store_meal_name] = {'数量': 1, '销售额': price}
+                                store_meal_temp_dict[store_meal_name] = {'数量': 1, currency: price}
                             else:
                                 store_meal_temp_dict[store_meal_name] = 1
                         order_summary.store_meal = store_meal_temp_dict
                         order_summary.save()
                     else:
-                        country_temp_dict = {
-                            country_name: 1
-                        }
+                        final_total = {currency: price}
                         if is_pay == 0:
+                            country_temp_dict = {
+                                country_name: {
+                                    '数量': 1,
+                                    currency: price
+                                }
+                            }
                             device_type_temp_dict = {
                                 device_type_name: {
                                     '数量': 1,
-                                    '销售额': price
+                                    currency: price
                                 }
                             }
                             store_meal_temp_dict = {
                                 store_meal_name: {
                                     '数量': 1,
-                                    '销售额': price
+                                    currency: price
                                 }
                             }
                         else:
@@ -612,8 +670,11 @@ class CronCollectDataView(View):
                             store_meal_temp_dict = {
                                 store_meal_name: 1
                             }
+                            country_temp_dict = {
+                                country_name: 1
+                            }
                         OrdersSummary.objects.create(time=add_time_stamp, count=1, query_type=is_pay,
-                                                     service_type=order_type, total=price,
+                                                     service_type=order_type, total=final_total,
                                                      country=country_temp_dict,
                                                      device_type=device_type_temp_dict, store_meal=store_meal_temp_dict)
             return response.json(0)