|
@@ -65,80 +65,15 @@ class OperatingCostsDataView(View):
|
|
|
else:
|
|
|
operating_costs_qs = OperatingCosts.objects.all()
|
|
|
count = operating_costs_qs.count()
|
|
|
- order_list = list(operating_costs_qs.values_list('order_id', flat=True).order_by('-time'))[:page * line]
|
|
|
operating_qs = operating_costs_qs.values('order_id', 'uid', 'day_average_price', 'month_average_price',
|
|
|
'purchase_quantity', 'actual_storage', 'actual_api',
|
|
|
'monthly_income', 'settlement_days', 'remaining_usage_time',
|
|
|
- 'end_time', 'created_time', 'start_time', 'time').order_by(
|
|
|
+ 'end_time', 'created_time', 'start_time', 'time', 'storage_cost',
|
|
|
+ 'api_cost', 'profit', 'profit_margin', 'fee', 'flow_cost',
|
|
|
+ 'real_income', 'price', 'region', 'country_name',
|
|
|
+ 'order_type', 'expire').order_by(
|
|
|
'-time')[(page - 1) * line:page * line]
|
|
|
- all_order_qs = Order_Model.objects.filter(orderID__in=order_list)
|
|
|
- country_qs = CountryModel.objects.values('id', 'country_name')
|
|
|
- country_dict = {}
|
|
|
- for item in country_qs:
|
|
|
- country_dict[item['id']] = item['country_name']
|
|
|
- res = []
|
|
|
- storage_univalence = 0.023 / 30
|
|
|
- api_univalence = 0.005 / 1000
|
|
|
- for item in operating_qs:
|
|
|
- order_qs = all_order_qs.filter(orderID=item['order_id']).values('price', 'order_type', 'fee',
|
|
|
- 'userID__region_country',
|
|
|
- 'rank__expire', 'payType')
|
|
|
- if not order_qs.exists():
|
|
|
- continue
|
|
|
- country_name = country_dict.get(order_qs[0]['userID__region_country'], '未知国家')
|
|
|
- region = '国内' if CONFIG_INFO == CONFIG_CN else '国外'
|
|
|
- if order_qs[0]['order_type'] in [0, 1]:
|
|
|
- order_type = '云存'
|
|
|
- storage_cost = round(
|
|
|
- float(item['actual_storage']) / 1024 * storage_univalence * item['settlement_days'], 2)
|
|
|
- api_cost = round(int(item['actual_api']) * api_univalence, 2)
|
|
|
- if CONFIG_INFO == CONFIG_CN: # 国内要换算汇率
|
|
|
- storage_cost = storage_cost * 7
|
|
|
- api_cost = api_cost * 7
|
|
|
- if float(item['monthly_income']) == 0.0:
|
|
|
- profit = 0
|
|
|
- profit_margin = 0
|
|
|
- else:
|
|
|
- profit = round(float(item['monthly_income']) - storage_cost - api_cost, 2) # 利润=月结算金额-月成本
|
|
|
- profit_margin = round(profit / float(item['month_average_price']), 2) # 利润率=利润/每月收入分摊
|
|
|
- expire = str(order_qs[0]['rank__expire']) + '个月'
|
|
|
- else:
|
|
|
- order_type = '4G流量'
|
|
|
- storage_cost = 0
|
|
|
- api_cost = 0
|
|
|
- if order_qs[0]['payType'] in [2, 3]:
|
|
|
- fee = float(order_qs[0]['price']) * 0.0054
|
|
|
- else:
|
|
|
- fee = float(order_qs[0]['fee']) if order_qs[0]['fee'] else 0
|
|
|
- res.append({
|
|
|
- 'order_id': item['order_id'],
|
|
|
- 'uid': item['uid'],
|
|
|
- 'region': region,
|
|
|
- 'country_name': country_name,
|
|
|
- 'order_type': order_type,
|
|
|
- 'expire': expire,
|
|
|
- 'price': order_qs[0]['price'],
|
|
|
- 'fee': fee,
|
|
|
- 'real_income': round(float(order_qs[0]['price']) - fee, 2),
|
|
|
- 'day_average_price': item['day_average_price'],
|
|
|
- 'month_average_price': item['month_average_price'],
|
|
|
- 'purchase_quantity': item['purchase_quantity'],
|
|
|
- 'start_time': item['start_time'],
|
|
|
- 'end_time': item['end_time'],
|
|
|
- 'settlement_time': item['created_time'],
|
|
|
- 'settlement_days': item['settlement_days'],
|
|
|
- 'monthly_income': item['monthly_income'],
|
|
|
- 'remaining_usage_time': item['remaining_usage_time'],
|
|
|
- 'actual_storage': item['actual_storage'],
|
|
|
- 'actual_api': item['actual_api'],
|
|
|
- 'storage_cost': storage_cost,
|
|
|
- 'api_cost': api_cost,
|
|
|
- 'profit': profit,
|
|
|
- 'profit_margin': profit_margin,
|
|
|
- 'time': item['time']
|
|
|
- })
|
|
|
- return response.json(0, {'count': count,
|
|
|
- 'res': res})
|
|
|
+ return response.json(0, {'count': count, 'res': list(operating_qs)})
|
|
|
except Exception as e:
|
|
|
print('error')
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|