新增(接单平台): 增加冻结账号售后微信提示
This commit is contained in:
@@ -98,3 +98,31 @@ test('履约状态集成接口要求密钥并接受空快照', async () => {
|
||||
await once(server, 'close')
|
||||
}
|
||||
})
|
||||
test('售后微信公开接口无需登录且关闭时不泄露联系方式', async () => {
|
||||
const startupState = createStartupState()
|
||||
startupState.core.ready = true
|
||||
const config = createDefaultRuntimeConfig('/tmp/order-site')
|
||||
const server = createApp({
|
||||
startupState,
|
||||
isShutdownStarted: () => false,
|
||||
config,
|
||||
}).listen(0, '127.0.0.1')
|
||||
await once(server, 'listening')
|
||||
|
||||
try {
|
||||
const address = server.address()
|
||||
assert.ok(address && typeof address === 'object')
|
||||
const response = await fetch(`http://127.0.0.1:${address.port}/api/v1/worker/support-contact`)
|
||||
assert.equal(response.status, 200)
|
||||
assert.equal(response.headers.get('cache-control'), 'no-store')
|
||||
assert.deepEqual((await response.json()).data, {
|
||||
enabled: false,
|
||||
wechatId: '',
|
||||
wechatQrCodeImage: null,
|
||||
notice: '',
|
||||
})
|
||||
} finally {
|
||||
server.close()
|
||||
await once(server, 'close')
|
||||
}
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ export const APP_CONFIG_KEYS = {
|
||||
workerPlatformNotifications: 'worker_platform_notifications',
|
||||
workerProductMatch: 'worker_product_match',
|
||||
workerAnnouncement: 'worker_announcement',
|
||||
workerSupportContact: 'worker_support_contact',
|
||||
workerHall: 'worker_hall',
|
||||
/** 商品名来源后缀:按 material.source.provider 在商品名后追加(文字),仅展示用 */
|
||||
workerProductNameSuffix: 'worker_product_name_suffix',
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
getAdminWorkerPlatformSummary,
|
||||
getAdminWorkerProductMatchConfig,
|
||||
getAdminWorkerProductNameSuffixConfig,
|
||||
getAdminWorkerSupportContactConfig,
|
||||
listAdminKuaishouMatchSources,
|
||||
listAdminWorkCategories,
|
||||
listAdminWorkProductMatchLogs,
|
||||
@@ -36,6 +37,7 @@ import {
|
||||
saveAdminWorkerPlatformNotificationConfig,
|
||||
saveAdminWorkerProductMatchConfig,
|
||||
saveAdminWorkerProductNameSuffixConfig,
|
||||
saveAdminWorkerSupportContactConfig,
|
||||
retryAdminOrderServiceAutoPublishJob,
|
||||
syncAdminWorkProductRulePrice,
|
||||
testAdminKuaishouProductMatch,
|
||||
@@ -374,6 +376,33 @@ router.post(
|
||||
}),
|
||||
)
|
||||
|
||||
router.get(
|
||||
'/worker-platform/support-contact',
|
||||
requireAdminRoles(['admin']),
|
||||
setHttpCache(0),
|
||||
createJsonHandler(() => getAdminWorkerSupportContactConfig(), {
|
||||
successMessage: 'ok',
|
||||
errorMessage: '读取售后微信配置失败',
|
||||
scope: '[admin/worker-platform/support-contact]',
|
||||
}),
|
||||
)
|
||||
|
||||
router.post(
|
||||
'/worker-platform/support-contact',
|
||||
requireAdminRoles(['admin']),
|
||||
createJsonHandler((req) => saveAdminWorkerSupportContactConfig(req.body || {}), {
|
||||
successMessage: '售后微信配置已保存',
|
||||
errorMessage: '保存售后微信配置失败',
|
||||
scope: '[admin/worker-platform/support-contact]',
|
||||
audit: (_req, data) => ({
|
||||
action: 'worker_support_contact_saved',
|
||||
targetType: 'worker_support_contact',
|
||||
targetId: 'worker_support_contact',
|
||||
data: data && typeof data === 'object' ? (data as Record<string, unknown>) : {},
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
router.get(
|
||||
'/worker-platform/product-name-suffix',
|
||||
requireAdminRoles(['admin', 'operator', 'support']),
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Router } from 'express'
|
||||
import { createRateLimitMiddleware, getBodyFieldRateLimitKey } from '../../middleware/rate-limit.js'
|
||||
import {
|
||||
deleteWorkerSessionWithCredentials,
|
||||
getPublicWorkerSupportContact,
|
||||
getWorkerSessionSummary,
|
||||
loginWorker,
|
||||
loginWorkerBySmsCode,
|
||||
@@ -182,6 +183,21 @@ router.post(
|
||||
),
|
||||
)
|
||||
|
||||
router.get(
|
||||
'/support-contact',
|
||||
createRouteHandler(
|
||||
(_req, res) => {
|
||||
res.setHeader('Cache-Control', 'no-store')
|
||||
return getPublicWorkerSupportContact()
|
||||
},
|
||||
{
|
||||
successMessage: 'ok',
|
||||
errorMessage: '读取售后微信配置失败',
|
||||
scope: '[worker/support-contact]',
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
router.get(
|
||||
'/auth/session',
|
||||
createRouteHandler((req, res) => getWorkerSessionSummary(extractWorkerBearerToken(req), res), {
|
||||
|
||||
@@ -16,6 +16,10 @@ import {
|
||||
getWorkerProductNameSuffixConfig,
|
||||
saveWorkerProductNameSuffixConfig,
|
||||
} from './worker-product-name-suffix-service.js'
|
||||
import {
|
||||
getWorkerSupportContactConfig,
|
||||
saveWorkerSupportContactConfig,
|
||||
} from './worker-support-contact-config-service.js'
|
||||
|
||||
export async function getAdminWorkerPlatformNotificationConfig() {
|
||||
return getWorkerPlatformNotificationConfig()
|
||||
@@ -65,3 +69,11 @@ export async function pruneAdminWorkProductMatchLogs(payload: JsonObject = {}) {
|
||||
: config.matchLogRetentionDays,
|
||||
})
|
||||
}
|
||||
|
||||
export async function getAdminWorkerSupportContactConfig() {
|
||||
return getWorkerSupportContactConfig()
|
||||
}
|
||||
|
||||
export async function saveAdminWorkerSupportContactConfig(payload: JsonObject = {}) {
|
||||
return saveWorkerSupportContactConfig(payload)
|
||||
}
|
||||
|
||||
@@ -60,6 +60,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 './worker-support-contact-config-service.js'
|
||||
export * from './worker-hall-config-service.js'
|
||||
export * from './worker-product-name-suffix-service.js'
|
||||
export * from './worker-acceptance-config-service.js'
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
DEFAULT_WORKER_SUPPORT_CONTACT_NOTICE,
|
||||
normalizeWorkerSupportContactConfig,
|
||||
saveWorkerSupportContactConfig,
|
||||
toPublicWorkerSupportContact,
|
||||
} from './worker-support-contact-config-service.js'
|
||||
|
||||
test('售后微信配置默认关闭,关闭时不公开联系方式', () => {
|
||||
const config = normalizeWorkerSupportContactConfig({
|
||||
wechatId: ' after_sales_wechat ',
|
||||
notice: ' 有问题请联系售后 ',
|
||||
wechatQrCodeImage: {
|
||||
objectKey: 'worker-support-contact/2026/11/24/qr.png',
|
||||
filename: 'qr.png',
|
||||
},
|
||||
})
|
||||
|
||||
assert.equal(config.enabled, false)
|
||||
assert.equal(config.wechatId, 'after_sales_wechat')
|
||||
assert.equal(config.notice, '有问题请联系售后')
|
||||
assert.equal(config.wechatQrCodeImage?.objectKey, 'worker-support-contact/2026/11/24/qr.png')
|
||||
|
||||
assert.deepEqual(toPublicWorkerSupportContact(config), {
|
||||
enabled: false,
|
||||
wechatId: '',
|
||||
wechatQrCodeImage: null,
|
||||
notice: '',
|
||||
})
|
||||
})
|
||||
|
||||
test('售后微信启用后公开微信号、二维码和提示文案', () => {
|
||||
const config = normalizeWorkerSupportContactConfig({
|
||||
enabled: true,
|
||||
wechatId: 'after_sales_wechat',
|
||||
notice: '',
|
||||
wechatQrCodeImage: {
|
||||
objectKey: 'worker-support-contact/2026/11/24/qr.png',
|
||||
url: '/api/v1/files/object?key=worker-support-contact%2F2026%2F11%2F24%2Fqr.png',
|
||||
filename: 'qr.png',
|
||||
contentType: 'image/png',
|
||||
size: 1024,
|
||||
},
|
||||
})
|
||||
|
||||
assert.equal(config.notice, DEFAULT_WORKER_SUPPORT_CONTACT_NOTICE)
|
||||
const publicContact = toPublicWorkerSupportContact(config)
|
||||
assert.equal(publicContact.enabled, true)
|
||||
assert.equal(publicContact.wechatId, 'after_sales_wechat')
|
||||
assert.equal(publicContact.notice, DEFAULT_WORKER_SUPPORT_CONTACT_NOTICE)
|
||||
assert.equal(publicContact.wechatQrCodeImage?.filename, 'qr.png')
|
||||
})
|
||||
test('启用售后微信时至少要求微信号或二维码', async () => {
|
||||
await assert.rejects(
|
||||
() =>
|
||||
saveWorkerSupportContactConfig({
|
||||
enabled: true,
|
||||
wechatId: ' ',
|
||||
notice: '',
|
||||
wechatQrCodeImage: null,
|
||||
}),
|
||||
/至少配置微信号或二维码/,
|
||||
)
|
||||
})
|
||||
@@ -0,0 +1,139 @@
|
||||
import { APP_CONFIG_KEYS } from '../../config/app-config-keys.js'
|
||||
import type { JsonObject } from '../../types/json.js'
|
||||
import { createHttpError } from '../../utils/http.js'
|
||||
import { readAppConfigEntry, saveAppConfigEntry } from '../config/app-config-store.js'
|
||||
import {
|
||||
normalizeStoredFileUrl,
|
||||
refreshUploadedFileUrls,
|
||||
type UploadedFileDto,
|
||||
} from '../file-storage/file-storage-service.js'
|
||||
|
||||
export const DEFAULT_WORKER_SUPPORT_CONTACT_NOTICE = '账号已被冻结,如有疑问请添加售后微信处理。'
|
||||
|
||||
export type WorkerSupportContactConfig = {
|
||||
enabled: boolean
|
||||
wechatId: string
|
||||
wechatQrCodeImage: UploadedFileDto | null
|
||||
notice: string
|
||||
}
|
||||
|
||||
export type PublicWorkerSupportContact = {
|
||||
enabled: boolean
|
||||
wechatId: string
|
||||
wechatQrCodeImage: UploadedFileDto | null
|
||||
notice: string
|
||||
}
|
||||
|
||||
export function getWorkerSupportContactConfig(): WorkerSupportContactConfig {
|
||||
const config = readAppConfigEntry({
|
||||
configKey: APP_CONFIG_KEYS.workerSupportContact,
|
||||
fallback: createDefaultWorkerSupportContactConfig,
|
||||
normalize: normalizeWorkerSupportContactConfig,
|
||||
})
|
||||
return refreshWorkerSupportContactConfig(config)
|
||||
}
|
||||
|
||||
export function getPublicWorkerSupportContact(): PublicWorkerSupportContact {
|
||||
return toPublicWorkerSupportContact(getWorkerSupportContactConfig())
|
||||
}
|
||||
|
||||
export function toPublicWorkerSupportContact(
|
||||
config: WorkerSupportContactConfig,
|
||||
): PublicWorkerSupportContact {
|
||||
if (!config.enabled) {
|
||||
return {
|
||||
enabled: false,
|
||||
wechatId: '',
|
||||
wechatQrCodeImage: null,
|
||||
notice: '',
|
||||
}
|
||||
}
|
||||
return {
|
||||
enabled: true,
|
||||
wechatId: config.wechatId,
|
||||
wechatQrCodeImage: config.wechatQrCodeImage,
|
||||
notice: config.notice,
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveWorkerSupportContactConfig(
|
||||
rawValue: unknown,
|
||||
): Promise<WorkerSupportContactConfig> {
|
||||
const normalized = normalizeWorkerSupportContactConfig(rawValue)
|
||||
if (normalized.enabled && !normalized.wechatId && !normalized.wechatQrCodeImage) {
|
||||
throw createHttpError('启用售后微信后,请至少配置微信号或二维码', {
|
||||
statusCode: 400,
|
||||
errorCode: 'worker_support_contact_required',
|
||||
})
|
||||
}
|
||||
return saveAppConfigEntry({
|
||||
configKey: APP_CONFIG_KEYS.workerSupportContact,
|
||||
value: normalized,
|
||||
normalize: normalizeWorkerSupportContactConfig,
|
||||
})
|
||||
}
|
||||
|
||||
export function createDefaultWorkerSupportContactConfig(): WorkerSupportContactConfig {
|
||||
return {
|
||||
enabled: false,
|
||||
wechatId: '',
|
||||
wechatQrCodeImage: null,
|
||||
notice: DEFAULT_WORKER_SUPPORT_CONTACT_NOTICE,
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeWorkerSupportContactConfig(rawValue: unknown): WorkerSupportContactConfig {
|
||||
const source = isPlainObject(rawValue) ? rawValue : {}
|
||||
const wechatId = String(source.wechatId || source.wechat_id || '')
|
||||
.trim()
|
||||
.slice(0, 64)
|
||||
const notice = String(source.notice || source.tip || '')
|
||||
.trim()
|
||||
.slice(0, 240)
|
||||
return {
|
||||
enabled: source.enabled === true,
|
||||
wechatId,
|
||||
wechatQrCodeImage: normalizeUploadedFileForStorage(
|
||||
source.wechatQrCodeImage || source.wechat_qr_code_image || source.qrCodeImage,
|
||||
'售后微信二维码',
|
||||
),
|
||||
notice: notice || DEFAULT_WORKER_SUPPORT_CONTACT_NOTICE,
|
||||
}
|
||||
}
|
||||
|
||||
function refreshWorkerSupportContactConfig(
|
||||
config: WorkerSupportContactConfig,
|
||||
): WorkerSupportContactConfig {
|
||||
return {
|
||||
...config,
|
||||
wechatQrCodeImage: config.wechatQrCodeImage
|
||||
? (refreshUploadedFileUrls(config.wechatQrCodeImage) as UploadedFileDto)
|
||||
: null,
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeUploadedFileForStorage(
|
||||
value: unknown,
|
||||
fallbackFilename: string,
|
||||
): UploadedFileDto | null {
|
||||
if (!isPlainObject(value)) {
|
||||
return null
|
||||
}
|
||||
const objectKey = String(value.objectKey || value.object_key || '').trim()
|
||||
if (!objectKey) {
|
||||
return null
|
||||
}
|
||||
return {
|
||||
objectKey,
|
||||
url: normalizeStoredFileUrl(value.url, objectKey),
|
||||
thumbnailUrl: normalizeStoredFileUrl(value.thumbnailUrl || value.thumbnail_url, objectKey),
|
||||
mediumUrl: normalizeStoredFileUrl(value.mediumUrl || value.medium_url, objectKey),
|
||||
filename: String(value.filename || '').trim() || fallbackFilename,
|
||||
contentType: String(value.contentType || value.content_type || '').trim(),
|
||||
size: Math.max(0, Number(value.size || 0) || 0),
|
||||
}
|
||||
}
|
||||
|
||||
function isPlainObject(value: unknown): value is JsonObject {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* 售后微信配置真实 PostgreSQL 集成测试。
|
||||
*
|
||||
* WORKER_SUPPORT_CONTACT_TEST_DATABASE_URL=postgres://.../order_site_ctest \
|
||||
* npx tsx --test src/services/worker-platform/worker-support-contact-config.integration.test.ts
|
||||
*/
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
const TEST_DATABASE_URL = String(process.env.WORKER_SUPPORT_CONTACT_TEST_DATABASE_URL || '').trim()
|
||||
|
||||
test(
|
||||
'售后微信配置可持久化并按启用状态公开',
|
||||
{ skip: !TEST_DATABASE_URL ? '未设置 WORKER_SUPPORT_CONTACT_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 {
|
||||
getPublicWorkerSupportContact,
|
||||
getWorkerSupportContactConfig,
|
||||
saveWorkerSupportContactConfig,
|
||||
} = await import('./worker-support-contact-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 = 'worker_support_contact'`,
|
||||
)
|
||||
hadOriginalConfig = Boolean(existing.rows[0])
|
||||
originalConfigJson = existing.rows[0]?.config_json ?? null
|
||||
|
||||
await saveWorkerSupportContactConfig({
|
||||
enabled: true,
|
||||
wechatId: 'after_sales_wechat',
|
||||
notice: '账号冻结后请联系售后微信',
|
||||
wechatQrCodeImage: {
|
||||
objectKey: 'worker-support-contact/2026/11/24/integration-qr.png',
|
||||
filename: 'integration-qr.png',
|
||||
contentType: 'image/png',
|
||||
size: 2048,
|
||||
},
|
||||
})
|
||||
|
||||
const saved = getWorkerSupportContactConfig()
|
||||
assert.equal(saved.enabled, true)
|
||||
assert.equal(saved.wechatId, 'after_sales_wechat')
|
||||
assert.equal(
|
||||
saved.wechatQrCodeImage?.objectKey,
|
||||
'worker-support-contact/2026/11/24/integration-qr.png',
|
||||
)
|
||||
|
||||
const persisted = await query<{ config_json: { enabled: boolean; wechatId: string } }>(
|
||||
`SELECT config_json FROM app_config_entries WHERE config_key = 'worker_support_contact'`,
|
||||
)
|
||||
assert.equal(persisted.rows[0]?.config_json.enabled, true)
|
||||
assert.equal(persisted.rows[0]?.config_json.wechatId, 'after_sales_wechat')
|
||||
|
||||
const publicContact = getPublicWorkerSupportContact()
|
||||
assert.equal(publicContact.enabled, true)
|
||||
assert.equal(publicContact.wechatId, 'after_sales_wechat')
|
||||
|
||||
await saveWorkerSupportContactConfig({
|
||||
enabled: false,
|
||||
wechatId: 'after_sales_wechat',
|
||||
notice: '',
|
||||
wechatQrCodeImage: null,
|
||||
})
|
||||
assert.deepEqual(getPublicWorkerSupportContact(), {
|
||||
enabled: false,
|
||||
wechatId: '',
|
||||
wechatQrCodeImage: null,
|
||||
notice: '',
|
||||
})
|
||||
} finally {
|
||||
if (hadOriginalConfig) {
|
||||
await query(
|
||||
`UPDATE app_config_entries
|
||||
SET config_json = $1::jsonb
|
||||
WHERE config_key = 'worker_support_contact'`,
|
||||
[JSON.stringify(originalConfigJson ?? {})],
|
||||
)
|
||||
} else {
|
||||
await query(`DELETE FROM app_config_entries WHERE config_key = 'worker_support_contact'`)
|
||||
}
|
||||
await loadAppConfigCacheFromDatabase()
|
||||
await closeDb()
|
||||
}
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user