|
@@ -13,7 +13,8 @@ import traceback
|
|
|
from django.db.models import Q
|
|
|
from django.views import View
|
|
|
|
|
|
-from Model.models import UnicomComboOrderInfo, UnicomDeviceInfo, GatewayPush, SysMsgModel, UnicomFlowPush, Device_User
|
|
|
+from Model.models import UnicomComboOrderInfo, UnicomDeviceInfo, GatewayPush, SysMsgModel, UnicomFlowPush, Device_User, \
|
|
|
+ Device_Info
|
|
|
from Object.AliyunSmsObject import AliyunSmsObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
|
|
@@ -150,15 +151,20 @@ class ComboCronPushView(View):
|
|
|
user_id = item.user_id
|
|
|
if not user_id:
|
|
|
continue
|
|
|
- user_push_qs = GatewayPush.objects.filter(user_id=user_id)
|
|
|
- if not user_push_qs:
|
|
|
+ device_info_qs = Device_Info.objects.filter(userID_id=user_id, serial_number=item.serial_no) \
|
|
|
+ .values('userID__phone', 'Type')
|
|
|
+ if not device_info_qs.exists():
|
|
|
+ logger.info('推送4G通知设备未被当前客户添加:{},serial:{}'.format(user_id, item.serial_no))
|
|
|
continue
|
|
|
now_time = int(time.time())
|
|
|
+
|
|
|
# 查询推送配置数据
|
|
|
- push_qs = GatewayPush.objects.filter(user_id=user_id, logout=False). \
|
|
|
- values('user_id', 'app_bundle_id', 'app_type', 'push_type', 'token_val', 'm_code', 'lang', 'tz')
|
|
|
- if not push_qs.exists():
|
|
|
- continue
|
|
|
+ push_qs = GatewayPush.objects.filter(user_id=user_id, logout=False).values('user_id', 'app_bundle_id',
|
|
|
+ 'app_type', 'push_type',
|
|
|
+ 'token_val', 'm_code',
|
|
|
+ 'lang', 'tz').order_by(
|
|
|
+ '-id')[:5]
|
|
|
+
|
|
|
usage = cls.flow_split(item.flow_total_usage)
|
|
|
total = cls.flow_split(item.flow_total)
|
|
|
usable = cls.flow_split(item.flow_total - item.flow_total_usage)
|
|
@@ -170,12 +176,20 @@ class ComboCronPushView(View):
|
|
|
sys_msg = cls.get_sys_msg_text(item.serial_no, combo_name, item.type)
|
|
|
msg = True
|
|
|
else:
|
|
|
- user_qs = Device_User.objects.filter(userID=user_id).values('phone')
|
|
|
- if user_qs.exists() and user_qs.first()['phone']:
|
|
|
+ if device_info_qs['userID__phone']:
|
|
|
params = u'{"devname":"' + item.serial_no + '","usage":"流量' + usage + '","usable":"流量' + \
|
|
|
usable + '","total":"流量共' + total + '"}'
|
|
|
- cls.send_aliyun_sms(user_qs.first()['phone'], params, 'SMS_246100414')
|
|
|
- sys_msg = cls.get_msg_text(item.serial_no, push_qs[0]['lang'], total, usage, usable)
|
|
|
+ cls.send_aliyun_sms(device_info_qs['userID__phone'], params, 'SMS_246100414')
|
|
|
+ lang = push_qs[0]['lang'] if push_qs.exists() else 'cn'
|
|
|
+ sys_msg = cls.get_msg_text(item.serial_no, lang, total, usage, usable)
|
|
|
+
|
|
|
+ cls.sys_msg_save(user_id, item.serial_no, now_time, sys_msg)
|
|
|
+ # 修改推送状态
|
|
|
+ UnicomFlowPush.objects.filter(id=item.id).update(status=1)
|
|
|
+ if not push_qs.exists():
|
|
|
+ logger.info('推送4G通知APP未登录:{},serial:{}'.format(user_id, item.serial_no))
|
|
|
+ continue
|
|
|
+
|
|
|
for push_vo in push_qs:
|
|
|
kwargs = {
|
|
|
'n_time': now_time,
|
|
@@ -196,11 +210,9 @@ class ComboCronPushView(View):
|
|
|
kwargs['msg_text'] = sys_msg_text
|
|
|
if not cls.msg_push(push_type, **kwargs):
|
|
|
continue
|
|
|
- cls.sys_msg_save(user_id, item.serial_no, now_time, sys_msg)
|
|
|
- # 修改推送状态
|
|
|
- UnicomFlowPush.objects.filter(id=item.id).update(status=1)
|
|
|
+
|
|
|
except Exception as e:
|
|
|
- logger.info('出错了~4G流量推送消息异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ logger.info('推送4G通知消息异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
continue
|
|
|
return response.json(0)
|
|
|
|