|
@@ -150,11 +150,7 @@ class UnicomComboView(View):
|
|
|
"""
|
|
|
logger = logging.getLogger('info')
|
|
|
try:
|
|
|
- flow_key = 'ASJ:UNICOM:FLOW:{}'
|
|
|
now_time = int(time.time())
|
|
|
- today = datetime.datetime.today()
|
|
|
- year = today.year
|
|
|
- month = today.month
|
|
|
unicom_device_info_qs = UnicomDeviceInfo.objects.filter(iccid=iccid)
|
|
|
if not unicom_device_info_qs.exists():
|
|
|
return False
|
|
@@ -184,23 +180,8 @@ class UnicomComboView(View):
|
|
|
UnicomComboExperienceHistory.objects.create(**experience_history_vo)
|
|
|
# 保存套餐激活信息
|
|
|
cls.create_combo_order_info('', 0, iccid, combo_qs['id'])
|
|
|
- usage_data = {'iccid': iccid}
|
|
|
- usage_history = unicom_api.unicom_flow_usage_cache(flow_key.format(iccid), (60 * 10 + 3), **usage_data)
|
|
|
- # 使用流量总历史
|
|
|
- flow_total = 0
|
|
|
- # 当月实际总使用流量
|
|
|
- flow_total_usage = 0
|
|
|
- if usage_history and usage_history['success']:
|
|
|
- device_usage_history_list = usage_history['data']['deviceUsageHistory']
|
|
|
- if device_usage_history_list:
|
|
|
- for item in device_usage_history_list:
|
|
|
- flow_total += float(item['flowTotalUsage'])
|
|
|
- if item['year'] == year and item['month'] == month:
|
|
|
- flow_total_usage = item['flowTotalUsage']
|
|
|
# 修改业务联通卡设备激活信息
|
|
|
- UnicomDeviceInfo.objects.filter(iccid=iccid).update(status=2, updated_time=now_time, year=year, month=month,
|
|
|
- flow_total_usage=str(flow_total_usage),
|
|
|
- before_usage_history=str(flow_total))
|
|
|
+ UnicomDeviceInfo.objects.filter(iccid=iccid).update(status=2, updated_time=now_time)
|
|
|
|
|
|
return True
|
|
|
except Exception as e:
|
|
@@ -471,6 +452,9 @@ class UnicomComboView(View):
|
|
|
logger = logging.getLogger('info')
|
|
|
logger.info('创建联通订单套餐信息,订单id{}'.format(order_id))
|
|
|
try:
|
|
|
+ today = datetime.datetime.today()
|
|
|
+ year = today.year
|
|
|
+ month = today.month
|
|
|
with transaction.atomic():
|
|
|
unicom_combo_qs = UnicomCombo.objects.filter(id=int(combo_id)).values()
|
|
|
if unicom_combo_qs.exists():
|
|
@@ -482,7 +466,8 @@ class UnicomComboView(View):
|
|
|
status = 1
|
|
|
combo_order_data = {'iccid': iccid, 'status': status, 'combo_id': int(combo_id),
|
|
|
'updated_time': now_time,
|
|
|
- 'created_time': now_time}
|
|
|
+ 'created_time': now_time,
|
|
|
+ 'year': year, 'month': month}
|
|
|
if order_id:
|
|
|
combo_order_data['order_id'] = order_id
|
|
|
# 有效期类型 1 等于自然月,0天数
|
|
@@ -495,15 +480,14 @@ class UnicomComboView(View):
|
|
|
combo_order_data['expire_time'] = end_time
|
|
|
combo_order_data['status'] = 0
|
|
|
else:
|
|
|
- zero_today, last_today = LocalDateTimeUtil.get_today_date(True)
|
|
|
start_time, month_end_time = cls.get_month_start_and_end_time()
|
|
|
- combo_order_data['activation_time'] = zero_today
|
|
|
+ combo_order_data['activation_time'] = now_time
|
|
|
combo_order_data['expire_time'] = month_end_time
|
|
|
|
|
|
elif unicom_combo['expiration_type'] == 0:
|
|
|
days = unicom_combo['expiration_days']
|
|
|
zero_today, end_time = cls.get_data_time(days)
|
|
|
- combo_order_data['activation_time'] = zero_today
|
|
|
+ combo_order_data['activation_time'] = now_time
|
|
|
combo_order_data['expire_time'] = end_time
|
|
|
# 联通业务逻辑
|
|
|
unicom_api = UnicomObjeect()
|
|
@@ -515,7 +499,9 @@ class UnicomComboView(View):
|
|
|
if res_dict and res_dict['data']['status'] != 1:
|
|
|
re_data = {"iccid": iccid, "status": 1}
|
|
|
unicom_api.update_device_state(**re_data)
|
|
|
- UnicomComboOrderInfo.objects.create(**combo_order_data)
|
|
|
+ flow_total_usage = unicom_api.get_flow_usage_total(year, month, iccid)
|
|
|
+ combo_order_data['flow_total_usage'] = str(flow_total_usage)
|
|
|
+ UnicomComboOrderInfo.objects.create(**combo_order_data)
|
|
|
logger.info('保存信息success')
|
|
|
return True
|
|
|
except Exception as e:
|