This commit is contained in:
jlj 2025-05-28 18:36:40 +08:00
parent 7248ee6f2b
commit 9f2ade35a2
2 changed files with 136 additions and 89 deletions

View File

@ -1007,6 +1007,142 @@ Authorization: Token <your_token>
- `409`: 资源冲突(如重名)
- `500`: 服务器内部错误
## 7. 搜索功能相关接口
### 7.1 公有达人库搜索
- **接口路径**: `GET /search/creators/`
- **功能**: 基于关键词搜索公有达人库中的达人,支持多关键词搜索
- **请求方法**: GET
**URL参数**:
- `q`: 搜索关键词,支持单个或多个关键词(多个关键词可用空格、逗号、分号分隔)
- `mode`: 搜索模式,可选 "and"(所有关键词都必须匹配)或 "or"(任一关键词匹配即可),默认为 "and"
- `page`: 页码默认为1
- `page_size`: 每页数量默认为10
**响应格式**:
```json
{
"code": 200,
"message": "搜索成功",
"data": {
"creators": [
{
"Creator": {
"name": "达人姓名",
"avatar": "头像URL"
},
"Category": "Beauty & Personal Care",
"E-commerce Level": "L3",
"Exposure Level": "KOL-1",
"Followers": "125k",
"GMV": "$534k",
"Items Sold": "2.5k",
"Avg. Video Views": "85k",
"Pricing": "$200",
"Pricing Package": "套餐描述",
"# Collab": 15,
"Latest Collab.": "2024-03-15",
"E-commerce": ["TikTok Shop"],
"creator_id": 123,
"profile": "tiktok",
"public_pool_category": "公有库分类",
"public_pool_remark": "公有库备注",
"is_public": true
}
],
"pagination": {
"current_page": 1,
"total_pages": 15,
"total_count": 150,
"has_next": true,
"has_prev": false,
"page_size": 10
},
"search_info": {
"query": "搜索关键词",
"keywords": ["关键词1", "关键词2"],
"search_mode": "and",
"results_count": 150,
"search_applied": true,
"supports_single_char": true,
"search_scope": "public_only"
}
}
}
```
### 7.2 私有达人库搜索
- **接口路径**: `GET /search/private/creators/`
- **功能**: 基于关键词搜索用户私有达人库中的达人,支持多关键词搜索
- **请求方法**: GET
**URL参数**:
- `q`: 搜索关键词,支持单个或多个关键词(多个关键词可用空格、逗号、分号分隔)
- `mode`: 搜索模式,可选 "and"(所有关键词都必须匹配)或 "or"(任一关键词匹配即可),默认为 "and"
- `pool_id`: 私有达人库ID可选如果提供则只搜索特定私有库
- `page`: 页码默认为1
- `page_size`: 每页数量默认为10
**响应格式**:
```json
{
"code": 200,
"message": "搜索成功",
"data": {
"creators": [
{
"Creator": {
"name": "达人姓名",
"avatar": "头像URL"
},
"Category": "Beauty & Personal Care",
"E-commerce Level": "L3",
"Exposure Level": "KOL-1",
"Followers": "125k",
"GMV": "$534k",
"Items Sold": "2.5k",
"Avg. Video Views": "85k",
"Pricing": "$200",
"Pricing Package": "套餐描述",
"# Collab": 15,
"Latest Collab.": "2024-03-15",
"E-commerce": ["TikTok Shop"],
"creator_id": 123,
"profile": "tiktok",
"private_pool": {
"id": 456,
"name": "我的收藏",
"is_default": true
},
"notes": "私有库中的笔记",
"status": "active",
"relation_id": 789,
"is_private": true
}
],
"pagination": {
"current_page": 1,
"total_pages": 3,
"total_count": 25,
"has_next": true,
"has_prev": false,
"page_size": 10
},
"search_info": {
"query": "搜索关键词",
"keywords": ["关键词1", "关键词2"],
"search_mode": "and",
"results_count": 25,
"search_applied": true,
"supports_single_char": true,
"search_scope": "private_only",
"pool_id": "456"
}
}
}
```
## 使用示例
### 筛选达人示例

View File

@ -1,89 +0,0 @@
import os
import django
import random
from datetime import datetime, timedelta
import sys
# 添加项目根目录到Python路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'daren.settings')
django.setup()
from apps.daren_detail.models import CreatorProfile
def generate_test_data():
# 类别列表
categories = [choice[0] for choice in CreatorProfile.CATEGORY_CHOICES]
# 曝光等级列表
exposure_levels = [choice[0] for choice in CreatorProfile.EXPOSURE_LEVEL_CHOICES]
# 电商平台列表
e_commerce_platforms = ["SUNLINK", "ARZOPA", "BELIFE", "TIKTOK", "SHOPEE", "LAZADA"]
# 生成50个测试数据
for i in range(50):
# 随机生成GMV (1-2000k)
gmv = random.randint(1, 2000)
# 随机生成粉丝数 (1k-1000k)
followers = random.randint(1000, 1000000)
# 随机生成平均视频观看量 (100-500k)
avg_views = random.randint(100, 500000)
# 随机生成售出商品数量 (100-10000)
items_sold = random.randint(100, 10000)
# 随机生成合作次数 (0-50)
collab_count = random.randint(0, 50)
# 随机生成最新合作时间
latest_collab = (datetime.now() - timedelta(days=random.randint(0, 365))).strftime("%Y-%m-%d")
# 随机选择2-4个电商平台
selected_platforms = random.sample(e_commerce_platforms, random.randint(2, 4))
# 创建达人信息
creator = CreatorProfile.objects.create(
name=f"测试达人{i+1}",
avatar_url=f"https://example.com/avatar{i+1}.jpg",
is_active=random.choice([True, False]),
email=f"creator{i+1}@example.com",
instagram=f"creator{i+1}",
tiktok_link=f"https://tiktok.com/@creator{i+1}",
location=random.choice(["北京", "上海", "广州", "深圳", "杭州"]),
live_schedule="每周一、三、五 20:00-22:00",
category=random.choice(categories),
e_commerce_level=random.randint(1, 7),
exposure_level=random.choice(exposure_levels),
followers=followers,
gmv=gmv,
items_sold=items_sold,
avg_video_views=avg_views,
pricing_individual=f"${random.randint(100, 1000)}/video",
pricing_package=f"${random.randint(1000, 5000)}/package",
collab_count=collab_count,
latest_collab=latest_collab,
e_commerce_platforms=selected_platforms,
gmv_by_channel={
"TikTok": random.randint(30, 70),
"Instagram": random.randint(20, 50),
"Facebook": random.randint(10, 30)
},
gmv_by_category={
"服装": random.randint(20, 40),
"美妆": random.randint(15, 35),
"数码": random.randint(10, 30),
"家居": random.randint(5, 25)
},
mcn=random.choice(["MCN机构A", "MCN机构B", "MCN机构C", None])
)
print(f"已创建达人: {creator.name}")
if __name__ == "__main__":
print("开始生成测试数据...")
generate_test_data()
print("测试数据生成完成!")