|
@@ -59,12 +59,9 @@ class OperatingCostsDataView(View):
|
|
return response.json(444, {'error param': 'page or line'})
|
|
return response.json(444, {'error param': 'page or line'})
|
|
page = int(page)
|
|
page = int(page)
|
|
line = int(line)
|
|
line = int(line)
|
|
- # params = {'page': page, 'line': line}
|
|
|
|
try:
|
|
try:
|
|
if start_time and end_time:
|
|
if start_time and end_time:
|
|
- operating_costs_qs = OperatingCosts.objects.filter(Q(time__gte=start_time), Q(time__lt=end_time))
|
|
|
|
- # params['startTime'] = start_time
|
|
|
|
- # params['endTime'] = end_time
|
|
|
|
|
|
+ operating_costs_qs = OperatingCosts.objects.filter(Q(time__gte=start_time), Q(time__lte=end_time))
|
|
else:
|
|
else:
|
|
operating_costs_qs = OperatingCosts.objects.all()
|
|
operating_costs_qs = OperatingCosts.objects.all()
|
|
count = operating_costs_qs.count()
|
|
count = operating_costs_qs.count()
|
|
@@ -98,8 +95,12 @@ class OperatingCostsDataView(View):
|
|
if CONFIG_INFO == CONFIG_CN: # 国内要换算汇率
|
|
if CONFIG_INFO == CONFIG_CN: # 国内要换算汇率
|
|
storage_cost = storage_cost * 7
|
|
storage_cost = storage_cost * 7
|
|
api_cost = api_cost * 7
|
|
api_cost = api_cost * 7
|
|
- profit = round(float(item['monthly_income']) - storage_cost - api_cost, 2) # 利润=月结算金额-月成本
|
|
|
|
- profit_margin = round(profit / float(item['month_average_price']), 2) # 利润率=利润/每月收入分摊
|
|
|
|
|
|
+ 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']) + '个月'
|
|
expire = str(order_qs[0]['rank__expire']) + '个月'
|
|
else:
|
|
else:
|
|
order_type = '4G流量'
|
|
order_type = '4G流量'
|
|
@@ -108,7 +109,7 @@ class OperatingCostsDataView(View):
|
|
if order_qs[0]['payType'] in [2, 3]:
|
|
if order_qs[0]['payType'] in [2, 3]:
|
|
fee = float(order_qs[0]['price']) * 0.0054
|
|
fee = float(order_qs[0]['price']) * 0.0054
|
|
else:
|
|
else:
|
|
- fee = order_qs[0]['fee']
|
|
|
|
|
|
+ fee = float(order_qs[0]['fee']) if order_qs[0]['fee'] else 0
|
|
res.append({
|
|
res.append({
|
|
'order_id': item['order_id'],
|
|
'order_id': item['order_id'],
|
|
'uid': item['uid'],
|
|
'uid': item['uid'],
|
|
@@ -118,7 +119,7 @@ class OperatingCostsDataView(View):
|
|
'expire': expire,
|
|
'expire': expire,
|
|
'price': order_qs[0]['price'],
|
|
'price': order_qs[0]['price'],
|
|
'fee': fee,
|
|
'fee': fee,
|
|
- 'real_income': round(float(order_qs[0]['price']) - float(order_qs[0]['fee']), 2),
|
|
|
|
|
|
+ 'real_income': round(float(order_qs[0]['price']) - fee, 2),
|
|
'day_average_price': item['day_average_price'],
|
|
'day_average_price': item['day_average_price'],
|
|
'month_average_price': item['month_average_price'],
|
|
'month_average_price': item['month_average_price'],
|
|
'purchase_quantity': item['purchase_quantity'],
|
|
'purchase_quantity': item['purchase_quantity'],
|
|
@@ -136,19 +137,8 @@ class OperatingCostsDataView(View):
|
|
'profit_margin': profit_margin,
|
|
'profit_margin': profit_margin,
|
|
'time': item['time']
|
|
'time': item['time']
|
|
})
|
|
})
|
|
- # if CONFIG_INFO == CONFIG_US:
|
|
|
|
- # headers = {
|
|
|
|
- # 'Authorization': request.META.get('HTTP_AUTHORIZATION')
|
|
|
|
- # }
|
|
|
|
- # eur_response = requests.get('https://www.zositeche.com/dataManagement/costsData/getOperatingCosts',
|
|
|
|
- # params=params, headers=headers)
|
|
|
|
- # if eur_response.status_code == 200:
|
|
|
|
- # eur_result = eur_response.json()
|
|
|
|
- # if eur_result['result_code'] == 0:
|
|
|
|
- # res += eur_result['result']['res']
|
|
|
|
- # count += eur_result['result']['count']
|
|
|
|
- # res = CommonService.list_sort_v2(res, 'time')
|
|
|
|
return response.json(0, {'count': count,
|
|
return response.json(0, {'count': count,
|
|
'res': res})
|
|
'res': res})
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
+ print('error')
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|