|
@@ -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
|
|
@@ -48,7 +48,7 @@ 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)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -279,9 +279,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,15 +304,22 @@ 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(userID=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 = user_set_status_qs.objects.filter(id=restriction.id).first()
|
|
|
+ # 用户控制
|
|
|
+ if user_set:
|
|
|
+ response_data[restriction.statusName] = user_set.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)):
|
|
|
+ # 返回值定义具体看表的content字段
|
|
|
response_data[restriction.statusName] = 1
|
|
|
|
|
|
LOGGER.info(f"请求ip地址为 {ip}, 解析为 {country_code}, {region}, {city}, {district}")
|