|
@@ -8,6 +8,7 @@
|
|
|
"""
|
|
|
import datetime
|
|
|
import logging
|
|
|
+import threading
|
|
|
import time
|
|
|
from decimal import Decimal
|
|
|
|
|
@@ -19,6 +20,8 @@ from Model.models import UnicomComboOrderInfo, UnicomCombo, Order_Model, UnicomD
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.UnicomObject import UnicomObjeect
|
|
|
|
|
|
+logger = logging.getLogger('info')
|
|
|
+
|
|
|
|
|
|
class UnicomComboTaskView(View):
|
|
|
|
|
@@ -56,7 +59,6 @@ class UnicomComboTaskView(View):
|
|
|
@param response:
|
|
|
@return:
|
|
|
"""
|
|
|
- logger = logging.getLogger('info')
|
|
|
print(request_dict)
|
|
|
logger.info('--->进入监控次月激活联通套餐')
|
|
|
now_time = int(time.time())
|
|
@@ -106,7 +108,6 @@ class UnicomComboTaskView(View):
|
|
|
检查流量使用情况
|
|
|
@return:
|
|
|
"""
|
|
|
- logger = logging.getLogger('info')
|
|
|
logger.info('--->进入监控流量使用情况')
|
|
|
try:
|
|
|
unicom_api = UnicomObjeect()
|
|
@@ -171,7 +172,6 @@ class UnicomComboTaskView(View):
|
|
|
@param flow_usage: 套餐已使用流量
|
|
|
@return:
|
|
|
"""
|
|
|
- logger = logging.getLogger('info')
|
|
|
try:
|
|
|
if not app_user_id:
|
|
|
return False
|
|
@@ -204,7 +204,6 @@ class UnicomComboTaskView(View):
|
|
|
@param usage_flow:
|
|
|
@return:
|
|
|
"""
|
|
|
- logger = logging.getLogger('info')
|
|
|
try:
|
|
|
now_time = int(time.time())
|
|
|
combo_order_qs = UnicomComboOrderInfo.objects \
|
|
@@ -224,12 +223,16 @@ class UnicomComboTaskView(View):
|
|
|
'year': year,
|
|
|
'month': month,
|
|
|
'flow_total_usage': str(usage_flow),
|
|
|
+ 'activation_time': now_time,
|
|
|
'updated_time': now_time,
|
|
|
}
|
|
|
UnicomComboOrderInfo.objects.filter(id=combo_order.id).update(**upd_data)
|
|
|
+ asy = threading.Thread(target=UnicomComboTaskView.async_combo_sys_msg_push,
|
|
|
+ args=(iccid, combo_order.id, 3))
|
|
|
+ asy.start()
|
|
|
return True
|
|
|
except Exception as e:
|
|
|
- logger.info('出错了~检测流量用量详情异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ logger.info('出错了~激活套餐,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return False
|
|
|
|
|
|
@classmethod
|
|
@@ -239,7 +242,6 @@ class UnicomComboTaskView(View):
|
|
|
@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,
|
|
@@ -257,7 +259,7 @@ class UnicomComboTaskView(View):
|
|
|
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)
|
|
|
+ UnicomComboOrderInfo.objects.filter(id=item['id']).update(status=2, updated_time=now_time)
|
|
|
iccid_list.append(icc_id)
|
|
|
logger.info('--->当前流量套餐已过期,iccid:{}'.format(icc_id))
|
|
|
except Exception as e:
|
|
@@ -276,6 +278,32 @@ class UnicomComboTaskView(View):
|
|
|
if not result:
|
|
|
# 停用设备
|
|
|
unicom_api.change_device_to_disable(item)
|
|
|
+ combo_order_info_qs = UnicomComboOrderInfo.objects.filter(iccid=item, status=2) \
|
|
|
+ .values('id').order_by('-updated_time')
|
|
|
+ combo_order = combo_order_info_qs.first()
|
|
|
+ asy = threading.Thread(target=UnicomComboTaskView.async_combo_sys_msg_push,
|
|
|
+ args=(icc_id, combo_order['id'], 4))
|
|
|
+ asy.start()
|
|
|
else:
|
|
|
unicom_api.change_device_to_activate(item)
|
|
|
return response.json(0)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def async_combo_sys_msg_push(iccid, combo_order_id, push_type):
|
|
|
+ """
|
|
|
+ 异步保存消息推送 激活|过期
|
|
|
+ @param iccid:
|
|
|
+ @param combo_order_id:
|
|
|
+ @param push_type:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ now_time = int(time.time())
|
|
|
+ ud_info_qs = UnicomDeviceInfo.objects.filter(iccid=iccid).values('serial_no', 'user_id')
|
|
|
+ push_data = {'combo_order_id': str(combo_order_id), 'serial_no': ud_info_qs.first()['serial_no'],
|
|
|
+ 'status': 0, 'type': push_type,
|
|
|
+ 'updated_time': now_time,
|
|
|
+ 'created_time': now_time, 'user_id': ud_info_qs.first()['user_id']}
|
|
|
+ UnicomFlowPush.objects.create(**push_data)
|
|
|
+ except Exception as e:
|
|
|
+ logger.info('-->出错了~,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|