瀏覽代碼

修复重复新增推送手机信息问题

peng 2 年之前
父節點
當前提交
f2a1183443
共有 1 個文件被更改,包括 28 次插入15 次删除
  1. 28 15
      Controller/DetectControllerV2.py

+ 28 - 15
Controller/DetectControllerV2.py

@@ -161,21 +161,34 @@ class DetectControllerViewV2(View):
 
             # 初始化UidPushModel推送表
             if electricity_status:
-                uid_push_create_dict = {
-                    'uid_set_id': uid_set_id,
-                    'userID_id': userID,
-                    'appBundleId': appBundleId,
-                    'app_type': app_type,
-                    'push_type': push_type,
-                    'token_val': token_val,
-                    'm_code': m_code,
-                    'addTime': nowTime,
-                    'updTime': nowTime,
-                    'lang': lang,
-                    'tz': tz
-                }
-                # 绑定设备推送
-                UidPushModel.objects.create(**uid_push_create_dict)
+                uid_push_qs = UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid)
+                if uid_push_qs.exists():
+                    uid_push_update_dict = {
+                        'appBundleId': appBundleId,
+                        'app_type': app_type,
+                        'push_type': push_type,
+                        'token_val': token_val,
+                        'updTime': nowTime,
+                        'lang': lang,
+                        'tz': tz
+                    }
+                    uid_push_qs.update(**uid_push_update_dict)
+                else:
+                    uid_push_create_dict = {
+                        'uid_set_id': uid_set_id,
+                        'userID_id': userID,
+                        'appBundleId': appBundleId,
+                        'app_type': app_type,
+                        'push_type': push_type,
+                        'token_val': token_val,
+                        'm_code': m_code,
+                        'addTime': nowTime,
+                        'updTime': nowTime,
+                        'lang': lang,
+                        'tz': tz
+                    }
+                    # 绑定设备推送
+                    UidPushModel.objects.create(**uid_push_create_dict)
                 return response.json(0)
 
             if status == 0: