Explorar o código

定时检测流量接口加打印,注册时存在推送配置则修改tokenVal

zhangdongming %!s(int64=3) %!d(string=hai) anos
pai
achega
88f8578fee

+ 8 - 6
Controller/UnicomCombo/UnicomComboTaskController.py

@@ -54,7 +54,7 @@ class UnicomComboTaskView(View):
         """
         logger = logging.getLogger('info')
         print(request_dict)
-        logger.info('定时检查是否有次月激活联通套餐')
+        logger.info('--->定时检查是否有次月激活联通套餐')
         now_time = int(time.time())
         combo_order_info_qs = UnicomComboOrderInfo.objects.filter(status=0, next_month_activate=True,
                                                                   activation_time__lte=now_time,
@@ -82,6 +82,7 @@ class UnicomComboTaskView(View):
                         combo_qs = UnicomCombo.objects.filter(id=combo_id).values()
                         if not combo_qs.exists():
                             continue
+                        # 查询当月用量情况
                         flow_total_usage = unicom_api.get_flow_usage_total(year, month, item['iccid'])
                         flow_total_usage = str(flow_total_usage)
                         iccid = item['iccid']
@@ -103,9 +104,9 @@ class UnicomComboTaskView(View):
         @return:
         """
         logger = logging.getLogger('info')
-        logger.info('进入检查流量使用情况')
+        logger.info('--->进入检查流量使用情况')
         try:
-            combo_order_qs = UnicomComboOrderInfo.objects.filter(status=1).values()
+            combo_order_qs = UnicomComboOrderInfo.objects.filter(status=1, is_del=False).values()
             if not combo_order_qs.exists():
                 return response.json(0)
             today = datetime.datetime.today()
@@ -123,6 +124,8 @@ class UnicomComboTaskView(View):
                     flow_total = combo_qs['flow_total']
                     # 查询当前月用量历史
                     month_usage_flow = unicom_api.get_flow_usage_total(year, month, iccid)
+                    logger.info('--->{}-{},iccid:{};套餐总值:{},激活时当月用量值:{},月已用量:{}'
+                                .format(year, month, iccid, flow_total, usage_flow, month_usage_flow))
                     is_expire = False
                     if item['year'] == year and item['month'] == month:
                         if month_usage_flow > 0:
@@ -139,7 +142,6 @@ class UnicomComboTaskView(View):
                         actual_usage_flow = last_usage_flow - usage_flow
                         # 剩余
                         surplus_flow = flow_total - actual_usage_flow
-                        # result = Decimal(surplus_flow).quantize(Decimal('0.00'))
                         if month_usage_flow > 0:
                             if month_usage_flow >= surplus_flow:
                                 is_expire = True
@@ -154,7 +156,7 @@ class UnicomComboTaskView(View):
 
             return response.json(0)
         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 response.json(177, repr(e))
 
     @staticmethod
@@ -170,7 +172,7 @@ class UnicomComboTaskView(View):
         try:
             now_time = int(time.time())
             combo_order_qs = UnicomComboOrderInfo.objects.filter(expire_time__gt=now_time, status=0,
-                                                                 iccid=iccid).order_by(
+                                                                 next_month_activate=False, iccid=iccid).order_by(
                 'created_time')
             if not combo_order_qs.exists():
                 return False

+ 23 - 19
Controller/UserController.py

@@ -291,6 +291,7 @@ class registerView(TemplateView):
         else:
             return response.json(109)
 
+
 # 登出
 class LogoutView(TemplateView):
     @method_decorator(csrf_exempt)
@@ -705,7 +706,7 @@ class refreshTokenViewV3(TemplateView):
             userID = tko.userID
             tko.lang = lang
 
-            if password:     # 检验密码
+            if password:  # 检验密码
                 password = password.strip()
                 # 解密
                 for i in range(1, 4):
@@ -899,8 +900,8 @@ class v2authCodeView(TemplateView):
             msg = res["Message"]
             if code == "isv.MOBILE_NUMBER_ILLEGAL":
                 if response.lang == "cn":
-                    msg = phone+"非法手机"
-            return response.json(10,msg)
+                    msg = phone + "非法手机"
+            return response.json(10, msg)
 
     def phoneCodeV2(self, country_code, phone, response, sign_name):
         dataValid = DataValid()
@@ -2001,7 +2002,8 @@ class v3LoginView(TemplateView):
             user_qs.update(subscribe_email=subscribe)
 
         users = user_qs.values('role__rid', 'role__roleName', 'userID', 'NickName', 'username', 'userEmail',
-                               'phone', 'password', 'userIconPath', 'fingerprint_enable', 'fingerprint_key', 'subscribe_email')[0]
+                               'phone', 'password', 'userIconPath', 'fingerprint_enable', 'fingerprint_key',
+                               'subscribe_email')[0]
         if not check_password(password, users['password']):
             return response.json(111)
 
@@ -2028,7 +2030,7 @@ class v3LoginView(TemplateView):
         if all([app_bundle_id, app_type, push_type, token_val, m_code, tz]):
             gateway_push_qs = GatewayPush.objects.filter(user_id=userID, m_code=m_code)
             if gateway_push_qs.exists():
-                gateway_push_qs.update(logout=False)
+                gateway_push_qs.update(token_val=token_val, logout=False)
             else:
                 GatewayPush.objects.create(user_id=userID, app_bundle_id=app_bundle_id, app_type=app_type,
                                            push_type=push_type, token_val=token_val, m_code=m_code, lang=lang, tz=tz)
@@ -2088,7 +2090,8 @@ class oneClickLoginView(TemplateView):
             if not phone:
                 return response.json(102)
 
-            user_qs = Device_User.objects.filter(phone=phone).values('userID', 'username', 'NickName', 'phone', 'password')
+            user_qs = Device_User.objects.filter(phone=phone).values('userID', 'username', 'NickName', 'phone',
+                                                                     'password')
             # 用户已存在的响应
             if user_qs.exists():
                 tokenObj = TokenObject()
@@ -3076,7 +3079,8 @@ class alexaUidView(TemplateView):
                 uid_list.append(UID)
                 uid_dict[UID] = {'nick': uid_q['NickName'], 'password': uid_q['View_Password']}
 
-            us_qs = UidSetModel.objects.filter(uid__in=uid_list, is_alexa=1).values('id', 'uid', 'region_alexa', 'channel')
+            us_qs = UidSetModel.objects.filter(uid__in=uid_list, is_alexa=1).values('id', 'uid', 'region_alexa',
+                                                                                    'channel')
             if not us_qs.exists():
                 return response.json(173)
             # uid,password,region的列表
@@ -3091,7 +3095,8 @@ class alexaUidView(TemplateView):
 
                 # 多通道设备获取通道名
                 if channel > 1:
-                    uid_channel_set_qs = UidChannelSetModel.objects.filter(uid_id=us['id']).values('channel', 'channel_name')
+                    uid_channel_set_qs = UidChannelSetModel.objects.filter(uid_id=us['id']).values('channel',
+                                                                                                   'channel_name')
                     if uid_channel_set_qs.exists():
                         # DVR设备名为 UidChannelSetModel 的 channel_name
                         for uid_channel_set in uid_channel_set_qs:
@@ -3108,6 +3113,7 @@ class alexaUidView(TemplateView):
         except Exception as e:
             return response.json(500, repr(e))
 
+
 # 登出
 class V2LogoutView(TemplateView):
     @method_decorator(csrf_exempt)
@@ -3614,7 +3620,6 @@ class v3LoginByCodeView(View):
         if oauth_qs.exists():
             auth_type = oauth_qs[0].authType
 
-
         if tko.code == 0:
             now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
             user_qs.update(last_login=now_time, language=response.lang)
@@ -4069,6 +4074,7 @@ def updateUserCountry(request):
     response = ResponseObject()
     return response.json(0)
 
+
 def confirmRegion(request):
     response = ResponseObject()
     request.encoding = 'utf-8'
@@ -4079,17 +4085,17 @@ def confirmRegion(request):
     number = request.POST.get('number', None)
     selectRegion = CountryModel.objects.filter(number=number).values('region__api')
     if not selectRegion.exists():
-        return response.json(0,{"request_url":"https://www.dvema.com"})
+        return response.json(0, {"request_url": "https://www.dvema.com"})
     else:
-        return response.json(0,{"request_url":selectRegion[0]['region__api']})
+        return response.json(0, {"request_url": selectRegion[0]['region__api']})
 
 
 def deleteAccount(request):
     response = ResponseObject()
     request.encoding = 'utf-8'
-    #test
-    token = request.POST.get('token',None)
-    password = request.POST.get('userPwd',None)
+    # test
+    token = request.POST.get('token', None)
+    password = request.POST.get('userPwd', None)
     try:
         for i in range(1, 4):
             if i == 1:
@@ -4135,8 +4141,8 @@ def deleteAccount(request):
         if hasDevices.exists():
             return response.json(10047)
 
-        orderUserIds = Order_Model.objects.filter(userID=userID,status=1).values_list('UID').distinct().order_by("UID")
-        hadUseSevice = UID_Bucket.objects.filter(uid__in=orderUserIds,use_status=1)
+        orderUserIds = Order_Model.objects.filter(userID=userID, status=1).values_list('UID').distinct().order_by("UID")
+        hadUseSevice = UID_Bucket.objects.filter(uid__in=orderUserIds, use_status=1)
         if hadUseSevice.exists():
             return response.json(10046)
 
@@ -4183,7 +4189,7 @@ class InitUserInformationView(View):
             now_time = int(time.time())
             if user_ex_qs.exists():
                 update = {
-                    'appBundleId':appBundleId,
+                    'appBundleId': appBundleId,
                     'updTime': now_time
                 }
                 user_ex_qs.update(**update)
@@ -4194,5 +4200,3 @@ class InitUserInformationView(View):
             return response.json(0)
         else:
             return response.json(444)
-
-