修改请求参数

This commit is contained in:
jlj 2025-05-29 12:04:43 +08:00
parent 1d1e7cf760
commit 638b0966c0
2 changed files with 28 additions and 107 deletions

View File

@ -2888,7 +2888,6 @@ def remove_creator_from_private_pool(request):
'data': None 'data': None
}, json_dumps_params={'ensure_ascii': False}) }, json_dumps_params={'ensure_ascii': False})
@api_view(['POST']) @api_view(['POST'])
@authentication_classes([CustomTokenAuthentication]) @authentication_classes([CustomTokenAuthentication])
@csrf_exempt @csrf_exempt
@ -2966,44 +2965,16 @@ def filter_public_creators(request):
public_creators = public_creators.filter(gmv_q) public_creators = public_creators.filter(gmv_q)
# 观看量范围过滤,单选 # 观看量范围过滤,使用数值数组格式
views_range = filter_data.get('views_range') views_range = filter_data.get('views_range')
if views_range and len(views_range) > 0: if views_range and isinstance(views_range, list) and len(views_range) == 2:
views_val = views_range[0] # 单选,取第一个值 views_min = views_range[0]
if ',' in views_val: views_max = views_range[1]
# 新格式: "1000,10000"
try:
views_min, views_max = views_val.split(',')
views_min = int(views_min.strip())
views_max = int(views_max.strip())
public_creators = public_creators.filter( if views_min is not None:
creator__avg_video_views__gte=views_min, public_creators = public_creators.filter(creator__avg_video_views__gte=views_min)
creator__avg_video_views__lte=views_max if views_max is not None:
) public_creators = public_creators.filter(creator__avg_video_views__lte=views_max)
except (ValueError, IndexError):
# 如果解析失败,忽略此过滤条件
pass
else:
# 兼容旧格式,保持原有逻辑
views_min, views_max = 0, float('inf')
if views_val == "0-100":
views_min, views_max = 0, 100
elif views_val == "1k-10k":
views_min, views_max = 1000, 10000
elif views_val == "10k-100k":
views_min, views_max = 10000, 100000
elif views_val == "100k-250k":
views_min, views_max = 100000, 250000
elif views_val == "250k-500k":
views_min, views_max = 250000, 500000
elif views_val == "500k+":
views_min = 500000
if views_min > 0:
public_creators = public_creators.filter(creator__avg_video_views__gte=views_min)
if views_max < float('inf'):
public_creators = public_creators.filter(creator__avg_video_views__lte=views_max)
# 获取总数据量 # 获取总数据量
total_count = public_creators.count() total_count = public_creators.count()
@ -3205,77 +3176,27 @@ def filter_private_pool_creators(request):
creator_relations = creator_relations.filter(gmv_q) creator_relations = creator_relations.filter(gmv_q)
# 观看量范围过滤,单选 # 观看量范围过滤,使用数值数组格式
views_range = filter_data.get('views_range') views_range = filter_data.get('views_range')
if views_range and len(views_range) > 0: if views_range and isinstance(views_range, list) and len(views_range) == 2:
views_val = views_range[0] # 单选,取第一个值 views_min = views_range[0]
if ',' in views_val: views_max = views_range[1]
# 新格式: "1000,10000"
try:
views_min, views_max = views_val.split(',')
views_min = int(views_min.strip())
views_max = int(views_max.strip())
creator_relations = creator_relations.filter( if views_min is not None:
creator__avg_video_views__gte=views_min, creator_relations = creator_relations.filter(creator__avg_video_views__gte=views_min)
creator__avg_video_views__lte=views_max if views_max is not None:
) creator_relations = creator_relations.filter(creator__avg_video_views__lte=views_max)
except (ValueError, IndexError):
# 如果解析失败,忽略此过滤条件
pass
else:
# 兼容旧格式,保持原有逻辑
views_min, views_max = 0, float('inf')
if views_val == "0-100":
views_min, views_max = 0, 100
elif views_val == "1k-10k":
views_min, views_max = 1000, 10000
elif views_val == "10k-100k":
views_min, views_max = 10000, 100000
elif views_val == "100k-250k":
views_min, views_max = 100000, 250000
elif views_val == "250k-500k":
views_min, views_max = 250000, 500000
elif views_val == "500k+":
views_min = 500000
if views_min > 0: # 价格区间过滤逻辑,使用数值数组格式
creator_relations = creator_relations.filter(creator__avg_video_views__gte=views_min)
if views_max < float('inf'):
creator_relations = creator_relations.filter(creator__avg_video_views__lte=views_max)
# 价格区间过滤逻辑,单选
pricing = filter_data.get('pricing') pricing = filter_data.get('pricing')
if pricing and len(pricing) > 0: if pricing and isinstance(pricing, list) and len(pricing) == 2:
pricing_val = pricing[0] # 单选,取第一个值 min_price = pricing[0]
if ',' in pricing_val: max_price = pricing[1]
# 新格式: "100,500"
try:
min_price, max_price = pricing_val.split(',')
min_price = float(min_price.strip())
max_price = float(max_price.strip())
creator_relations = creator_relations.filter( if min_price is not None:
creator__pricing__gte=min_price, creator_relations = creator_relations.filter(creator__pricing__gte=min_price)
creator__pricing__lte=max_price if max_price is not None:
) creator_relations = creator_relations.filter(creator__pricing__lte=max_price)
except (ValueError, IndexError):
# 如果解析失败,忽略此过滤条件
pass
elif '-' in pricing_val:
# 兼容旧格式: "100-500"
try:
min_price, max_price = pricing_val.split('-')
min_price = float(min_price.strip())
max_price = float(max_price.strip())
creator_relations = creator_relations.filter(
creator__pricing__gte=min_price,
creator__pricing__lte=max_price
)
except (ValueError, IndexError):
# 如果解析失败,忽略此过滤条件
pass
# 获取总数据量 # 获取总数据量
total_count = creator_relations.count() total_count = creator_relations.count()

View File

@ -105,7 +105,7 @@ DATABASES = {
'NAME': 'daren_detail', 'NAME': 'daren_detail',
'USER': 'root', 'USER': 'root',
'PASSWORD': '123456', 'PASSWORD': '123456',
'HOST': '192.168.31.138', 'HOST': '127.0.0.1',
'PORT': '3306', 'PORT': '3306',
'OPTIONS': { 'OPTIONS': {
'charset': 'utf8mb4', 'charset': 'utf8mb4',