|
@@ -11,9 +11,10 @@ import logging
|
|
|
import time
|
|
|
|
|
|
from django.db import transaction
|
|
|
+from django.db.models import Q
|
|
|
from django.views import View
|
|
|
|
|
|
-from Model.models import UnicomComboOrderInfo, UnicomCombo, Order_Model
|
|
|
+from Model.models import UnicomComboOrderInfo, UnicomCombo, Order_Model, UnicomDeviceInfo
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.UnicomObject import UnicomObjeect
|
|
|
|
|
@@ -37,6 +38,8 @@ class UnicomComboTaskView(View):
|
|
|
return self.check_activate_combo(request_dict, response)
|
|
|
elif operation == 'check-flow':
|
|
|
return self.check_flow_usage(response)
|
|
|
+ elif operation == 'check-flow-expire':
|
|
|
+ return self.check_flow_expire(response)
|
|
|
elif operation == 'check-expire':
|
|
|
today = datetime.datetime.today()
|
|
|
year = today.year
|
|
@@ -62,7 +65,6 @@ class UnicomComboTaskView(View):
|
|
|
if not combo_order_info_qs.exists():
|
|
|
return response.json(0)
|
|
|
try:
|
|
|
- now_time = int(time.time())
|
|
|
today = datetime.datetime.today()
|
|
|
year = today.year
|
|
|
month = today.month
|
|
@@ -88,9 +90,7 @@ class UnicomComboTaskView(View):
|
|
|
iccid = item['iccid']
|
|
|
# 检查激活iccid
|
|
|
unicom_api.change_device_to_activate(iccid)
|
|
|
- UnicomComboOrderInfo.objects.filter(id=item['id']) \
|
|
|
- .update(status=1, updated_time=now_time, year=year, month=month,
|
|
|
- flow_total_usage=flow_total_usage)
|
|
|
+ cls.query_unused_combo_and_activate(iccid, year, month, flow_total_usage)
|
|
|
logger.info('激活成功,订单编号:{}'.format(order_id))
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
@@ -172,13 +172,18 @@ class UnicomComboTaskView(View):
|
|
|
logger = logging.getLogger('info')
|
|
|
try:
|
|
|
now_time = int(time.time())
|
|
|
- combo_order_qs = UnicomComboOrderInfo.objects.filter(expire_time__gt=now_time, status=0,
|
|
|
- next_month_activate=False, iccid=iccid).order_by(
|
|
|
- 'created_time')
|
|
|
+ combo_order_qs = UnicomComboOrderInfo.objects \
|
|
|
+ .filter(expire_time__gt=now_time, activation_time__lte=now_time, status=0, iccid=iccid) \
|
|
|
+ .order_by('created_time')
|
|
|
if not combo_order_qs.exists():
|
|
|
return False
|
|
|
|
|
|
combo_order = combo_order_qs.first()
|
|
|
+ if not combo_order.order_id:
|
|
|
+ return False
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=combo_order.order_id, status=1)
|
|
|
+ if not order_qs.exists():
|
|
|
+ return False
|
|
|
upd_data = {
|
|
|
'status': 1,
|
|
|
'year': year,
|
|
@@ -191,3 +196,49 @@ class UnicomComboTaskView(View):
|
|
|
except Exception as e:
|
|
|
logger.info('检测流量用量详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return False
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def check_flow_expire(cls, response):
|
|
|
+ """
|
|
|
+ 检查流量到期停卡操作
|
|
|
+ @param response:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ logger = logging.getLogger('info')
|
|
|
+ logger.info('--->进入监控流量到期停卡或激活叠加包')
|
|
|
+ now_time = int(time.time())
|
|
|
+ combo_order_qs = UnicomComboOrderInfo.objects.filter(~Q(status=2), expire_time__lte=now_time,
|
|
|
+ is_del=False).values()
|
|
|
+ today = datetime.datetime.today()
|
|
|
+ year = today.year
|
|
|
+ month = today.month
|
|
|
+ if not combo_order_qs.exists():
|
|
|
+ return response.json(0)
|
|
|
+ iccid_list = []
|
|
|
+ with transaction.atomic():
|
|
|
+ for item in combo_order_qs:
|
|
|
+ try:
|
|
|
+ icc_id = item['iccid']
|
|
|
+ um_device_qs = UnicomDeviceInfo.objects.filter(iccid=icc_id)
|
|
|
+ if not um_device_qs.exists():
|
|
|
+ continue
|
|
|
+ UnicomComboOrderInfo.objects.filter(id=item['id']).update(status=2)
|
|
|
+ iccid_list.append(icc_id)
|
|
|
+ logger.info('--->当前流量套餐已过期,iccid:{}'.format(icc_id))
|
|
|
+ except Exception as e:
|
|
|
+ logger.info('监控流量到期异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ continue
|
|
|
+ # set无序不重复元素集
|
|
|
+ iccid_list = list(set(iccid_list))
|
|
|
+ unicom_api = UnicomObjeect()
|
|
|
+ for item in iccid_list:
|
|
|
+ activate_combo_qs = UnicomComboOrderInfo.objects.filter(iccid=item, status=1, expire_time__gt=now_time,
|
|
|
+ is_del=False).values()
|
|
|
+ if activate_combo_qs.exists():
|
|
|
+ continue
|
|
|
+ usage_flow = unicom_api.get_flow_usage_total(year, month, item)
|
|
|
+ result = cls.query_unused_combo_and_activate(item, year, month, usage_flow)
|
|
|
+ if not result:
|
|
|
+ # 停用设备
|
|
|
+ unicom_api.change_device_to_disable(item)
|
|
|
+ return response.json(0)
|