ソースを参照

新增设备所在国家

zhangdongming 2 年 前
コミット
0222c5c042
1 ファイル変更15 行追加0 行削除
  1. 15 0
      AdminController/AiServeController.py

+ 15 - 0
AdminController/AiServeController.py

@@ -421,6 +421,7 @@ class AiServeView(View):
                 if country_qs.exists():
                     country = country_qs.first()['country_name']
                 data_dict['country'] = country
+                data_dict['deviceCountry'] = self.get_device_country(data_dict['ip'])
                 uid_set_qs = UidSetModel.objects.filter(uid=order['UID']).values('version')
                 data_dict['version'] = uid_set_qs.first()['version'] if uid_set_qs.exists() else ''
                 ai_service_qs = AiService.objects.filter(
@@ -436,6 +437,20 @@ class AiServeView(View):
             print(e)
             return response.json(500, repr(e))
 
+    @staticmethod
+    def get_device_country(ip):
+        """
+        根据IP获取国家名称
+        """
+        if not ip:
+            return '未知国家'
+        ipInfo = CommonService.getIpIpInfo(ip, 'EN')
+        country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
+        if not country_qs.exists():
+            return country_qs[0]['country_name']
+        return '未知国家'
+
+
     def getAiDataList(self, request_dict, response):
         year = request_dict.get('year', None)
         Jan = int(time.mktime(time.strptime(year + '-1-1 00:00:00', "%Y-%m-%d %H:%M:%S")))