feat: 新增路线详情关联管家顾问及相关功能
详细变更如下: - 更新 .gitignore 文件,添加 pnpm-store 忽略规则 - 新增数据库迁移脚本,为 DetailRecord 添加可空的 conciergeAdvisorId 字段用于关联管家顾问 - 完善 Admin 后台玩法详情编辑器,支持选择关联的管家顾问并校验合法性 - 公共 API 支持返回已启用的管家顾问完整数据,不在详情表中冗余存储管家资料 - 小程序端新增详情页联系管家入口、个人页最近浏览历史功能 - 更新所有相关文档与测试用例,修复下拉选择框的 z-index 样式问题
This commit is contained in:
1 parent
e7b8c5bf43
commit
b7a81964c9
34 files changed
+739
-63
No files matched your search
@@ -206,6 +206,7 @@ class DetailRecord(Base):
|
||||
excluded: Mapped[list[str]] = mapped_column(JSONB, default=list, nullable=False)
|
||||
notes: Mapped[list[str]] = mapped_column(JSONB, default=list, nullable=False)
|
||||
gallery: Mapped[list[str]] = mapped_column(JSONB, default=list, nullable=False)
|
||||
conciergeAdvisorId: Mapped[str | None] = mapped_column(String, nullable=True)
|
||||
isActive: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False, index=True)
|
||||
sortOrder: Mapped[int] = mapped_column(Integer, default=0, nullable=False, index=True)
|
||||
createdAt: Mapped[datetime] = mapped_column(DateTime, default=utc_now, nullable=False)
|
||||
|
||||
@@ -841,6 +841,18 @@ def detail_key_conflict(db: Session, key: str, current_id: str | None = None) ->
|
||||
detail_error(409, "详情 key 已存在", "DETAIL_KEY_EXISTS", {"key": key})
|
||||
|
||||
|
||||
def validate_detail_concierge_advisor(db: Session, advisor_id: str | None) -> None:
|
||||
if not advisor_id:
|
||||
return
|
||||
if not db.get(ConciergeAdvisor, advisor_id):
|
||||
detail_error(
|
||||
422,
|
||||
"关联的管家顾问不存在",
|
||||
"DETAIL_CONCIERGE_ADVISOR_INVALID",
|
||||
{"conciergeAdvisorId": advisor_id},
|
||||
)
|
||||
|
||||
|
||||
def validate_detail_order(item_ids: list[str], current_ids: list[str]) -> None:
|
||||
validate_wanfa_order(item_ids, current_ids, "DETAIL_REORDER_INVALID")
|
||||
|
||||
@@ -881,6 +893,7 @@ def create_detail(
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
detail_key_conflict(db, body.key)
|
||||
validate_detail_concierge_advisor(db, body.conciergeAdvisorId)
|
||||
detail = DetailRecord(
|
||||
**body.model_dump(exclude={"sortOrder"}),
|
||||
sortOrder=body.sortOrder if body.sortOrder is not None else next_site_sort_order(db, DetailRecord),
|
||||
@@ -905,6 +918,8 @@ def update_detail(
|
||||
before = detail_record_dict(detail)
|
||||
if "key" in body.model_fields_set:
|
||||
detail_key_conflict(db, body.key or "", detail.id)
|
||||
if "conciergeAdvisorId" in body.model_fields_set:
|
||||
validate_detail_concierge_advisor(db, body.conciergeAdvisorId)
|
||||
for field in body.model_fields_set:
|
||||
setattr(detail, field, getattr(body, field))
|
||||
db.flush()
|
||||
|
||||
@@ -64,7 +64,12 @@ def get_public_detail(detail_key: str, db: Session = Depends(get_db)):
|
||||
)
|
||||
if not detail:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="详情不存在")
|
||||
return success_response(public_detail_dict(detail))
|
||||
advisor = None
|
||||
if detail.conciergeAdvisorId:
|
||||
candidate = db.get(ConciergeAdvisor, detail.conciergeAdvisorId)
|
||||
if candidate and candidate.isActive:
|
||||
advisor = candidate
|
||||
return success_response(public_detail_dict(detail, advisor))
|
||||
|
||||
|
||||
@router.get("/api/public/concierge/advisors")
|
||||
|
||||
@@ -193,6 +193,7 @@ class DetailCreate(BaseModel):
|
||||
excluded: list[str] = Field(default_factory=list)
|
||||
notes: list[str] = Field(default_factory=list)
|
||||
gallery: list[str] = Field(default_factory=list)
|
||||
conciergeAdvisorId: str | None = Field(default=None, max_length=120)
|
||||
isActive: bool = True
|
||||
sortOrder: int | None = Field(default=None, ge=0)
|
||||
|
||||
@@ -211,6 +212,14 @@ class DetailCreate(BaseModel):
|
||||
def validate_detail_gallery(cls, value: list[str]) -> list[str]:
|
||||
return normalize_detail_gallery(value)
|
||||
|
||||
@field_validator("conciergeAdvisorId", mode="before")
|
||||
@classmethod
|
||||
def normalize_concierge_advisor_id(cls, value: str | None) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
normalized = str(value).strip()
|
||||
return normalized or None
|
||||
|
||||
|
||||
class DetailPatch(BaseModel):
|
||||
key: str | None = Field(default=None, min_length=1, max_length=120)
|
||||
@@ -224,6 +233,7 @@ class DetailPatch(BaseModel):
|
||||
excluded: list[str] | None = None
|
||||
notes: list[str] | None = None
|
||||
gallery: list[str] | None = None
|
||||
conciergeAdvisorId: str | None = Field(default=None, max_length=120)
|
||||
isActive: bool | None = None
|
||||
sortOrder: int | None = Field(default=None, ge=0)
|
||||
|
||||
@@ -248,6 +258,14 @@ class DetailPatch(BaseModel):
|
||||
raise ValueError("字段不能为空")
|
||||
return normalize_detail_gallery(value)
|
||||
|
||||
@field_validator("conciergeAdvisorId", mode="before")
|
||||
@classmethod
|
||||
def normalize_optional_concierge_advisor_id(cls, value: str | None) -> str | None:
|
||||
if value is None:
|
||||
return None
|
||||
normalized = str(value).strip()
|
||||
return normalized or None
|
||||
|
||||
|
||||
class HomeExperienceCreate(BaseModel):
|
||||
badge: str = Field(min_length=1, max_length=40)
|
||||
|
||||
@@ -50,7 +50,7 @@ def detail_record_dict(detail) -> dict:
|
||||
return model_dict(detail)
|
||||
|
||||
|
||||
def public_detail_dict(detail) -> dict:
|
||||
def public_detail_dict(detail, concierge_advisor=None) -> dict:
|
||||
return {
|
||||
"key": detail.key,
|
||||
"eyebrow": detail.eyebrow,
|
||||
@@ -63,6 +63,7 @@ def public_detail_dict(detail) -> dict:
|
||||
"excluded": detail.excluded or [],
|
||||
"notes": detail.notes or [],
|
||||
"gallery": detail.gallery or [],
|
||||
"conciergeAdvisor": public_concierge_advisor_dict(concierge_advisor) if concierge_advisor else None,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user