|
@@ -7,7 +7,7 @@ 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, IPAddr
|
|
|
+ UserOperationLog, Order_Model, IPAddr, RegionRestriction
|
|
|
from Object.IPWeatherObject import IPQuery
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
@@ -278,38 +278,46 @@ class AppSetView(View):
|
|
|
return response.json(500)
|
|
|
return response.json(0)
|
|
|
|
|
|
-
|
|
|
- def status_by_ip(self, request, response):
|
|
|
+ @staticmethod
|
|
|
+ def status_by_ip(request, response):
|
|
|
"""
|
|
|
- 根据ip 解析地址返回状态
|
|
|
+ 根据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':
|
|
|
- splashAdStatus = 1
|
|
|
+ ip_info = ip_addr_qs[0]
|
|
|
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':
|
|
|
- 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}
|
|
|
+ ip_info = {
|
|
|
+ 'country_code': ip_qs.country_id,
|
|
|
+ 'region': ip_qs.region,
|
|
|
+ 'city': ip_qs.city,
|
|
|
+ 'district': ip_qs.district
|
|
|
+ }
|
|
|
+
|
|
|
+ country_code = ip_info['country_code']
|
|
|
+ region = ip_info['region']
|
|
|
+ city = ip_info['city']
|
|
|
+ district = ip_info['district']
|
|
|
+
|
|
|
+ restrictions = RegionRestriction.objects.all()
|
|
|
+ response_data = {}
|
|
|
+
|
|
|
+ for restriction in restrictions:
|
|
|
+ response_data[restriction.statusName] = 0
|
|
|
+ if ((not restriction.country_code or country_code in restriction.country_code) and
|
|
|
+ (not restriction.region or region in restriction.region) and
|
|
|
+ (not restriction.city or city in restriction.city) and
|
|
|
+ (not restriction.district or district in restriction.district)):
|
|
|
+ response_data[restriction.statusName] = 1
|
|
|
+
|
|
|
+ LOGGER.info(f"请求ip地址为 {ip}, 解析为 {country_code}, {region}, {city}, {district}")
|
|
|
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)
|
|
|
-
|