|
@@ -140,7 +140,20 @@ class ComboCronPushView(View):
|
|
@classmethod
|
|
@classmethod
|
|
def flow_warning_push(cls, response):
|
|
def flow_warning_push(cls, response):
|
|
"""
|
|
"""
|
|
- 流量到期或者流量预警消息推送
|
|
|
|
|
|
+ 处理流量到期或使用量预警的消息推送
|
|
|
|
+
|
|
|
|
+ 流程说明:
|
|
|
|
+ 1. 查询所有待处理的流量推送通知
|
|
|
|
+ 2. 遍历每个通知,校验设备及用户信息
|
|
|
|
+ 3. 计算流量使用情况,检查关联套餐
|
|
|
|
+ 4. 生成推送消息内容,通过短信和系统消息推送
|
|
|
|
+ 5. 更新通知状态,记录推送日志
|
|
|
|
+
|
|
|
|
+ Args:
|
|
|
|
+ response: 响应对象,用于返回处理结果
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ response.json(0): 固定返回成功响应
|
|
"""
|
|
"""
|
|
logger = logging.getLogger('info')
|
|
logger = logging.getLogger('info')
|
|
flow_push_qs = UnicomFlowPush.objects.filter(status=0)
|
|
flow_push_qs = UnicomFlowPush.objects.filter(status=0)
|
|
@@ -158,28 +171,35 @@ class ComboCronPushView(View):
|
|
continue
|
|
continue
|
|
now_time = int(time.time())
|
|
now_time = int(time.time())
|
|
|
|
|
|
|
|
+ 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)
|
|
|
|
+ # 查询当前套餐并且套餐类型不等于长期无限流量
|
|
|
|
+ unicom_order_qs = UnicomComboOrderInfo.objects.filter(id=item.combo_order_id).exclude(combo_id=33) \
|
|
|
|
+ .values('combo__combo_name')
|
|
|
|
+ if unicom_order_qs.exists():
|
|
|
|
+ logger.info(f'推送4G通知套餐订单不存在或长期无限流量不通知:{item.combo_order_id}')
|
|
|
|
+ UnicomFlowPush.objects.filter(id=item.id).update(status=1, updated_time=now_time)
|
|
|
|
+ continue
|
|
|
|
+
|
|
# 查询推送配置数据
|
|
# 查询推送配置数据
|
|
- push_qs = GatewayPush.objects.filter(user_id=user_id, logout=False).values('user_id', 'app_bundle_id',
|
|
|
|
|
|
+ push_qs = GatewayPush.objects.filter(user_id=user_id, logout=False).values('user_id',
|
|
|
|
+ 'app_bundle_id',
|
|
'app_type', 'push_type',
|
|
'app_type', 'push_type',
|
|
'token_val', 'm_code',
|
|
'token_val', 'm_code',
|
|
'lang', 'tz').order_by(
|
|
'lang', 'tz').order_by(
|
|
'-id')[:5]
|
|
'-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)
|
|
|
|
msg = False
|
|
msg = False
|
|
- if item.type != 0 and item.type != 1:
|
|
|
|
- unicom_order_qs = UnicomComboOrderInfo.objects.filter(id=item.combo_order_id) \
|
|
|
|
- .values('combo__combo_name')
|
|
|
|
|
|
+ if item.type != 0 and item.type != 1: # 不等于流量预警通知并且不等于流量到期
|
|
combo_name = unicom_order_qs.first()['combo__combo_name'] if unicom_order_qs.exists() else ''
|
|
combo_name = unicom_order_qs.first()['combo__combo_name'] if unicom_order_qs.exists() else ''
|
|
sys_msg = cls.get_sys_msg_text(item.serial_no, combo_name, item.type)
|
|
sys_msg = cls.get_sys_msg_text(item.serial_no, combo_name, item.type)
|
|
msg = True
|
|
msg = True
|
|
|
|
+
|
|
else:
|
|
else:
|
|
- if device_info_qs['userID__phone']:
|
|
|
|
|
|
+ if device_info_qs[0]['userID__phone']:
|
|
params = u'{"devname":"' + item.serial_no + '","usage":"流量' + usage + '","usable":"流量' + \
|
|
params = u'{"devname":"' + item.serial_no + '","usage":"流量' + usage + '","usable":"流量' + \
|
|
usable + '","total":"流量共' + total + '"}'
|
|
usable + '","total":"流量共' + total + '"}'
|
|
- cls.send_aliyun_sms(device_info_qs['userID__phone'], params, 'SMS_246100414')
|
|
|
|
|
|
+ cls.send_aliyun_sms(device_info_qs[0]['userID__phone'], params, 'SMS_246100414')
|
|
lang = push_qs[0]['lang'] if push_qs.exists() else 'cn'
|
|
lang = push_qs[0]['lang'] if push_qs.exists() else 'cn'
|
|
sys_msg = cls.get_msg_text(item.serial_no, lang, total, usage, usable)
|
|
sys_msg = cls.get_msg_text(item.serial_no, lang, total, usage, usable)
|
|
|
|
|