|
@@ -539,6 +539,8 @@ class CronCollectDataView(View):
|
|
return self.collect_device_user(response)
|
|
return self.collect_device_user(response)
|
|
elif operation == 'collectOrder': # 定时保存订单数据
|
|
elif operation == 'collectOrder': # 定时保存订单数据
|
|
return self.collect_order(response)
|
|
return self.collect_order(response)
|
|
|
|
+ elif operation == 'collectIcloudOrder': # 定时保存云盘订单数据
|
|
|
|
+ return self.collect_icloud_order(response)
|
|
elif operation == 'collectDeviceInfo': # 定时保存设备数据
|
|
elif operation == 'collectDeviceInfo': # 定时保存设备数据
|
|
return self.collect_device_info(response)
|
|
return self.collect_device_info(response)
|
|
else:
|
|
else:
|
|
@@ -867,6 +869,160 @@ class CronCollectDataView(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(500, repr(e))
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def collect_icloud_order(response):
|
|
|
|
+ try:
|
|
|
|
+ order_type = 4
|
|
|
|
+ created_time = int(time.time())
|
|
|
|
+ today = datetime.datetime.today()
|
|
|
|
+ start_time = datetime.datetime(today.year, today.month, today.day)
|
|
|
|
+ end_time = start_time + datetime.timedelta(days=1)
|
|
|
|
+ start_time = CommonService.str_to_timestamp(start_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
|
+ end_time = CommonService.str_to_timestamp(end_time.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
|
+ order_qs = Order_Model.objects.filter(addTime__gte=start_time, addTime__lt=end_time, order_type=order_type,
|
|
|
|
+ status=1).values('userID',
|
|
|
|
+ 'store_meal_name', 'price',
|
|
|
|
+ 'addTime', 'currency').order_by(
|
|
|
|
+ 'addTime')
|
|
|
|
+ user_list = []
|
|
|
|
+ all_order_qs = Order_Model.objects.filter(addTime__lt=start_time, status=1, order_type=order_type).values(
|
|
|
|
+ 'userID')
|
|
|
|
+ for item in all_order_qs:
|
|
|
|
+ if item['userID'] not in user_list:
|
|
|
|
+ user_list.append(item['userID'])
|
|
|
|
+ # 国家表数据
|
|
|
|
+ country_qs = CountryModel.objects.values('id', 'country_name')
|
|
|
|
+ country_dict = {}
|
|
|
|
+ for item in country_qs:
|
|
|
|
+ country_dict[item['id']] = item['country_name']
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ for item in order_qs:
|
|
|
|
+ price = float(item['price'])
|
|
|
|
+ currency = item['currency']
|
|
|
|
+ user_qs = Device_User.objects.filter(userID=item['userID']).values('region_country')
|
|
|
|
+ country_id = user_qs[0]['region_country'] if user_qs.exists() else 0
|
|
|
|
+ country_name = country_dict.get(country_id, '未知国家')
|
|
|
|
+ store_meal_name = item['store_meal_name']
|
|
|
|
+ add_time_stamp = item['addTime']
|
|
|
|
+ add_time_str = datetime.datetime.fromtimestamp(int(add_time_stamp))
|
|
|
|
+ add_time_str = datetime.datetime(add_time_str.year, add_time_str.month, add_time_str.day)
|
|
|
|
+ add_time_stamp = CommonService.str_to_timestamp(add_time_str.strftime('%Y-%m-%d %H:%M:%S'))
|
|
|
|
+
|
|
|
|
+ order_summary_qs = OrdersSummary.objects.filter(time=add_time_stamp, query_type=0,
|
|
|
|
+ service_type=order_type)
|
|
|
|
+ if item['userID'] not in user_list:
|
|
|
|
+ pay_order_summary_qs = OrdersSummary.objects.filter(time=add_time_stamp, query_type=2,
|
|
|
|
+ service_type=order_type)
|
|
|
|
+ query_type = 2
|
|
|
|
+ else:
|
|
|
|
+ pay_order_summary_qs = OrdersSummary.objects.filter(time=add_time_stamp, query_type=3,
|
|
|
|
+ service_type=order_type)
|
|
|
|
+ query_type = 3
|
|
|
|
+ if pay_order_summary_qs.exists():
|
|
|
|
+ pay_order_summary = pay_order_summary_qs.first()
|
|
|
|
+ pay_order_summary.count += 1
|
|
|
|
+ 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
|
|
|
|
+ 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, currency: price}
|
|
|
|
+ pay_order_summary.country = country_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
|
|
|
|
+ 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, 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,
|
|
|
|
+ currency: price
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ store_meal_temp_dict = {
|
|
|
|
+ store_meal_name: {
|
|
|
|
+ '数量': 1,
|
|
|
|
+ currency: price
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ OrdersSummary.objects.create(time=add_time_stamp, count=1, query_type=query_type,
|
|
|
|
+ service_type=order_type, total=final_total,
|
|
|
|
+ country=country_temp_dict, created_time=created_time,
|
|
|
|
+ device_type={},
|
|
|
|
+ store_meal=store_meal_temp_dict)
|
|
|
|
+ if order_summary_qs.exists():
|
|
|
|
+ order_summary = order_summary_qs.first()
|
|
|
|
+ order_summary.count += 1
|
|
|
|
+ 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 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, currency: price}
|
|
|
|
+ order_summary.country = country_temp_dict
|
|
|
|
+ store_meal_temp_dict = eval(order_summary.store_meal)
|
|
|
|
+ if store_meal_name in store_meal_temp_dict:
|
|
|
|
+ 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, currency: price}
|
|
|
|
+ order_summary.store_meal = store_meal_temp_dict
|
|
|
|
+ order_summary.save()
|
|
|
|
+ else:
|
|
|
|
+ final_total = {currency: price}
|
|
|
|
+ country_temp_dict = {
|
|
|
|
+ country_name: {
|
|
|
|
+ '数量': 1,
|
|
|
|
+ currency: price
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ store_meal_temp_dict = {
|
|
|
|
+ store_meal_name: {
|
|
|
|
+ '数量': 1,
|
|
|
|
+ currency: price
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ OrdersSummary.objects.create(time=add_time_stamp, count=1, query_type=0,
|
|
|
|
+ service_type=order_type, total=final_total,
|
|
|
|
+ country=country_temp_dict, created_time=created_time,
|
|
|
|
+ device_type={}, store_meal=store_meal_temp_dict)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
+
|
|
@staticmethod
|
|
@staticmethod
|
|
def collect_device_info(response):
|
|
def collect_device_info(response):
|
|
try:
|
|
try:
|