|
@@ -23,7 +23,7 @@ from django.views import View
|
|
|
|
|
|
from Ansjer.config import USED_SERIAL_REDIS_LIST, UNUSED_SERIAL_REDIS_LIST, CONFIG_INFO, CONFIG_US, \
|
|
|
RESET_REGION_ID_SERIAL_REDIS_LIST, LOGGER, PAYPAL_CRD, CONFIG_EUR, DETECT_PUSH_DOMAINS, ACCESS_KEY_ID, \
|
|
|
- SECRET_ACCESS_KEY, REGION_NAME
|
|
|
+ SECRET_ACCESS_KEY, REGION_NAME, CONFIG_CN
|
|
|
from Model.models import Device_User, Device_Info, UidSetModel, UID_Bucket, Unused_Uid_Meal, Order_Model, StsCrdModel, \
|
|
|
VodHlsModel, ExperienceContextModel, AiService, VodHlsSummary, VideoPlaybackTimeModel, DeviceUserSummary, \
|
|
|
CountryModel, DeviceTypeModel, OrdersSummary, DeviceInfoSummary, CompanySerialModel, \
|
|
@@ -1154,13 +1154,24 @@ class CronCollectDataView(View):
|
|
|
operating_costs_qs = OperatingCosts.objects.filter(time=start_time_stamp).values('order_id', 'end_time',
|
|
|
'uid')
|
|
|
create_time = int(time.time())
|
|
|
+ storage_univalence = 0.023 / 30
|
|
|
+ api_univalence = 0.005 / 1000
|
|
|
+ region = '国内' if CONFIG_INFO == CONFIG_CN else '国外'
|
|
|
+ country_qs = CountryModel.objects.values('id', 'country_name')
|
|
|
+ country_dict = {}
|
|
|
+ for item in country_qs:
|
|
|
+ country_dict[item['id']] = item['country_name']
|
|
|
for item in operating_costs_qs:
|
|
|
order_qs = Order_Model.objects.filter(orderID=item['order_id']).values('price', 'payTime', 'order_type',
|
|
|
- 'rank__expire', 'fee', 'payType')
|
|
|
+ 'rank__expire', 'fee', 'payType',
|
|
|
+ 'userID__region_country')
|
|
|
if order_qs.exists():
|
|
|
order = order_qs[0]
|
|
|
+ country_name = country_dict.get(order['userID__region_country'], '未知国家')
|
|
|
if order['order_type'] not in [0, 1]:
|
|
|
continue
|
|
|
+ order_type = '云存'
|
|
|
+ expire = str(order_qs[0]['rank__expire']) + '个月'
|
|
|
price = float(order['price'])
|
|
|
if order['payType'] in [2, 3]:
|
|
|
fee = 0.0054 * price
|
|
@@ -1184,6 +1195,7 @@ class CronCollectDataView(View):
|
|
|
day_average_price = round(price / order_days, 2) # 收入分摊/天
|
|
|
month_average_price = round(day_average_price * settlement_days, 2) # 收入分摊/月
|
|
|
monthly_income = round((price - fee) / order_days * settlement_days, 2) # 当月结算收入
|
|
|
+ real_income = round(price - fee, 2)
|
|
|
if item['end_time'] < end_time_stamp:
|
|
|
uid_bucket_statistics = UidBucketStatistics.objects.filter(time__gte=start_time_stamp,
|
|
|
time__lt=item['end_time'],
|
|
@@ -1195,16 +1207,32 @@ class CronCollectDataView(View):
|
|
|
result = uid_bucket_statistics.aggregate(size=Sum('storage_size'), api_count=Sum('api_count'))
|
|
|
actual_storage = round(result['size'], 2) if result['size'] else 0
|
|
|
actual_api = result['api_count'] if result['api_count'] else 0
|
|
|
+ storage_cost = round(actual_storage / 1024 * storage_univalence * settlement_days, 2)
|
|
|
+ api_cost = round(actual_api * api_univalence, 2)
|
|
|
+ if CONFIG_INFO == CONFIG_CN: # 国内要换算汇率
|
|
|
+ storage_cost = storage_cost * 7
|
|
|
+ api_cost = api_cost * 7
|
|
|
+ if monthly_income == 0.0:
|
|
|
+ profit = 0
|
|
|
+ profit_margin = 0
|
|
|
+ else:
|
|
|
+ profit = round(monthly_income - storage_cost - api_cost, 2) # 利润=月结算金额-月成本
|
|
|
+ profit_margin = round(profit / month_average_price, 2) # 利润率=利润/每月收入分摊
|
|
|
OperatingCosts.objects.filter(time=start_time_stamp, order_id=item['order_id'],
|
|
|
uid=item['uid']).update(day_average_price=day_average_price,
|
|
|
month_average_price=month_average_price,
|
|
|
monthly_income=monthly_income,
|
|
|
actual_storage=actual_storage,
|
|
|
settlement_days=settlement_days,
|
|
|
- actual_api=actual_api,
|
|
|
- created_time=create_time,
|
|
|
+ actual_api=actual_api, fee=fee,
|
|
|
+ created_time=create_time, region=region,
|
|
|
start_time=order_start_time,
|
|
|
- remaining_usage_time=remaining_usage_time)
|
|
|
+ remaining_usage_time=remaining_usage_time,
|
|
|
+ storage_cost=storage_cost, api_cost=api_cost,
|
|
|
+ profit=profit, profit_margin=profit_margin,
|
|
|
+ real_income=real_income, price=price,
|
|
|
+ country_name=country_name,
|
|
|
+ order_type=order_type, expire=expire)
|
|
|
print('结束')
|
|
|
except Exception as e:
|
|
|
LOGGER.info(
|
|
@@ -1266,6 +1294,7 @@ class CronCollectDataView(View):
|
|
|
print(actual_storage, actual_api)
|
|
|
print('结束')
|
|
|
except Exception as e:
|
|
|
+ print('error')
|
|
|
LOGGER.info('统计s3信息异常:errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|