fix: 校验咨询表单关联业务并修正发布清单文案

- 关联的业务提供项必须存在且属于当前品牌,非法 id 返回 400 而不是数据库外键错误
- targetType 由 offeringId 推导,允许传 null 改回品牌通用入口
- 业务被停用时在发布准备度里点名说明,避免静默卡住发布
- 发布清单条目改为中性描述,是否达标交给状态标签表达
This commit is contained in:
que01 committed 2026-10-14 13:55:00 +08:00
1 parent 47d6309cba
commit 7b1e9eee47
6 files changed
+223 -25

No files matched your search

+27 -18
View File
@@ -78,7 +78,7 @@ export class BrandReleaseApiService {
}),
database.inquiryForm.findMany({
where: { brandId, isEnabled: true },
select: { offeringId: true, fieldsSnapshot: true },
select: { offeringId: true, name: true, fieldsSnapshot: true },
}),
database.trustContent.findMany({
where: { brandId, isPublished: true },
@@ -92,12 +92,17 @@ export class BrandReleaseApiService {
),
);
const offeringIds = new Set(offerings.map((item) => item.id));
const validFields = (form: { fieldsSnapshot: unknown }) =>
Array.isArray(form.fieldsSnapshot) &&
form.fieldsSnapshot.length > 0 &&
validateFieldSnapshot(form.fieldsSnapshot).length === 0;
const usableForms = forms.filter(
(form) =>
(form.offeringId === null || offeringIds.has(form.offeringId)) &&
Array.isArray(form.fieldsSnapshot) &&
form.fieldsSnapshot.length > 0 &&
validateFieldSnapshot(form.fieldsSnapshot).length === 0,
(form) => (form.offeringId === null || offeringIds.has(form.offeringId)) && validFields(form),
);
// 挂在某个业务上的表单,一旦该业务被停用就再也进不去,小程序也没有入口。这种情况要在发布清单里说清楚,
// 否则只会显示「可用的咨询表单:待完善」,运营者不知道去哪儿改。
const dormantForms = forms.filter(
(form) => form.offeringId !== null && !offeringIds.has(form.offeringId) && validFields(form),
);
const checks: Array<{
key: string;
@@ -108,38 +113,43 @@ export class BrandReleaseApiService {
}> = [
{
key: "brand",
label: "请先完善品牌名称",
label: "品牌名称",
passed: Boolean(brand?.name.trim()),
destination: "/admin/brand",
},
{
key: "positioning",
label: "请先完善品牌定位和介绍",
label: "品牌定位和介绍",
passed: Boolean(brand?.tagline?.trim() && brand.description?.trim()),
destination: "/admin/brand",
},
{ key: "template", label: "当前行业模板不存在", passed: Boolean(template) },
{ key: "template", label: "行业模板配置", passed: Boolean(template) },
{
key: "visual",
label: "当前视觉模板不适配行业模板",
label: "视觉模板与行业模板的适配",
passed: Boolean(visual && template && isVisualTemplateCompatible(visual, template.key)),
destination: "/admin/publication",
},
{
key: "offerings",
label: "至少需要一项已启用的业务提供项",
label: "已启用的业务提供项",
passed: offerings.length > 0,
destination: "/admin/services",
},
{
key: "forms",
label: "至少需要一个可用的咨询表单",
label: "可用的咨询表单",
passed: usableForms.length > 0,
...(dormantForms.length === 0
? {}
: {
help: `「${dormantForms.map((form) => form.name).join("」「")}」关联的业务提供项已停用,该表单在小程序里没有入口;请启用对应业务,或把表单改回品牌通用入口。`,
}),
destination: "/admin/workspace",
},
{
key: "trust",
label: "至少需要一条已发布的信任内容",
label: "已发布的信任内容",
passed: validTrustItems.length > 0,
destination: "/admin/trust",
},
@@ -149,7 +159,7 @@ export class BrandReleaseApiService {
if (type.required !== true) continue;
checks.push({
key: `trust:${type.type}`,
label: `请完善${type.label}`,
label: type.label,
passed:
publishedTrustTypes.has(type.type) &&
(type.maxPublishedItems === undefined ||
@@ -176,9 +186,8 @@ export class BrandReleaseApiService {
});
checks.push({
key: `content:${section.key}:${field.key}`,
label: present
? `${section.title}:${field.label}`
: `请补充「${section.title}」中的「${field.label}」`,
// 检查项只描述「要检查什么」,是否完成由 UI 的状态标签表达,避免出现「已完成 · 请先完善…」这类自相矛盾的文案。
label: `${section.title}:${field.label}`,
passed: present,
help: section.description,
destination:
@@ -202,7 +211,7 @@ export class BrandReleaseApiService {
: trustItems.length > 0;
checks.push({
key: `asset:${String(slot.key)}`,
label: present ? `已添加${String(slot.label)}` : `请添加${String(slot.label)}`,
label: String(slot.label),
passed: present,
help: String(slot.help),
destination: slot.target === "offering" ? "/admin/services" : "/admin/brand",