|
@@ -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, RegionRestriction
|
|
|
+ UserOperationLog, Order_Model, IPAddr, RegionRestriction, UserSetStatus
|
|
|
from Object.IPWeatherObject import IPQuery
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
@@ -35,6 +35,8 @@ class AppSetView(View):
|
|
|
if operation == 'query':
|
|
|
return self.do_query(request_dict, response)
|
|
|
token = request_dict.get('token', None)
|
|
|
+ if not token:
|
|
|
+ token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
tko = TokenObject(token)
|
|
|
if tko.code != 0:
|
|
|
return response.json(tko.code)
|
|
@@ -48,7 +50,9 @@ class AppSetView(View):
|
|
|
elif operation == 'admin_update':
|
|
|
return self.do_admin_update(user_id, request_dict, response)
|
|
|
elif operation == 'statusByIp':
|
|
|
- return self.status_by_ip(request, response)
|
|
|
+ return self.status_by_ip(user_id, request, response)
|
|
|
+ elif operation == 'userSetAdStatus':
|
|
|
+ return self.user_set_ad_status(user_id, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -279,9 +283,9 @@ class AppSetView(View):
|
|
|
return response.json(0)
|
|
|
|
|
|
@staticmethod
|
|
|
- def status_by_ip(request, response):
|
|
|
+ def status_by_ip(user_id, request, response):
|
|
|
"""
|
|
|
- 根据ip解析地址返回状态
|
|
|
+ 根据ip解析或用户设置返回状态
|
|
|
"""
|
|
|
try:
|
|
|
ip = CommonService.get_ip_address(request)
|
|
@@ -304,16 +308,30 @@ class AppSetView(View):
|
|
|
city = ip_info['city']
|
|
|
district = ip_info['district']
|
|
|
|
|
|
- restrictions = RegionRestriction.objects.all()
|
|
|
+ restrictions_qs = RegionRestriction.objects.all()
|
|
|
+ user_set_status_qs = UserSetStatus.objects.filter(user_id=user_id)
|
|
|
response_data = {}
|
|
|
|
|
|
- for restriction in restrictions:
|
|
|
+ for restriction in restrictions_qs:
|
|
|
response_data[restriction.statusName] = 0
|
|
|
- if ((not restriction.country_code or country_code in restriction.country_code) and
|
|
|
+ user_set_qs = user_set_status_qs.filter(region_restriction_id=restriction.id)
|
|
|
+ # 用户控制
|
|
|
+ if user_set_qs.exists():
|
|
|
+ if restriction.statusName == "splashAdStatus":
|
|
|
+ if user_set_qs[0].end_time > int(time.time()):
|
|
|
+ response_data[restriction.statusName] = user_set_qs[0].status
|
|
|
+ else:
|
|
|
+ response_data[restriction.statusName] = restriction.default_status
|
|
|
+ else:
|
|
|
+ response_data[restriction.statusName] = user_set_qs[0].status
|
|
|
+
|
|
|
+ # 地区控制
|
|
|
+ elif ((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
|
|
|
+ # 返回值定义具体看表的content字段
|
|
|
+ response_data[restriction.statusName] = restriction.default_status
|
|
|
|
|
|
LOGGER.info(f"请求ip地址为 {ip}, 解析为 {country_code}, {region}, {city}, {district}")
|
|
|
return response.json(0, response_data)
|
|
@@ -321,3 +339,32 @@ class AppSetView(View):
|
|
|
except Exception as e:
|
|
|
LOGGER.info('根据ip解析地址返回状态异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return response.json(500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def user_set_ad_status(user_id, request_dict, response):
|
|
|
+ """
|
|
|
+ 用户设置广告状态
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ status_name = request_dict.get("statusName", None)
|
|
|
+ value = request_dict.get("value", None)
|
|
|
+ if not all([status_name, value]):
|
|
|
+ return response.json(444)
|
|
|
+ value = int(value)
|
|
|
+ now_time = int(time.time())
|
|
|
+ end_time = now_time + 15 * 24 * 60 * 60
|
|
|
+ user_set_status_qs = UserSetStatus.objects.filter(user_id=user_id)
|
|
|
+ region_restriction_qs = RegionRestriction.objects.filter(statusName=status_name)
|
|
|
+ if not region_restriction_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ if not user_set_status_qs.exists():
|
|
|
+ UserSetStatus.objects.create(user_id=user_id, status=value, created_time=now_time,
|
|
|
+ updated_time=now_time, end_time=end_time,
|
|
|
+ region_restriction_id=region_restriction_qs[0].id)
|
|
|
+ else:
|
|
|
+ user_set_status_qs.update(status=value, updated_time=now_time, end_time=end_time,
|
|
|
+ region_restriction_id=region_restriction_qs[0].id)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('设置用户广告状态异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+ return response.json(500)
|