Browse Source

修改查找ip地区的逻辑3

tanghongbin 4 years ago
parent
commit
305c2b152f
2 changed files with 7 additions and 4 deletions
  1. 5 4
      Controller/UserController.py
  2. 2 0
      Model/models.py

+ 5 - 4
Controller/UserController.py

@@ -3644,7 +3644,7 @@ def delete_local_account(username):
 
 
 def updateUserCountry(request):
-    country_ip_qs = CountryIPModel.objects.filter()
+    country_ip_qs = CountryIPModel.objects.filter(status=0)
     if country_ip_qs.exists():
         country_ip_qs = country_ip_qs[0: 100].values()
         ids = []
@@ -3658,8 +3658,9 @@ def updateUserCountry(request):
                 country = CommonService.getAddr(country_ip['ip'])
                 redisObject.set_data(key=key, val=country, expire=3600)
 
-            UserExModel.objects.filter(id=country_ip['user_ex_id']).update(country=country)
-            ids.append(country_ip['id'])
-        CountryIPModel.objects.filter(id__in=tuple(ids)).delete()
+            country_ip['country'] = country
+            CountryIPModel.objects.filter(id=country_ip['id']).update(country=country, status=1)
+            # ids.append(country_ip['id'])
+        # CountryIPModel.objects.filter(id__in=tuple(ids)).update(status=1)
     response = ResponseObject()
     return response.json(0)

+ 2 - 0
Model/models.py

@@ -1002,6 +1002,8 @@ class CountryIPModel(models.Model):
     id = models.AutoField(primary_key=True)
     ip = models.CharField(default='', max_length=32, verbose_name='ip')
     user_ex = models.ForeignKey(UserExModel, to_field='id', on_delete=models.CASCADE, verbose_name='关联用户扩展信息表id')
+    country = models.CharField(default='', max_length=100, verbose_name='国家')
+    status = models.SmallIntegerField(default=0, verbose_name='是否已经查找,0:否,1:是')
     add_time = models.IntegerField(default=0, verbose_name='添加时间')
 
     class Meta: