瀏覽代碼

初始化 推送状态修正不会变,但token会自动更正

chenjunkai 5 年之前
父節點
當前提交
b41c5c74ab
共有 1 個文件被更改,包括 62 次插入2 次删除
  1. 62 2
      Controller/UserController.py

+ 62 - 2
Controller/UserController.py

@@ -1274,6 +1274,66 @@ class InitInfoView(View):
         # 未读的系统消息
         sm_count = SysMsgModel.objects.filter(userID_id=userID, status=0).count()
 
+        token_val = request_dict.get('token_val', None)
+        m_code = request_dict.get('m_code', None)
+        push_type = request_dict.get('push_type', None)
+        appBundleId = request_dict.get('appBundleId', None)
+        tz = request_dict.get('tz', '0')
+        lang = request_dict.get('lang', '')  # 语言区域
+        # region = request_dict.get('region', '')  # 语言区域
+        nowTime = int(time.time())
+        if all([token_val, push_type, appBundleId]):
+            push_type = int(push_type)
+            if push_type == 0:
+                if appBundleId not in APNS_CONFIG.keys():
+                    return response.json(904)
+            elif push_type == 1:
+                if appBundleId not in FCM_CONFIG.keys():
+                    return response.json(904)
+            elif push_type == 2:
+                if appBundleId not in JPUSH_CONFIG.keys():
+                    return response.json(904)
+            else:
+                return response.json(173)
+            uid_list = ModelService.get_uid_list(userID=userID)
+            if uid_list:
+                # 获取设备推送状态
+                update_dict = {
+                    'token_val': token_val,
+                    'push_type': push_type,
+                    'tz': tz,
+                }
+                # 更新当前用户推送设备状态
+                UidPushModel.objects.filter(userID_id=userID, m_code=m_code,uid_set__detect_status=1).update(**update_dict)
+            if appBundleId:
+                user_extend_qs = UserExtendModel.objects.filter(userID_id=userID)
+                if user_extend_qs.exists():
+                    update_dict = {
+                        'updTime': nowTime,
+                        'appBundleId': appBundleId,
+                        'region': lang
+                        # 'is_cn':
+                    }
+                    user_extend_qs.update(**update_dict)
+                else:
+                    create_dict = {
+                        'addTime': nowTime,
+                        'updTime': nowTime,
+                        'appBundleId': appBundleId,
+                        'userID_id': userID,
+                        'region': lang
+                    }
+                    UserExtendModel.objects.create(**create_dict)
+        res = {
+            'usmsg': sm_count
+        }
+        return response.json(0, res)
+
+    # 初始化设备token
+    def init_uid22(self, request_dict, userID, response):
+        # 未读的系统消息
+        sm_count = SysMsgModel.objects.filter(userID_id=userID, status=0).count()
+
         token_val = request_dict.get('token_val', None)
         m_code = request_dict.get('m_code', None)
         push_type = request_dict.get('push_type', None)
@@ -1304,8 +1364,8 @@ class InitInfoView(View):
             uid_list = ModelService.get_uid_list(userID=userID)
             if uid_list:
                 # 获取设备推送状态
-                uid_set_id_list = UidSetModel.objects.filter(uid__in=uid_list, detect_status=1). \
-                    values_list('id', flat=True)
+                uid_set_id_list = UidSetModel.objects.filter(uid__in=uid_list, detect_status=1).values_list('id',
+                                                                                                            flat=True)
                 if uid_set_id_list:
                     # 批量绑定推送
                     qs_list = []