فهرست منبع

判断影子信息(新增影子加入tb_country字段)

guanhailong 2 سال پیش
والد
کامیت
65d1cc8735
5فایلهای تغییر یافته به همراه41 افزوده شده و 15 حذف شده
  1. 7 2
      Controller/EquipmentManager.py
  2. 7 2
      Controller/EquipmentManagerV2.py
  3. 13 7
      Controller/EquipmentManagerV3.py
  4. 7 2
      Controller/UidSetController.py
  5. 7 2
      Controller/UidUser.py

+ 7 - 2
Controller/EquipmentManager.py

@@ -15,7 +15,7 @@ from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY, BASE_DIR
 from Ansjer.config import PUSH_REDIS_ADDRESS
 from Controller.DetectController import DetectControllerView
 from Model.models import Device_User, Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel, \
-    UIDCompanySerialModel, iotdeviceInfoModel, UidChannelSetModel, LogModel, UnicomDeviceInfo, SysMsgModel
+    UIDCompanySerialModel, iotdeviceInfoModel, UidChannelSetModel, LogModel, UnicomDeviceInfo, SysMsgModel, CountryModel
 from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
@@ -470,6 +470,10 @@ def addInterface(request):
                     # 判断是否有用户绑定
                     nowTime = int(time.time())
                     us_qs = UidSetModel.objects.filter(uid=UID)
+                    ip = CommonService.get_ip_address(request)
+                    ipInfo = CommonService.getIpIpInfo(ip, 'CN')
+                    country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
+                    country = country_qs.exists() if country_qs[0]['id'] else 0
                     if not us_qs.exists():
                         uid_set_create_dict = {
                             'uid': UID,
@@ -479,7 +483,8 @@ def addInterface(request):
                             'channel': ChannelIndex,
                             'nickname': NickName,
                             'version': version,
-                            'device_type': is_bind[0]['Type']
+                            'device_type': is_bind[0]['Type'],
+                            'tb_country': country
                         }
                         UidSetModel.objects.create(**uid_set_create_dict)
                     else:

+ 7 - 2
Controller/EquipmentManagerV2.py

@@ -9,7 +9,7 @@ from django.views.generic.base import View
 
 from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
 from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel, UidChannelSetModel, \
-    iotdeviceInfoModel, UIDModel
+    iotdeviceInfoModel, UIDModel, CountryModel
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
@@ -74,6 +74,10 @@ class EquipmentManagerV2(View):
                     # if is_bind:
                     #     return response.json(15)
                     try:
+                        ip = CommonService.get_ip_address(request)
+                        ipInfo = CommonService.getIpIpInfo(ip, 'CN')
+                        country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
+                        country = country_qs.exists() if country_qs[0]['id'] else 0
                         # 判断是否有用户绑定
                         nowTime = int(time.time())
                         us_qs = UidSetModel.objects.filter(uid=UID)
@@ -85,7 +89,8 @@ class EquipmentManagerV2(View):
                                 'ip': CommonService.get_ip_address(request),
                                 'channel': ChannelIndex,
                                 'nickname': NickName,
-                                'device_type': Type
+                                'device_type': Type,
+                                'tb_country': country
                             }
                             UidSetModel.objects.create(**uid_set_create_dict)
                         else:

+ 13 - 7
Controller/EquipmentManagerV3.py

@@ -175,10 +175,7 @@ class EquipmentManagerV3(View):
                 ip = CommonService.get_ip_address(request)
                 ipInfo = CommonService.getIpIpInfo(ip, 'CN')
                 country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
-                if country_qs.exists():
-                    country = country_qs[0]['id']
-                else:
-                    country = '0'
+                country = country_qs.exists() if country_qs[0]['id'] else 0
                 region_id = Device_Region().get_device_region(ip)
                 region_alexa = 'CN' if region_id == 1 else 'ALL'
                 uid_set_create_dict = {
@@ -409,6 +406,9 @@ class EquipmentManagerV3(View):
                     UidSet_id = us_qs.first().id
                 else:
                     ip = CommonService.get_ip_address(request)
+                    ipInfo = CommonService.getIpIpInfo(ip, 'CN')
+                    country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
+                    country = country_qs.exists() if country_qs[0]['id'] else 0
                     region_id = Device_Region().get_device_region(ip)
                     region_alexa = 'CN' if region_id == 1 else 'ALL'
                     uid_set_create_dict = {
@@ -420,7 +420,8 @@ class EquipmentManagerV3(View):
                         'nickname': NickName,
                         'version': version,
                         'region_alexa': region_alexa,
-                        'device_type': is_bind[0]['Type']
+                        'device_type': is_bind[0]['Type'],
+                        'tb_country': country
                     }
                     UidSet = UidSetModel.objects.create(**uid_set_create_dict)
                     UidSet_id = UidSet.id
@@ -556,16 +557,21 @@ class EquipmentManagerV3(View):
                     if deviceData.__contains__('NickName'):
                         us_qs.update(nickname=nickname)
                 else:
+                    ip = CommonService.get_ip_address(request)
+                    ipInfo = CommonService.getIpIpInfo(ip, 'CN')
+                    country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
+                    country = country_qs.exists() if country_qs[0]['id'] else 0
                     ChannelIndex = qs[0].ChannelIndex
                     nowTime = int(time.time())
                     uid_set_create_dict = {
                         'uid': uid,
                         'addTime': nowTime,
                         'updTime': nowTime,
-                        # 'ip': CommonService.get_ip_address(request),
+                        'ip': CommonService.get_ip_address(request),
                         'channel': ChannelIndex,
                         'nickname': nickname,
-                        'device_type': qs[0].Type
+                        'device_type': qs[0].Type,
+                        'tb_country': country
                     }
                     UidSetModel.objects.create(**uid_set_create_dict)
                 di_qs = Device_Info.objects.filter(UID=uid)

+ 7 - 2
Controller/UidSetController.py

@@ -26,7 +26,7 @@ from django.views.generic.base import View
 
 from Model.models import UidSetModel, Device_User, Device_Info, UidPushModel, Equipment_Info, UID_Preview, UID_Bucket, \
     VodHlsModel, Order_Model, OssCrdModel, UidUserModel, UidChannelSetModel, User_Brand, ExperienceContextModel, \
-    StsCrdModel, Unused_Uid_Meal, UIDMainUser, LogModel
+    StsCrdModel, Unused_Uid_Meal, UIDMainUser, LogModel, CountryModel
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
@@ -339,6 +339,10 @@ class UidSetView(View):
                 di_qs = Device_Info.objects.filter(UID=uid, userID=userID)
                 if di_qs.exists():
                     di = di_qs[0]
+                    ip = CommonService.get_ip_address(request)
+                    ipInfo = CommonService.getIpIpInfo(ip, 'CN')
+                    country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
+                    country = country_qs.exists() if country_qs[0]['id'] else 0
                     nowTime = int(time.time())
                     uid_set_create_dict = {
                         'uid': di.UID,
@@ -347,7 +351,8 @@ class UidSetView(View):
                         'ip': CommonService.get_ip_address(request),
                         'channel': di.ChannelIndex,
                         'nickname': di.NickName,
-                        'device_type': di.Type
+                        'device_type': di.Type,
+                        'tb_country': country
                     }
                     for k, v in deviceData.items():
                         uid_set_create_dict[k] = v

+ 7 - 2
Controller/UidUser.py

@@ -21,7 +21,7 @@ from django.views.decorators.csrf import csrf_exempt
 from django.views.generic.base import View
 
 from Ansjer.config import OSS_STS_ACCESS_SECRET, OSS_STS_ACCESS_KEY
-from Model.models import UID_Bucket, UID_Preview, UidSetModel
+from Model.models import UID_Bucket, UID_Preview, UidSetModel, CountryModel
 from Model.models import UidUserModel
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
@@ -431,6 +431,10 @@ def v3addInterface(request):
                         # 判断影子信息
                         nowTime = int(time.time())
                         us_qs = UidSetModel.objects.filter(uid=UID)
+                        ip = CommonService.get_ip_address(request)
+                        ipInfo = CommonService.getIpIpInfo(ip, 'CN')
+                        country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
+                        country = country_qs.exists() if country_qs[0]['id'] else 0
                         if not us_qs.exists():
                             uid_set_create_dict = {
                                 'uid': UID,
@@ -439,7 +443,8 @@ def v3addInterface(request):
                                 'ip': CommonService.get_ip_address(request),
                                 'channel': ChannelIndex,
                                 'nickname': NickName,
-                                'device_type': Type
+                                'device_type': Type,
+                                'tb_country': country
                             }
                             UidSetModel.objects.create(**uid_set_create_dict)
                     except Exception as e: