详细变更如下: - 更新 .gitignore 文件,添加 pnpm-store 忽略规则 - 新增数据库迁移脚本,为 DetailRecord 添加可空的 conciergeAdvisorId 字段用于关联管家顾问 - 完善 Admin 后台玩法详情编辑器,支持选择关联的管家顾问并校验合法性 - 公共 API 支持返回已启用的管家顾问完整数据,不在详情表中冗余存储管家资料 - 小程序端新增详情页联系管家入口、个人页最近浏览历史功能 - 更新所有相关文档与测试用例,修复下拉选择框的 z-index 样式问题
149 lines
4.2 KiB
Python
149 lines
4.2 KiB
Python
from datetime import datetime
|
|
from sqlalchemy.inspection import inspect
|
|
|
|
|
|
def encode_value(value):
|
|
if isinstance(value, datetime):
|
|
return value.isoformat()
|
|
if isinstance(value, list):
|
|
return [encode_value(item) for item in value]
|
|
if isinstance(value, dict):
|
|
return {key: encode_value(item) for key, item in value.items()}
|
|
return value
|
|
|
|
|
|
def model_dict(instance, include: dict[str, object] | None = None) -> dict:
|
|
data = {column.key: encode_value(getattr(instance, column.key)) for column in inspect(instance).mapper.column_attrs}
|
|
if include:
|
|
for key, value in include.items():
|
|
data[key] = encode_value(value)
|
|
return data
|
|
|
|
|
|
def lead_dict(lead) -> dict:
|
|
return model_dict(
|
|
lead,
|
|
{"assignedUser": {"id": lead.assignedUser.id, "name": lead.assignedUser.name} if lead.assignedUser else None},
|
|
)
|
|
|
|
|
|
def public_wanfa_route_dict(route) -> dict:
|
|
return {
|
|
"id": route.id,
|
|
"title": route.title,
|
|
"subtitle": route.subtitle,
|
|
"image": route.image,
|
|
"routeCount": route.routeCount,
|
|
"demandKeyword": route.demandKeyword,
|
|
}
|
|
|
|
|
|
def public_wanfa_category_dict(category) -> dict:
|
|
return {
|
|
"id": category.id,
|
|
"label": category.label,
|
|
"routes": [public_wanfa_route_dict(route) for route in category.routes],
|
|
}
|
|
|
|
|
|
def detail_record_dict(detail) -> dict:
|
|
return model_dict(detail)
|
|
|
|
|
|
def public_detail_dict(detail, concierge_advisor=None) -> dict:
|
|
return {
|
|
"key": detail.key,
|
|
"eyebrow": detail.eyebrow,
|
|
"duration": detail.duration,
|
|
"title": detail.title,
|
|
"subtitle": detail.subtitle,
|
|
"intro": detail.intro,
|
|
"highlights": detail.highlights or [],
|
|
"included": detail.included or [],
|
|
"excluded": detail.excluded or [],
|
|
"notes": detail.notes or [],
|
|
"gallery": detail.gallery or [],
|
|
"conciergeAdvisor": public_concierge_advisor_dict(concierge_advisor) if concierge_advisor else None,
|
|
}
|
|
|
|
|
|
def public_home_wanfa_recommendation_dict(item) -> dict:
|
|
return {
|
|
"id": item.id,
|
|
"categoryId": item.category.id,
|
|
"label": item.category.label,
|
|
"routes": [public_wanfa_route_dict(route) for route in item.category.routes],
|
|
}
|
|
|
|
|
|
def concierge_advisor_dict(advisor) -> dict:
|
|
return model_dict(advisor)
|
|
|
|
|
|
def public_concierge_advisor_dict(advisor) -> dict:
|
|
return {
|
|
"avatar": advisor.avatar,
|
|
"name": advisor.name,
|
|
"role": advisor.role,
|
|
"details": advisor.details or [],
|
|
"qrImage": advisor.qrImage,
|
|
}
|
|
|
|
|
|
def public_home_experience_dict(item) -> dict:
|
|
return {
|
|
"id": item.id,
|
|
"badge": item.badge,
|
|
"category": item.category,
|
|
"title": item.title,
|
|
"englishTitle": item.englishTitle,
|
|
"image": item.image,
|
|
"demandKeyword": item.demandKeyword,
|
|
}
|
|
|
|
|
|
def public_home_team_building_dict(item) -> dict:
|
|
return {
|
|
"id": item.id,
|
|
"tag": item.tag,
|
|
"title": item.title,
|
|
"description": item.description,
|
|
"image": item.image,
|
|
"demandKeyword": item.demandKeyword,
|
|
}
|
|
|
|
|
|
def public_home_team_building_detail_dict(item) -> dict:
|
|
paragraphs = [
|
|
paragraph.strip()
|
|
for paragraph in (getattr(item, "detailParagraphs", None) or [])
|
|
if isinstance(paragraph, str) and paragraph.strip()
|
|
]
|
|
if not paragraphs:
|
|
paragraphs = [item.description]
|
|
return {
|
|
**public_home_team_building_dict(item),
|
|
"detailSubtitle": (getattr(item, "detailSubtitle", None) or item.description).strip(),
|
|
"detailParagraphs": paragraphs,
|
|
}
|
|
|
|
|
|
def public_home_wild_archive_dict(item) -> dict:
|
|
return {
|
|
"id": item.id,
|
|
"title": item.title,
|
|
"image": item.image,
|
|
"demandKeyword": item.demandKeyword,
|
|
"photoCount": len(item.images or [item.image]),
|
|
}
|
|
|
|
|
|
def public_home_wild_archive_detail_dict(item) -> dict:
|
|
images = [image for image in (item.images or []) if isinstance(image, str) and image.strip()]
|
|
if not images:
|
|
images = [item.image]
|
|
return {
|
|
**public_home_wild_archive_dict(item),
|
|
"images": images,
|
|
}
|