功能(订单服务): 将未成年提示和底部引导图并入分类配置

This commit is contained in:
2026-11-27 15:53:09 +08:00
parent 5e45b69720
commit c3a13c5f36
25 changed files with 619 additions and 384 deletions
@@ -6,8 +6,6 @@ export const APP_CONFIG_KEYS = {
workerPlatformNotifications: 'worker_platform_notifications',
workerProductMatch: 'worker_product_match',
workerAnnouncement: 'worker_announcement',
/** 工单补资料页未成年提示:全局配置,默认关闭 */
orderServiceAgeGate: 'order_service_age_gate',
workerSupportContact: 'worker_support_contact',
workerHall: 'worker_hall',
/** 商品名来源后缀:按 material.source.provider 在商品名后追加(文字),仅展示用 */
@@ -0,0 +1,12 @@
-- 183_order_service_content_config_fields.sql
-- 未成年提示与底部引导图并入分类级订单服务配置。
-- 不新增独立配置表;草稿、发布版本、父子分类继承和工单快照继续复用订单服务配置链路。
ALTER TABLE order_service_profiles
ADD COLUMN IF NOT EXISTS age_gate_json JSONB NOT NULL DEFAULT '{}'::jsonb,
ADD COLUMN IF NOT EXISTS bottom_guide_image_json JSONB NOT NULL DEFAULT '{}'::jsonb;
COMMENT ON COLUMN order_service_profiles.age_gate_json IS
'分类级未成年提示配置:enabled/title/warningText/content/importantNotice/按钮与拦截文案';
COMMENT ON COLUMN order_service_profiles.bottom_guide_image_json IS
'分类级填写资料页底部引导图:enabled/image';
@@ -9,6 +9,8 @@ export type OrderServiceProfileRow = {
title: string
description: string
guide_image_json: Record<string, unknown>
age_gate_json: Record<string, unknown>
bottom_guide_image_json: Record<string, unknown>
fields_json: Array<Record<string, unknown>>
screenshots_json: Record<string, unknown>
auto_publish_json: Record<string, unknown>
@@ -99,6 +101,8 @@ export async function upsertOrderServiceProfile(input: {
title: string
description: string
guideImage: Record<string, unknown>
ageGate: Record<string, unknown>
bottomGuideImage: Record<string, unknown>
fields: Array<Record<string, unknown>>
screenshots: Record<string, unknown>
autoPublish: Record<string, unknown>
@@ -113,19 +117,24 @@ export async function upsertOrderServiceProfile(input: {
`
INSERT INTO order_service_profiles (
category_id, name, title, description,
guide_image_json, fields_json, screenshots_json, auto_publish_json,
guide_image_json, age_gate_json, bottom_guide_image_json,
fields_json, screenshots_json, auto_publish_json,
material_confirmation_json, status_steps_json,
submit_text, success_text, post_submit_text, status, created_by_admin_user_id
) VALUES (
$1, $2, $3, $4,
$5::jsonb, $6::jsonb, $7::jsonb, $8::jsonb, $9::jsonb, $10::jsonb,
$11, $12, $13, 'draft', $14
$5::jsonb, $6::jsonb, $7::jsonb,
$8::jsonb, $9::jsonb, $10::jsonb,
$11::jsonb, $12::jsonb,
$13, $14, $15, 'draft', $16
)
ON CONFLICT (category_id) DO UPDATE SET
name = EXCLUDED.name,
title = EXCLUDED.title,
description = EXCLUDED.description,
guide_image_json = EXCLUDED.guide_image_json,
age_gate_json = EXCLUDED.age_gate_json,
bottom_guide_image_json = EXCLUDED.bottom_guide_image_json,
fields_json = EXCLUDED.fields_json,
screenshots_json = EXCLUDED.screenshots_json,
auto_publish_json = EXCLUDED.auto_publish_json,
@@ -148,6 +157,8 @@ export async function upsertOrderServiceProfile(input: {
input.title,
input.description,
JSON.stringify(input.guideImage),
JSON.stringify(input.ageGate),
JSON.stringify(input.bottomGuideImage),
JSON.stringify(input.fields),
JSON.stringify(input.screenshots),
JSON.stringify(input.autoPublish),
@@ -163,7 +174,6 @@ export async function upsertOrderServiceProfile(input: {
if (!row) throw new Error('order service profile upsert returned no row')
return mapProfile(row)
}
export async function archiveOrderServiceProfile(
profileId: number | string,
): Promise<OrderServiceProfileRow | null> {
@@ -6,7 +6,6 @@ import {
deleteAdminWorkProductRule,
deleteAdminWorkProductRuleMapping,
deleteAdminWorkerLevel,
getAdminOrderServiceAgeGateConfig,
getAdminWorkerAnnouncementConfig,
getAdminWorkerFinanceConfig,
getAdminWorkerHallConfig,
@@ -26,7 +25,6 @@ import {
saveAdminWorkCategory,
saveAdminWorkProductRule,
saveAdminWorkProductRuleMapping,
saveAdminOrderServiceAgeGateConfig,
saveAdminWorkerAnnouncementConfig,
archiveAdminOrderServiceProfile,
listAdminOrderServiceAutoPublishJobs,
@@ -426,33 +424,6 @@ router.post(
}),
)
router.get(
'/worker-platform/order-service-age-gate',
requireAdminPermission('worker_platform.misc_config'),
setHttpCache(0),
createJsonHandler(() => getAdminOrderServiceAgeGateConfig(), {
successMessage: 'ok',
errorMessage: '读取工单补资料页未成年提示失败',
scope: '[admin/worker-platform/order-service-age-gate]',
}),
)
router.post(
'/worker-platform/order-service-age-gate',
requireAdminPermission('worker_platform.misc_config'),
createJsonHandler((req) => saveAdminOrderServiceAgeGateConfig(req.body || {}), {
successMessage: '工单补资料页未成年提示已保存',
errorMessage: '保存工单补资料页未成年提示失败',
scope: '[admin/worker-platform/order-service-age-gate]',
audit: (_req, data) => ({
action: 'order_service_age_gate_saved',
targetType: 'order_service_age_gate',
targetId: 'order_service_age_gate',
data: data && typeof data === 'object' ? (data as Record<string, unknown>) : {},
}),
}),
)
router.get(
'/worker-platform/support-contact',
requireAdminPermission('worker_platform.misc_config'),
@@ -303,7 +303,13 @@ export function refreshUploadedFileUrls(value: unknown) {
}
}
export const PUBLIC_SCENES = new Set(['category_icon', 'hall_icon', 'public', 'announcement'])
export const PUBLIC_SCENES = new Set([
'category_icon',
'hall_icon',
'public',
'announcement',
'order-service-guide',
])
export function isPublicObjectKey(objectKey: string) {
const normalized = normalizeObjectKey(objectKey)
@@ -4,10 +4,6 @@ import {
getWorkerAnnouncementConfig,
saveWorkerAnnouncementConfig,
} from './worker-announcement-config-service.js'
import {
getOrderServiceAgeGateConfig,
saveOrderServiceAgeGateConfig,
} from './order-service-age-gate-config-service.js'
import {
getWorkerPlatformNotificationConfig,
saveWorkerPlatformNotificationConfig,
@@ -45,14 +41,6 @@ export async function saveAdminWorkerAnnouncementConfig(payload: JsonObject = {}
return saveWorkerAnnouncementConfig(payload)
}
export async function getAdminOrderServiceAgeGateConfig() {
return getOrderServiceAgeGateConfig()
}
export async function saveAdminOrderServiceAgeGateConfig(payload: JsonObject = {}) {
return saveOrderServiceAgeGateConfig(payload)
}
export async function saveAdminWorkerProductMatchConfig(payload: JsonObject = {}) {
return saveWorkerProductMatchConfig(payload)
}
@@ -3,6 +3,8 @@ import test from 'node:test'
import {
DEFAULT_ORDER_SERVICE_AGE_GATE_CONTENT,
DEFAULT_ORDER_SERVICE_BOTTOM_GUIDE_IMAGE_CONFIG,
normalizeOrderServiceBottomGuideImageConfig,
normalizeOrderServiceAgeGateConfig,
} from './order-service-age-gate-config-service.js'
@@ -74,3 +76,20 @@ test('非布尔启用值和超长文本不会穿透配置边界', () => {
assert.equal(config.minorBlockedTitle.length, 40)
assert.equal(config.minorBlockedContent.length, 500)
})
test('底部引导图默认关闭,启用后保留上传图片对象', () => {
assert.deepEqual(DEFAULT_ORDER_SERVICE_BOTTOM_GUIDE_IMAGE_CONFIG, {
enabled: false,
image: {},
})
const config = normalizeOrderServiceBottomGuideImageConfig({
enabled: true,
image: {
objectKey: 'order-service-guide/2026/11/27/demo.png',
url: '/api/v1/files/object?key=order-service-guide%2F2026%2F11%2F27%2Fdemo.png',
contentType: 'image/png',
},
})
assert.equal(config.enabled, true)
assert.equal(config.image.objectKey, 'order-service-guide/2026/11/27/demo.png')
})
@@ -1,6 +1,5 @@
import { APP_CONFIG_KEYS } from '../../config/app-config-keys.js'
import type { JsonObject } from '../../types/json.js'
import { readAppConfigEntry, saveAppConfigEntry } from '../config/app-config-store.js'
import { normalizeUploadedFiles } from './worker-input-normalizers.js'
export type OrderServiceAgeGateConfig = {
enabled: boolean
@@ -14,6 +13,11 @@ export type OrderServiceAgeGateConfig = {
minorBlockedContent: string
}
export type OrderServiceBottomGuideImageConfig = {
enabled: boolean
image: Record<string, unknown>
}
export const DEFAULT_ORDER_SERVICE_AGE_GATE_CONTENT = `1. 购买商品和角色信息有没有错误
角色名/系统/区服有无遗漏
如未核对导致送错,本店概不负责哦~
@@ -42,26 +46,9 @@ export const DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG: OrderServiceAgeGateConfig =
'根据平台规则,本店无法向未成年人销售或操作发货。当前资料提交流程已停止,请勿继续操作。',
}
export function createDefaultOrderServiceAgeGateConfig(): OrderServiceAgeGateConfig {
return { ...DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG }
}
export function getOrderServiceAgeGateConfig(): OrderServiceAgeGateConfig {
return readAppConfigEntry({
configKey: APP_CONFIG_KEYS.orderServiceAgeGate,
fallback: createDefaultOrderServiceAgeGateConfig,
normalize: normalizeOrderServiceAgeGateConfig,
})
}
export async function saveOrderServiceAgeGateConfig(
rawValue: unknown,
): Promise<OrderServiceAgeGateConfig> {
return saveAppConfigEntry({
configKey: APP_CONFIG_KEYS.orderServiceAgeGate,
value: rawValue,
normalize: normalizeOrderServiceAgeGateConfig,
})
export const DEFAULT_ORDER_SERVICE_BOTTOM_GUIDE_IMAGE_CONFIG: OrderServiceBottomGuideImageConfig = {
enabled: false,
image: {},
}
export function normalizeOrderServiceAgeGateConfig(rawValue: unknown): OrderServiceAgeGateConfig {
@@ -84,6 +71,17 @@ export function normalizeOrderServiceAgeGateConfig(rawValue: unknown): OrderServ
}
}
export function normalizeOrderServiceBottomGuideImageConfig(
rawValue: unknown,
): OrderServiceBottomGuideImageConfig {
const source = isPlainObject(rawValue) ? rawValue : {}
const image = normalizeUploadedFiles([source.image])[0] || {}
return {
enabled: source.enabled === true,
image,
}
}
function textOrDefault(value: unknown, fallback: string, maxLength: number) {
const normalized = String(value ?? '')
.trim()
@@ -1,78 +0,0 @@
/**
* 工单补资料页未成年提示配置真实 PostgreSQL 集成测试。
*
* ORDER_SERVICE_AGE_GATE_TEST_DATABASE_URL=postgres://.../order_site_ctest \
* npx tsx --test src/services/worker-platform/order-service-age-gate-config.integration.test.ts
*/
import assert from 'node:assert/strict'
import test from 'node:test'
const TEST_DATABASE_URL = String(process.env.ORDER_SERVICE_AGE_GATE_TEST_DATABASE_URL || '').trim()
test(
'工单补资料页未成年提示配置可持久化并默认关闭',
{ skip: !TEST_DATABASE_URL ? '未设置 ORDER_SERVICE_AGE_GATE_TEST_DATABASE_URL' : false },
async () => {
process.env.DATABASE_URL = TEST_DATABASE_URL
const { closeDb, query } = await import('../../db/client.js')
const { loadAppConfigCacheFromDatabase } = await import('../config/app-config-store.js')
const { getOrderServiceAgeGateConfig, saveOrderServiceAgeGateConfig } =
await import('./order-service-age-gate-config-service.js')
let originalConfigJson: unknown = null
let hadOriginalConfig = false
try {
await loadAppConfigCacheFromDatabase()
const existing = await query<{ config_json: unknown }>(
`SELECT config_json FROM app_config_entries WHERE config_key = 'order_service_age_gate'`,
)
hadOriginalConfig = Boolean(existing.rows[0])
originalConfigJson = existing.rows[0]?.config_json ?? null
const defaults = getOrderServiceAgeGateConfig()
assert.equal(defaults.enabled, false)
assert.equal(defaults.title, '购买前必读')
await saveOrderServiceAgeGateConfig({
enabled: true,
title: '购买前确认',
warningText: '未成年人请勿购买',
content: '1. 请核对商品和角色信息',
importantNotice: '请警惕冒充售后诈骗',
adultButtonText: '已成年',
minorButtonText: '未成年',
minorBlockedTitle: '不能购买',
minorBlockedContent: '当前流程已停止',
})
const saved = getOrderServiceAgeGateConfig()
assert.equal(saved.enabled, true)
assert.equal(saved.title, '购买前确认')
assert.equal(saved.content, '1. 请核对商品和角色信息')
const persisted = await query<{
config_json: { enabled: boolean; title: string; content: string }
}>(`SELECT config_json FROM app_config_entries WHERE config_key = 'order_service_age_gate'`)
assert.equal(persisted.rows[0]?.config_json.enabled, true)
assert.equal(persisted.rows[0]?.config_json.title, '购买前确认')
assert.equal(persisted.rows[0]?.config_json.content, '1. 请核对商品和角色信息')
await saveOrderServiceAgeGateConfig({ enabled: false })
assert.equal(getOrderServiceAgeGateConfig().enabled, false)
} finally {
if (hadOriginalConfig) {
await query(
`UPDATE app_config_entries
SET config_json = $1::jsonb
WHERE config_key = 'order_service_age_gate'`,
[JSON.stringify(originalConfigJson ?? {})],
)
} else {
await query(`DELETE FROM app_config_entries WHERE config_key = 'order_service_age_gate'`)
}
await loadAppConfigCacheFromDatabase()
await closeDb()
}
},
)
@@ -0,0 +1,132 @@
/**
* 订单服务分类级未成年提示/底部引导图真实 PostgreSQL 集成测试。
*
* ORDER_SERVICE_CONTENT_TEST_DATABASE_URL=postgres://.../order_site_ctest \
* npx tsx --test src/services/worker-platform/order-service-content-config.integration.test.ts
*/
import assert from 'node:assert/strict'
import test from 'node:test'
const TEST_DATABASE_URL = String(process.env.ORDER_SERVICE_CONTENT_TEST_DATABASE_URL || '').trim()
test(
'分类订单服务草稿和发布版本都能保存未成年提示与底部引导图',
{ skip: !TEST_DATABASE_URL ? '未设置 ORDER_SERVICE_CONTENT_TEST_DATABASE_URL' : false },
async () => {
process.env.DATABASE_URL = TEST_DATABASE_URL
const { closeDb, query } = await import('../../db/client.js')
const { publishAdminOrderServiceProfile, saveAdminOrderServiceProfile } =
await import('./order-service-profile-service.js')
const suffix = `${Date.now()}-${process.pid}`
let categoryId = 0
let profileId = 0
try {
const category = await query<{ id: number }>(
`INSERT INTO work_categories
(category_key, name, sort_order, status, created_at, updated_at)
VALUES ($1, $2, 1, 'active', NOW(), NOW())
RETURNING id`,
[`order-service-content-test-${suffix}`, '订单服务内容测试分类'],
)
categoryId = Number(category.rows[0]?.id || 0)
const saved = await saveAdminOrderServiceProfile({
categoryId,
name: '订单服务内容测试',
title: '测试订单服务',
description: '',
guideImage: {},
guideImageDescription: '',
ageGate: {
enabled: true,
title: '测试未成年提示',
warningText: '测试警示',
content: '测试正文',
importantNotice: '测试重要提示',
adultButtonText: '我已成年',
minorButtonText: '我是未成年',
minorBlockedTitle: '不能购买',
minorBlockedContent: '流程停止',
},
bottomGuideImage: {
enabled: true,
image: {
objectKey: 'order-service-guide/integration/demo.png',
url: '/api/v1/files/object?key=order-service-guide%2Fintegration%2Fdemo.png',
contentType: 'image/png',
},
},
fields: [
{
key: 'gameId',
label: '游戏编号',
type: 'text',
validation: 'none',
required: false,
placeholder: '',
helpText: '',
options: [],
sortOrder: 10,
},
],
screenshots: { enabled: false, required: false, minCount: 0, maxCount: 5 },
autoPublish: { enabled: false, requireVoucherConsume: true, retryMax: 3 },
materialConfirmation: {
enabled: false,
title: '',
content: '',
confirmText: '',
cancelText: '',
},
statusSteps: {
submitted: { title: '提交资料', description: '' },
scheduled: { title: '客服安排', description: '' },
processing: { title: '订单处理', description: '' },
completed: { title: '交付完成', description: '' },
},
})
profileId = Number(saved.profile?.id || 0)
const draft = await query<{
age_gate_json: { enabled: boolean; title: string }
bottom_guide_image_json: { enabled: boolean; image: { objectKey?: string } }
}>(
`SELECT age_gate_json, bottom_guide_image_json
FROM order_service_profiles
WHERE id = $1`,
[profileId],
)
assert.equal(draft.rows[0]?.age_gate_json.enabled, true)
assert.equal(draft.rows[0]?.age_gate_json.title, '测试未成年提示')
assert.equal(draft.rows[0]?.bottom_guide_image_json.enabled, true)
assert.equal(
draft.rows[0]?.bottom_guide_image_json.image.objectKey,
'order-service-guide/integration/demo.png',
)
await publishAdminOrderServiceProfile(profileId)
const version = await query<{
config_json: { ageGate: { enabled: boolean }; bottomGuideImage: { enabled: boolean } }
}>(
`SELECT config_json
FROM order_service_profile_versions
WHERE profile_id = $1
ORDER BY version_no DESC
LIMIT 1`,
[profileId],
)
assert.equal(version.rows[0]?.config_json.ageGate.enabled, true)
assert.equal(version.rows[0]?.config_json.bottomGuideImage.enabled, true)
} finally {
if (profileId > 0) {
await query(`DELETE FROM order_service_profiles WHERE id = $1`, [profileId])
}
if (categoryId > 0) {
await query(`DELETE FROM work_categories WHERE id = $1`, [categoryId])
}
await closeDb()
}
},
)
@@ -221,3 +221,37 @@ test('订单服务配置:二级分类优先,未发布时沿分类链继承
assert.match(capturedSql, /ORDER BY chain\.depth ASC/)
assert.match(capturedSql, /p\.status <> 'archived'/)
})
test('分类订单服务配置包含未成年提示和独立底部引导图,旧配置默认关闭', () => {
const normalized = config()
assert.equal(normalized.ageGate.enabled, false)
assert.equal(normalized.bottomGuideImage.enabled, false)
assert.deepEqual(normalized.bottomGuideImage.image, {})
const custom = config({
ageGate: {
enabled: true,
title: '分类未成年提示',
warningText: '警示',
content: '正文',
importantNotice: '重要提示',
adultButtonText: '已成年',
minorButtonText: '未成年',
minorBlockedTitle: '不能购买',
minorBlockedContent: '已停止',
},
bottomGuideImage: {
enabled: true,
image: {
objectKey: 'order-service-guide/2026/11/27/demo.png',
url: '/api/v1/files/object?key=order-service-guide%2F2026%2F11%2F27%2Fdemo.png',
contentType: 'image/png',
},
},
})
assert.equal(custom.ageGate.enabled, true)
assert.equal(custom.ageGate.title, '分类未成年提示')
assert.equal(custom.bottomGuideImage.enabled, true)
assert.equal(custom.bottomGuideImage.image.objectKey, 'order-service-guide/2026/11/27/demo.png')
})
@@ -18,6 +18,14 @@ import {
} from '../../repositories/worker-platform/order-service-profile-repo.js'
import { listAllWorkCategories } from '../../repositories/worker-platform/work-category-repo.js'
import { normalizeUploadedFiles } from './worker-input-normalizers.js'
import {
DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG,
DEFAULT_ORDER_SERVICE_BOTTOM_GUIDE_IMAGE_CONFIG,
normalizeOrderServiceAgeGateConfig,
normalizeOrderServiceBottomGuideImageConfig,
type OrderServiceAgeGateConfig,
type OrderServiceBottomGuideImageConfig,
} from './order-service-age-gate-config-service.js'
export type OrderServiceFieldType = 'text' | 'textarea' | 'select' | 'radio' | 'number' | 'date'
export type OrderServiceFieldValidation = 'none' | 'digits'
@@ -70,6 +78,8 @@ export type OrderServiceProfileConfig = {
description: string
guideImage: Record<string, unknown>
guideImageDescription: string
ageGate: OrderServiceAgeGateConfig
bottomGuideImage: OrderServiceBottomGuideImageConfig
fields: OrderServiceField[]
screenshots: OrderServiceScreenshots
autoPublish: OrderServiceAutoPublish
@@ -168,6 +178,10 @@ export async function saveAdminOrderServiceProfile(payload: JsonObject = {}) {
payload.guideImage ?? payload.guide_image_json,
guideImageDescription,
)
const ageGate = normalizeOrderServiceAgeGateConfig(payload.ageGate ?? payload.age_gate_json)
const bottomGuideImage = normalizeOrderServiceBottomGuideImageConfig(
payload.bottomGuideImage ?? payload.bottom_guide_image_json,
)
const adminUserId = Number(payload.adminUserId ?? payload.admin_user_id ?? 0) || null
const saved = await upsertOrderServiceProfile({
@@ -176,6 +190,8 @@ export async function saveAdminOrderServiceProfile(payload: JsonObject = {}) {
title: text(payload.title, 80),
description: text(payload.description, 300),
guideImage,
ageGate,
bottomGuideImage,
fields,
screenshots,
autoPublish,
@@ -257,6 +273,8 @@ function mapAdminProfile(row: OrderServiceProfileRow) {
description: row.description,
guideImage: row.guide_image_json,
guideImageDescription: buildProfileConfig(row).guideImageDescription,
ageGate: buildProfileConfig(row).ageGate,
bottomGuideImage: buildProfileConfig(row).bottomGuideImage,
fields: buildProfileConfig(row).fields,
screenshots: row.screenshots_json,
autoPublish: row.auto_publish_json,
@@ -278,6 +296,8 @@ export function buildProfileConfig(row: {
title: string
description: string
guide_image_json: unknown
age_gate_json?: unknown
bottom_guide_image_json?: unknown
fields_json: unknown
screenshots_json: unknown
auto_publish_json: unknown
@@ -294,6 +314,8 @@ export function buildProfileConfig(row: {
description: row.description,
guideImage,
guideImageDescription: readGuideImageDescription(guideImage),
ageGate: normalizeOrderServiceAgeGateConfig(row.age_gate_json),
bottomGuideImage: normalizeOrderServiceBottomGuideImageConfig(row.bottom_guide_image_json),
fields: normalizeFields(row.fields_json),
screenshots: normalizeScreenshots(row.screenshots_json),
autoPublish: normalizeAutoPublish(row.auto_publish_json),
@@ -358,6 +380,8 @@ export function normalizeProfileConfig(value: JsonObject): OrderServiceProfileCo
description: text(value.description, 300),
guideImage,
guideImageDescription: readGuideImageDescription(guideImage),
ageGate: normalizeOrderServiceAgeGateConfig(value.ageGate),
bottomGuideImage: normalizeOrderServiceBottomGuideImageConfig(value.bottomGuideImage),
fields: normalizeFields(value.fields),
screenshots: normalizeScreenshots(value.screenshots),
autoPublish: normalizeAutoPublish(value.autoPublish),
@@ -48,7 +48,12 @@ import {
processDueOrderServiceAutoPublishJobs,
} from './order-service-auto-publish-service.js'
import { mapAcceptanceForResponse } from './work-order-material-mappers.js'
import { getOrderServiceAgeGateConfig } from './order-service-age-gate-config-service.js'
import {
DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG,
DEFAULT_ORDER_SERVICE_BOTTOM_GUIDE_IMAGE_CONFIG,
type OrderServiceAgeGateConfig,
type OrderServiceBottomGuideImageConfig,
} from './order-service-age-gate-config-service.js'
const PUBLIC_STATUS_MESSAGES: Record<string, string> = {
[WORK_ORDER_STATUS.PENDING_MATERIAL]: '请补充订单资料。',
@@ -100,6 +105,8 @@ export type OrderServicePublicItem = {
submittedAt?: string
acceptanceSubmittedAt?: string
acceptedAt?: string
ageGate?: OrderServiceAgeGateConfig
bottomGuideImage?: OrderServiceBottomGuideImageConfig
}
const PUBLIC_ACCEPTANCE_IMAGE_STATUSES = new Set<string>([
@@ -227,7 +234,6 @@ export async function getOrderServiceByPlatformOrderId(platformOrderIdInput: unk
platformOrderId,
items,
pendingCount: items.filter((item) => item.canSubmit).length,
ageGate: getOrderServiceAgeGateConfig(),
}
}
@@ -498,6 +504,15 @@ async function mapPublicOrderItem(order: WorkOrderRow): Promise<OrderServicePubl
.map(refreshUploadedFileUrls)
.filter(Boolean)
const ageGate = profile?.ageGate?.enabled ? profile.ageGate : undefined
const bottomGuideImage =
profile?.bottomGuideImage?.enabled && profile.bottomGuideImage.image
? {
enabled: true,
image: refreshUploadedFileUrls(profile.bottomGuideImage.image),
}
: undefined
const base: OrderServicePublicItem = {
workOrderId: Number(order.id),
productName: String(order.product_name || ''),
@@ -527,6 +542,8 @@ async function mapPublicOrderItem(order: WorkOrderRow): Promise<OrderServicePubl
...(profile?.materialConfirmation
? { materialConfirmation: profile.materialConfirmation }
: {}),
...(state.canSubmit && ageGate ? { ageGate } : {}),
...(state.canSubmit && bottomGuideImage ? { bottomGuideImage } : {}),
fields: profile?.fields || [],
values,
screenshots,
@@ -586,6 +603,8 @@ async function resolveProfileConfig(
description: '',
guideImage: {},
guideImageDescription: '',
ageGate: DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG,
bottomGuideImage: DEFAULT_ORDER_SERVICE_BOTTOM_GUIDE_IMAGE_CONFIG,
fields: normalizeProfileConfig({
name: '通用资料',
fields: legacy.fields,