|
@@ -1180,39 +1180,50 @@ class CronCollectDataView(View):
|
|
order_start_time = int((datetime.datetime.fromtimestamp(item['end_time']) - relativedelta(
|
|
order_start_time = int((datetime.datetime.fromtimestamp(item['end_time']) - relativedelta(
|
|
months=order['rank__expire'])).timestamp())
|
|
months=order['rank__expire'])).timestamp())
|
|
order_days = round((item['end_time'] - order_start_time) / 86400)
|
|
order_days = round((item['end_time'] - order_start_time) / 86400)
|
|
- if item['end_time'] > end_time_stamp: # 订单到下个月结束
|
|
|
|
- if order_start_time <= start_time_stamp: # 订单在上月开始服务
|
|
|
|
|
|
+ if item['end_time'] > end_time_stamp: # 订单结束时间大于统计时间
|
|
|
|
+ if order_start_time <= start_time_stamp: # 订单月初之前开始
|
|
settlement_days = (end_time - start_time).days # 当月结算天数=月初-月底
|
|
settlement_days = (end_time - start_time).days # 当月结算天数=月初-月底
|
|
- else: # 订单当月开始服务
|
|
|
|
|
|
+ uid_bucket_statistics = UidBucketStatistics.objects.filter(time__gte=start_time_stamp,
|
|
|
|
+ time__lt=end_time_stamp,
|
|
|
|
+ uid=item['uid'])
|
|
|
|
+ elif order_start_time >= end_time_stamp: # 订单在统计时间之后开始
|
|
|
|
+ settlement_days = 1
|
|
|
|
+ uid_bucket_statistics = UidBucketStatistics.objects.filter(time__gte=end_time_stamp,
|
|
|
|
+ time__lt=order_start_time,
|
|
|
|
+ uid=item['uid'])
|
|
|
|
+ else: # 订单月初和统计时间之间开始
|
|
settlement_days = round((end_time_stamp - order_start_time) / 86400)
|
|
settlement_days = round((end_time_stamp - order_start_time) / 86400)
|
|
|
|
+ uid_bucket_statistics = UidBucketStatistics.objects.filter(time__gte=order_start_time,
|
|
|
|
+ time__lt=end_time_stamp,
|
|
|
|
+ uid=item['uid'])
|
|
remaining_usage_time = round((item['end_time'] - end_time_stamp) / 86400) # 剩余使用时间
|
|
remaining_usage_time = round((item['end_time'] - end_time_stamp) / 86400) # 剩余使用时间
|
|
- else: # 订单当月结束
|
|
|
|
|
|
+ else: # 订单结束时间小于统计时间
|
|
if order_start_time <= start_time_stamp:
|
|
if order_start_time <= start_time_stamp:
|
|
settlement_days = round((item['end_time'] - start_time_stamp) / 86400)
|
|
settlement_days = round((item['end_time'] - start_time_stamp) / 86400)
|
|
|
|
+ uid_bucket_statistics = UidBucketStatistics.objects.filter(time__gte=start_time_stamp,
|
|
|
|
+ time__lt=item['end_time'],
|
|
|
|
+ uid=item['uid'])
|
|
else:
|
|
else:
|
|
settlement_days = round((item['end_time'] - order_start_time) / 86400)
|
|
settlement_days = round((item['end_time'] - order_start_time) / 86400)
|
|
|
|
+ uid_bucket_statistics = UidBucketStatistics.objects.filter(time__gte=order_start_time,
|
|
|
|
+ time__lt=item['end_time'],
|
|
|
|
+ uid=item['uid'])
|
|
remaining_usage_time = 0
|
|
remaining_usage_time = 0
|
|
day_average_price = round(price / order_days, 2) # 收入分摊/天
|
|
day_average_price = round(price / order_days, 2) # 收入分摊/天
|
|
month_average_price = round(day_average_price * settlement_days, 2) # 收入分摊/月
|
|
month_average_price = round(day_average_price * settlement_days, 2) # 收入分摊/月
|
|
monthly_income = round((price - fee) / order_days * settlement_days, 2) # 当月结算收入
|
|
monthly_income = round((price - fee) / order_days * settlement_days, 2) # 当月结算收入
|
|
real_income = round(price - fee, 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'],
|
|
|
|
- uid=item['uid'])
|
|
|
|
- else:
|
|
|
|
- uid_bucket_statistics = UidBucketStatistics.objects.filter(time__gte=start_time_stamp,
|
|
|
|
- time__lt=end_time_stamp,
|
|
|
|
- uid=item['uid'])
|
|
|
|
result = uid_bucket_statistics.aggregate(size=Sum('storage_size'), api_count=Sum('api_count'))
|
|
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_storage = round(result['size'], 2) if result['size'] else 0
|
|
actual_api = result['api_count'] if result['api_count'] 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)
|
|
|
|
|
|
+ storage_cost = actual_storage / 1024 * storage_univalence * settlement_days
|
|
|
|
+ api_cost = actual_api * api_univalence
|
|
if CONFIG_INFO == CONFIG_CN: # 国内要换算汇率
|
|
if CONFIG_INFO == CONFIG_CN: # 国内要换算汇率
|
|
- storage_cost = round(storage_cost * 7, 2)
|
|
|
|
- api_cost = round(api_cost * 7, 2)
|
|
|
|
|
|
+ storage_cost = storage_cost * 7
|
|
|
|
+ api_cost = api_cost * 7
|
|
profit = round(monthly_income - storage_cost - api_cost, 2) # 利润=月结算金额-月成本
|
|
profit = round(monthly_income - storage_cost - api_cost, 2) # 利润=月结算金额-月成本
|
|
|
|
+ storage_cost = round(storage_cost, 2)
|
|
|
|
+ api_cost = round(api_cost, 2)
|
|
if monthly_income == 0.0:
|
|
if monthly_income == 0.0:
|
|
profit_margin = 0
|
|
profit_margin = 0
|
|
else:
|
|
else:
|