功能(订单服务): 增加可配置未成年提示门禁
This commit is contained in:
@@ -6,6 +6,8 @@ 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 在商品名后追加(文字),仅展示用 */
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
deleteAdminWorkProductRule,
|
||||
deleteAdminWorkProductRuleMapping,
|
||||
deleteAdminWorkerLevel,
|
||||
getAdminOrderServiceAgeGateConfig,
|
||||
getAdminWorkerAnnouncementConfig,
|
||||
getAdminWorkerFinanceConfig,
|
||||
getAdminWorkerHallConfig,
|
||||
@@ -25,6 +26,7 @@ import {
|
||||
saveAdminWorkCategory,
|
||||
saveAdminWorkProductRule,
|
||||
saveAdminWorkProductRuleMapping,
|
||||
saveAdminOrderServiceAgeGateConfig,
|
||||
saveAdminWorkerAnnouncementConfig,
|
||||
archiveAdminOrderServiceProfile,
|
||||
listAdminOrderServiceAutoPublishJobs,
|
||||
@@ -376,6 +378,33 @@ router.post(
|
||||
}),
|
||||
)
|
||||
|
||||
router.get(
|
||||
'/worker-platform/order-service-age-gate',
|
||||
requireAdminRoles(['admin']),
|
||||
setHttpCache(0),
|
||||
createJsonHandler(() => getAdminOrderServiceAgeGateConfig(), {
|
||||
successMessage: 'ok',
|
||||
errorMessage: '读取工单补资料页未成年提示失败',
|
||||
scope: '[admin/worker-platform/order-service-age-gate]',
|
||||
}),
|
||||
)
|
||||
|
||||
router.post(
|
||||
'/worker-platform/order-service-age-gate',
|
||||
requireAdminRoles(['admin']),
|
||||
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',
|
||||
requireAdminRoles(['admin']),
|
||||
|
||||
@@ -4,6 +4,10 @@ import {
|
||||
getWorkerAnnouncementConfig,
|
||||
saveWorkerAnnouncementConfig,
|
||||
} from './worker-announcement-config-service.js'
|
||||
import {
|
||||
getOrderServiceAgeGateConfig,
|
||||
saveOrderServiceAgeGateConfig,
|
||||
} from './order-service-age-gate-config-service.js'
|
||||
import {
|
||||
getWorkerPlatformNotificationConfig,
|
||||
saveWorkerPlatformNotificationConfig,
|
||||
@@ -41,6 +45,14 @@ 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)
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ export {
|
||||
} from './admin-work-order-acceptance-service.js'
|
||||
export * from './worker-product-match-config-service.js'
|
||||
export * from './worker-announcement-config-service.js'
|
||||
export * from './order-service-age-gate-config-service.js'
|
||||
export * from './worker-support-contact-config-service.js'
|
||||
export * from './worker-hall-config-service.js'
|
||||
export * from './worker-product-name-suffix-service.js'
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
DEFAULT_ORDER_SERVICE_AGE_GATE_CONTENT,
|
||||
normalizeOrderServiceAgeGateConfig,
|
||||
} from './order-service-age-gate-config-service.js'
|
||||
|
||||
test('工单补资料页未成年提示默认关闭,并带完整通用文案', () => {
|
||||
const config = normalizeOrderServiceAgeGateConfig({})
|
||||
|
||||
assert.equal(config.enabled, false)
|
||||
assert.equal(config.title, '购买前必读')
|
||||
assert.equal(config.warningText, '无法向未成年人操作发货,请认真阅读作答!!!')
|
||||
assert.equal(config.adultButtonText, '我已成年')
|
||||
assert.equal(config.minorButtonText, '我是未成年')
|
||||
assert.equal(config.minorBlockedTitle, '未成年不能购买')
|
||||
assert.equal(config.content, DEFAULT_ORDER_SERVICE_AGE_GATE_CONTENT)
|
||||
assert.match(config.content, /购买商品和角色信息有没有错误/)
|
||||
assert.doesNotMatch(config.content, /苏尔南|鉴定物珍宝/)
|
||||
assert.match(config.importantNotice, /冒充本店售后专员/)
|
||||
})
|
||||
|
||||
test('只有显式启用才生效,空文本回退默认值并裁剪首尾空白', () => {
|
||||
const config = normalizeOrderServiceAgeGateConfig({
|
||||
enabled: true,
|
||||
title: ' 购买说明 ',
|
||||
warningText: ' ',
|
||||
content: ' 1. 请核对角色信息 ',
|
||||
importantNotice: ' ',
|
||||
adultButtonText: ' 已成年 ',
|
||||
minorButtonText: '',
|
||||
minorBlockedTitle: ' 未成年拦截 ',
|
||||
minorBlockedContent: ' ',
|
||||
})
|
||||
|
||||
assert.equal(config.enabled, true)
|
||||
assert.equal(config.title, '购买说明')
|
||||
assert.equal(config.warningText, '无法向未成年人操作发货,请认真阅读作答!!!')
|
||||
assert.equal(config.content, '1. 请核对角色信息')
|
||||
assert.equal(
|
||||
config.importantNotice,
|
||||
'【重要提示】近期有人冒充本店售后专员,以“道具回收”为由实施诈骗。请广大玩家务必以本店官方售后渠道为准,谨防上当受骗。',
|
||||
)
|
||||
assert.equal(config.adultButtonText, '已成年')
|
||||
assert.equal(config.minorButtonText, '我是未成年')
|
||||
assert.equal(config.minorBlockedTitle, '未成年拦截')
|
||||
assert.equal(
|
||||
config.minorBlockedContent,
|
||||
'根据平台规则,本店无法向未成年人销售或操作发货。当前资料提交流程已停止,请勿继续操作。',
|
||||
)
|
||||
})
|
||||
|
||||
test('非布尔启用值和超长文本不会穿透配置边界', () => {
|
||||
const config = normalizeOrderServiceAgeGateConfig({
|
||||
enabled: 'true',
|
||||
title: '标'.repeat(80),
|
||||
warningText: '警'.repeat(260),
|
||||
content: '文'.repeat(2200),
|
||||
importantNotice: '重'.repeat(600),
|
||||
adultButtonText: '已'.repeat(20),
|
||||
minorButtonText: '未'.repeat(20),
|
||||
minorBlockedTitle: '拦'.repeat(80),
|
||||
minorBlockedContent: '止'.repeat(600),
|
||||
})
|
||||
|
||||
assert.equal(config.enabled, false)
|
||||
assert.equal(config.title.length, 40)
|
||||
assert.equal(config.warningText.length, 200)
|
||||
assert.equal(config.content.length, 2000)
|
||||
assert.equal(config.importantNotice.length, 500)
|
||||
assert.equal(config.adultButtonText.length, 12)
|
||||
assert.equal(config.minorButtonText.length, 12)
|
||||
assert.equal(config.minorBlockedTitle.length, 40)
|
||||
assert.equal(config.minorBlockedContent.length, 500)
|
||||
})
|
||||
@@ -0,0 +1,96 @@
|
||||
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'
|
||||
|
||||
export type OrderServiceAgeGateConfig = {
|
||||
enabled: boolean
|
||||
title: string
|
||||
warningText: string
|
||||
content: string
|
||||
importantNotice: string
|
||||
adultButtonText: string
|
||||
minorButtonText: string
|
||||
minorBlockedTitle: string
|
||||
minorBlockedContent: string
|
||||
}
|
||||
|
||||
export const DEFAULT_ORDER_SERVICE_AGE_GATE_CONTENT = `1. 购买商品和角色信息有没有错误
|
||||
角色名/系统/区服有无遗漏
|
||||
如未核对导致送错,本店概不负责哦~
|
||||
|
||||
2. 购买本人实际为成年用户!!
|
||||
|
||||
3. 虚拟商品到您的游戏里,一旦发货完成,概不退款。
|
||||
|
||||
4. 发货时间具体以排单顺序为准,活动期间可能会延迟送达,未发货前协商可退。
|
||||
|
||||
5. 由于市场成本原因,价格会有所浮动,不支持以此原因退差价。
|
||||
|
||||
6. 禁止私自交易,私自交易被骗本店概不负责!!!!`
|
||||
|
||||
export const DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG: OrderServiceAgeGateConfig = {
|
||||
enabled: false,
|
||||
title: '购买前必读',
|
||||
warningText: '无法向未成年人操作发货,请认真阅读作答!!!',
|
||||
content: DEFAULT_ORDER_SERVICE_AGE_GATE_CONTENT,
|
||||
importantNotice:
|
||||
'【重要提示】近期有人冒充本店售后专员,以“道具回收”为由实施诈骗。请广大玩家务必以本店官方售后渠道为准,谨防上当受骗。',
|
||||
adultButtonText: '我已成年',
|
||||
minorButtonText: '我是未成年',
|
||||
minorBlockedTitle: '未成年不能购买',
|
||||
minorBlockedContent:
|
||||
'根据平台规则,本店无法向未成年人销售或操作发货。当前资料提交流程已停止,请勿继续操作。',
|
||||
}
|
||||
|
||||
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 function normalizeOrderServiceAgeGateConfig(rawValue: unknown): OrderServiceAgeGateConfig {
|
||||
const source = isPlainObject(rawValue) ? rawValue : {}
|
||||
const defaults = DEFAULT_ORDER_SERVICE_AGE_GATE_CONFIG
|
||||
return {
|
||||
enabled: source.enabled === true,
|
||||
title: textOrDefault(source.title, defaults.title, 40),
|
||||
warningText: textOrDefault(source.warningText, defaults.warningText, 200),
|
||||
content: textOrDefault(source.content, defaults.content, 2000),
|
||||
importantNotice: textOrDefault(source.importantNotice, defaults.importantNotice, 500),
|
||||
adultButtonText: textOrDefault(source.adultButtonText, defaults.adultButtonText, 12),
|
||||
minorButtonText: textOrDefault(source.minorButtonText, defaults.minorButtonText, 12),
|
||||
minorBlockedTitle: textOrDefault(source.minorBlockedTitle, defaults.minorBlockedTitle, 40),
|
||||
minorBlockedContent: textOrDefault(
|
||||
source.minorBlockedContent,
|
||||
defaults.minorBlockedContent,
|
||||
500,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
function textOrDefault(value: unknown, fallback: string, maxLength: number) {
|
||||
const normalized = String(value ?? '')
|
||||
.trim()
|
||||
.slice(0, maxLength)
|
||||
return normalized || fallback
|
||||
}
|
||||
|
||||
function isPlainObject(value: unknown): value is JsonObject {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* 工单补资料页未成年提示配置真实 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()
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -48,6 +48,7 @@ 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'
|
||||
|
||||
const PUBLIC_STATUS_MESSAGES: Record<string, string> = {
|
||||
[WORK_ORDER_STATUS.PENDING_MATERIAL]: '请补充订单资料。',
|
||||
@@ -226,6 +227,7 @@ export async function getOrderServiceByPlatformOrderId(platformOrderIdInput: unk
|
||||
platformOrderId,
|
||||
items,
|
||||
pendingCount: items.filter((item) => item.canSubmit).length,
|
||||
ageGate: getOrderServiceAgeGateConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user