Browse Source

新增ip返回状态接口adStatus限定珠海市

linhaohong 1 year ago
parent
commit
b5d390ea8a
1 changed files with 44 additions and 4 deletions
  1. 44 4
      Controller/AppSetController.py

+ 44 - 4
Controller/AppSetController.py

@@ -7,11 +7,13 @@ from django.views.generic.base import View
 
 from Ansjer.config import SERVER_TYPE
 from Model.models import AppSetModel, PromotionRuleModel, PopupsConfig, RedDotsConfig, Device_Info, UidSetModel, \
-    UserOperationLog, Order_Model
+    UserOperationLog, Order_Model, IPAddr
+from Object.IPWeatherObject import IPQuery
 from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.utils import LocalDateTimeUtil
+from Service.CommonService import CommonService
 from Service.ModelService import ModelService
 
 LOGGER = logging.getLogger('info')
@@ -21,14 +23,14 @@ class AppSetView(View):
     def get(self, request, *args, **kwargs):
         request.encoding = 'utf-8'
         operation = kwargs.get('operation', None)
-        return self.validation(request.GET, operation)
+        return self.validation(request.GET, request, operation)
 
     def post(self, request, *args, **kwargs):
         request.encoding = 'utf-8'
         operation = kwargs.get('operation', None)
-        return self.validation(request.POST, operation)
+        return self.validation(request.POST, request, operation)
 
-    def validation(self, request_dict, operation):
+    def validation(self, request_dict, request, operation):
         response = ResponseObject()
         if operation == 'query':
             return self.do_query(request_dict, response)
@@ -45,6 +47,8 @@ class AppSetView(View):
             return self.do_admin_query(user_id, request_dict, response)
         elif operation == 'admin_update':
             return self.do_admin_update(user_id, request_dict, response)
+        elif operation == 'statusByIp':
+            return self.status_by_ip(request, response)
         else:
             return response.json(414)
 
@@ -273,3 +277,39 @@ class AppSetView(View):
             LOGGER.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             return response.json(500)
         return response.json(0)
+
+
+    def status_by_ip(self, request, response):
+        """
+        根据ip 解析地址返回状态
+        """
+        try:
+            # 这里加sdStatus过滤条件条件
+            ip = CommonService.get_ip_address(request)
+            splashAdStatus = 0
+            ip_addr_qs = IPAddr.objects.filter(ip=ip, is_geoip2=False).values('country_code', 'city', 'region',
+                                                                              'district')
+            if ip_addr_qs.exists():
+                ip_country_code = ip_addr_qs[0]['country_code']
+                ip_region = ip_addr_qs[0]['region']
+                ip_city = ip_addr_qs[0]['city']
+                ip_district = ip_addr_qs[0]['district']
+                if ip_country_code == 'CN' and ip_region == '广东' and ip_city == '珠海市':
+                    splashAdStatus = 1
+            else:
+                ip_qs = IPQuery(ip)
+                ip_country_code = ip_addr_qs.country_id
+                ip_region = ip_qs.region
+                ip_city = ip_addr_qs.city
+                ip_district = ip_addr_qs.district
+                if ip_country_code == 'CN' and ip_region == '广东' and ip_city == '珠海市':
+                    splashAdStatus = 1
+                IPAddr.objects.create(ip=ip, country_code=ip_country_code, region=ip_region, city=ip_city,
+                                      district=ip_district)
+            LOGGER.info(f"请求ip地址为 {ip}, 解析为{ip_country_code},{ip_region},{ip_city},{ip_district}")
+            response_data = {"splashAdStatus": splashAdStatus}
+            return response.json(0, response_data)
+        except Exception as e:
+            LOGGER.info('根据ip解析地址返回状态异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            return response.json(500)
+