feat(wanfa): 新增路线详情参考价格配置及展示功能
- 新增数据库迁移脚本,为详情表添加四个价格相关字段 - 完善后端schema校验、序列化逻辑,增加价格相关的数据清理与验证规则 - 新增价格配置校验逻辑,设置起售价时必须选择对应的计价单位 - 在Admin UI详情编辑器中新增价格配置模块,支持配置起售价、计价单位、适用人数范围和价格说明 - 更新小程序端详情页面,支持展示配置的参考价格信息 - 补充相关测试用例,更新API文档与类型定义
This commit is contained in:
1 parent
f18971a430
commit
feec6ab80f
20 files changed
+351
-17
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import type { DetailCreate, WanfaRouteCreate } from "@/types";
|
||||
import type { DetailCreate, DetailPriceUnit, WanfaRouteCreate } from "@/types";
|
||||
|
||||
export function createEmptyWanfaRoute(): WanfaRouteCreate {
|
||||
return { title: "", subtitle: "", image: "", routeCount: 0, demandKeyword: "" };
|
||||
@@ -27,6 +27,10 @@ export function createEmptyDetail(): DetailCreate {
|
||||
excluded: [],
|
||||
notes: [],
|
||||
gallery: [],
|
||||
priceStartingValue: null,
|
||||
priceUnit: null,
|
||||
pricePeopleRange: "",
|
||||
priceDescription: "",
|
||||
conciergeAdvisorId: null,
|
||||
isActive: true,
|
||||
};
|
||||
@@ -45,9 +49,13 @@ export function compactDetail(draft: DetailCreate): DetailCreate {
|
||||
excluded: compactList(draft.excluded),
|
||||
notes: compactList(draft.notes),
|
||||
gallery: compactList(draft.gallery),
|
||||
priceStartingValue: normalizePriceStartingValue(draft.priceStartingValue),
|
||||
priceUnit: normalizePriceUnit(draft.priceUnit),
|
||||
pricePeopleRange: draft.pricePeopleRange?.trim() || null,
|
||||
priceDescription: draft.priceDescription?.trim() || null,
|
||||
conciergeAdvisorId: draft.conciergeAdvisorId?.trim() || null,
|
||||
isActive: draft.isActive ?? true,
|
||||
sortOrder: draft.sortOrder,
|
||||
...(draft.sortOrder === undefined ? {} : { sortOrder: draft.sortOrder }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,9 +71,21 @@ export function validateWanfaWrite(route: WanfaRouteCreate, detail: DetailCreate
|
||||
return "请完整填写详情眉标、时长、标题、副标题和详情介绍。";
|
||||
}
|
||||
if (detail.gallery.some((image) => !isHttpUrl(image))) return "详情图片必须是有效的 HTTP(S) URL。";
|
||||
if (detail.priceStartingValue !== null && detail.priceStartingValue !== undefined && !detail.priceUnit) {
|
||||
return "配置价格起始值时请选择价格单位。";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function normalizePriceStartingValue(value: number | null | undefined) {
|
||||
if (value === null || value === undefined || !Number.isFinite(Number(value))) return null;
|
||||
return Math.max(0, Number(Number(value).toFixed(2)));
|
||||
}
|
||||
|
||||
function normalizePriceUnit(value: DetailPriceUnit | null | undefined): DetailPriceUnit | null {
|
||||
return value === "person" || value === "day" || value === "group" ? value : null;
|
||||
}
|
||||
|
||||
function compactList(items: string[]) {
|
||||
return items.map((item) => item.trim()).filter(Boolean);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user