新增(接单平台): 增加冻结账号售后微信提示
This commit is contained in:
@@ -98,3 +98,31 @@ test('履约状态集成接口要求密钥并接受空快照', async () => {
|
|||||||
await once(server, 'close')
|
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',
|
workerPlatformNotifications: 'worker_platform_notifications',
|
||||||
workerProductMatch: 'worker_product_match',
|
workerProductMatch: 'worker_product_match',
|
||||||
workerAnnouncement: 'worker_announcement',
|
workerAnnouncement: 'worker_announcement',
|
||||||
|
workerSupportContact: 'worker_support_contact',
|
||||||
workerHall: 'worker_hall',
|
workerHall: 'worker_hall',
|
||||||
/** 商品名来源后缀:按 material.source.provider 在商品名后追加(文字),仅展示用 */
|
/** 商品名来源后缀:按 material.source.provider 在商品名后追加(文字),仅展示用 */
|
||||||
workerProductNameSuffix: 'worker_product_name_suffix',
|
workerProductNameSuffix: 'worker_product_name_suffix',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
getAdminWorkerPlatformSummary,
|
getAdminWorkerPlatformSummary,
|
||||||
getAdminWorkerProductMatchConfig,
|
getAdminWorkerProductMatchConfig,
|
||||||
getAdminWorkerProductNameSuffixConfig,
|
getAdminWorkerProductNameSuffixConfig,
|
||||||
|
getAdminWorkerSupportContactConfig,
|
||||||
listAdminKuaishouMatchSources,
|
listAdminKuaishouMatchSources,
|
||||||
listAdminWorkCategories,
|
listAdminWorkCategories,
|
||||||
listAdminWorkProductMatchLogs,
|
listAdminWorkProductMatchLogs,
|
||||||
@@ -36,6 +37,7 @@ import {
|
|||||||
saveAdminWorkerPlatformNotificationConfig,
|
saveAdminWorkerPlatformNotificationConfig,
|
||||||
saveAdminWorkerProductMatchConfig,
|
saveAdminWorkerProductMatchConfig,
|
||||||
saveAdminWorkerProductNameSuffixConfig,
|
saveAdminWorkerProductNameSuffixConfig,
|
||||||
|
saveAdminWorkerSupportContactConfig,
|
||||||
retryAdminOrderServiceAutoPublishJob,
|
retryAdminOrderServiceAutoPublishJob,
|
||||||
syncAdminWorkProductRulePrice,
|
syncAdminWorkProductRulePrice,
|
||||||
testAdminKuaishouProductMatch,
|
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(
|
router.get(
|
||||||
'/worker-platform/product-name-suffix',
|
'/worker-platform/product-name-suffix',
|
||||||
requireAdminRoles(['admin', 'operator', 'support']),
|
requireAdminRoles(['admin', 'operator', 'support']),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Router } from 'express'
|
|||||||
import { createRateLimitMiddleware, getBodyFieldRateLimitKey } from '../../middleware/rate-limit.js'
|
import { createRateLimitMiddleware, getBodyFieldRateLimitKey } from '../../middleware/rate-limit.js'
|
||||||
import {
|
import {
|
||||||
deleteWorkerSessionWithCredentials,
|
deleteWorkerSessionWithCredentials,
|
||||||
|
getPublicWorkerSupportContact,
|
||||||
getWorkerSessionSummary,
|
getWorkerSessionSummary,
|
||||||
loginWorker,
|
loginWorker,
|
||||||
loginWorkerBySmsCode,
|
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(
|
router.get(
|
||||||
'/auth/session',
|
'/auth/session',
|
||||||
createRouteHandler((req, res) => getWorkerSessionSummary(extractWorkerBearerToken(req), res), {
|
createRouteHandler((req, res) => getWorkerSessionSummary(extractWorkerBearerToken(req), res), {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ import {
|
|||||||
getWorkerProductNameSuffixConfig,
|
getWorkerProductNameSuffixConfig,
|
||||||
saveWorkerProductNameSuffixConfig,
|
saveWorkerProductNameSuffixConfig,
|
||||||
} from './worker-product-name-suffix-service.js'
|
} from './worker-product-name-suffix-service.js'
|
||||||
|
import {
|
||||||
|
getWorkerSupportContactConfig,
|
||||||
|
saveWorkerSupportContactConfig,
|
||||||
|
} from './worker-support-contact-config-service.js'
|
||||||
|
|
||||||
export async function getAdminWorkerPlatformNotificationConfig() {
|
export async function getAdminWorkerPlatformNotificationConfig() {
|
||||||
return getWorkerPlatformNotificationConfig()
|
return getWorkerPlatformNotificationConfig()
|
||||||
@@ -65,3 +69,11 @@ export async function pruneAdminWorkProductMatchLogs(payload: JsonObject = {}) {
|
|||||||
: config.matchLogRetentionDays,
|
: 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'
|
} from './admin-work-order-acceptance-service.js'
|
||||||
export * from './worker-product-match-config-service.js'
|
export * from './worker-product-match-config-service.js'
|
||||||
export * from './worker-announcement-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-hall-config-service.js'
|
||||||
export * from './worker-product-name-suffix-service.js'
|
export * from './worker-product-name-suffix-service.js'
|
||||||
export * from './worker-acceptance-config-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()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -25,14 +25,22 @@ import {
|
|||||||
fetchAdminWorkerAnnouncement,
|
fetchAdminWorkerAnnouncement,
|
||||||
fetchAdminWorkerProductNameSuffix,
|
fetchAdminWorkerProductNameSuffix,
|
||||||
fetchAdminWorkerProductNameSuffixSources,
|
fetchAdminWorkerProductNameSuffixSources,
|
||||||
|
fetchAdminWorkerSupportContact,
|
||||||
renameAdminMockCustomShop,
|
renameAdminMockCustomShop,
|
||||||
runAdminScheduledJob,
|
runAdminScheduledJob,
|
||||||
saveAdminWorkerAnnouncement,
|
saveAdminWorkerAnnouncement,
|
||||||
saveAdminWorkerProductNameSuffix,
|
saveAdminWorkerProductNameSuffix,
|
||||||
|
saveAdminWorkerSupportContact,
|
||||||
saveAdminScheduledJobsConfig,
|
saveAdminScheduledJobsConfig,
|
||||||
} from '@/services/admin'
|
} from '@/services/admin'
|
||||||
import type { AdminScheduledJobItem, AdminScheduledJobRuntimeState } from '@/types/admin'
|
import type { AdminScheduledJobItem, AdminScheduledJobRuntimeState } from '@/types/admin'
|
||||||
import type { WorkerAnnouncementConfig, WorkerProductNameSuffixItem } from '@/types/worker-platform'
|
import type {
|
||||||
|
UploadedFile,
|
||||||
|
WorkerAnnouncementConfig,
|
||||||
|
WorkerProductNameSuffixItem,
|
||||||
|
WorkerSupportContactConfig,
|
||||||
|
} from '@/types/worker-platform'
|
||||||
|
import ImageUpload from '@/components/files/ImageUpload'
|
||||||
import { formatAdminDateTime } from '@/utils/admin-time'
|
import { formatAdminDateTime } from '@/utils/admin-time'
|
||||||
import { normalizeProductNameSuffixText } from '@/utils/product-name-source-suffix'
|
import { normalizeProductNameSuffixText } from '@/utils/product-name-source-suffix'
|
||||||
|
|
||||||
@@ -46,6 +54,7 @@ export default function AnnouncementPanel() {
|
|||||||
return (
|
return (
|
||||||
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
||||||
<AnnouncementCard />
|
<AnnouncementCard />
|
||||||
|
<SupportContactCard />
|
||||||
<ProductNameSourceSuffixCard />
|
<ProductNameSourceSuffixCard />
|
||||||
<DepositUnfreezeCard />
|
<DepositUnfreezeCard />
|
||||||
<MockCustomShopsCard />
|
<MockCustomShopsCard />
|
||||||
@@ -192,6 +201,107 @@ function DepositUnfreezeCard() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SupportContactFormValues = {
|
||||||
|
enabled?: boolean
|
||||||
|
wechatId?: string
|
||||||
|
wechatQrCodeImageList?: UploadedFile[]
|
||||||
|
notice?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function SupportContactCard() {
|
||||||
|
const { message } = App.useApp()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const [form] = Form.useForm<SupportContactFormValues>()
|
||||||
|
const [saving, setSaving] = useState(false)
|
||||||
|
const contactQuery = useQuery({
|
||||||
|
queryKey: ['admin-worker-support-contact'],
|
||||||
|
queryFn: fetchAdminWorkerSupportContact,
|
||||||
|
})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const config = contactQuery.data?.data
|
||||||
|
if (!config) return
|
||||||
|
form.setFieldsValue({
|
||||||
|
enabled: config.enabled,
|
||||||
|
wechatId: config.wechatId,
|
||||||
|
wechatQrCodeImageList: config.wechatQrCodeImage ? [config.wechatQrCodeImage] : [],
|
||||||
|
notice: config.notice,
|
||||||
|
})
|
||||||
|
}, [contactQuery.data, form])
|
||||||
|
|
||||||
|
async function saveSupportContact(values: SupportContactFormValues) {
|
||||||
|
const enabled = values.enabled === true
|
||||||
|
const wechatId = String(values.wechatId || '').trim()
|
||||||
|
const qrCodeImage = values.wechatQrCodeImageList?.[0] || null
|
||||||
|
if (enabled && !wechatId && !qrCodeImage) {
|
||||||
|
message.warning('启用售后微信后,请至少配置微信号或二维码')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setSaving(true)
|
||||||
|
try {
|
||||||
|
await saveAdminWorkerSupportContact({
|
||||||
|
enabled,
|
||||||
|
wechatId,
|
||||||
|
wechatQrCodeImage: qrCodeImage,
|
||||||
|
notice: String(values.notice || '').trim(),
|
||||||
|
})
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['admin-worker-support-contact'] })
|
||||||
|
message.success('售后微信配置已保存')
|
||||||
|
} catch (error) {
|
||||||
|
message.error(error instanceof Error ? error.message : '保存售后微信配置失败')
|
||||||
|
} finally {
|
||||||
|
setSaving(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card title="售后微信(冻结账号联系)" bordered={false}>
|
||||||
|
<Typography.Paragraph type="secondary" style={{ marginBottom: 16 }}>
|
||||||
|
账号被冻结后,登录页会展示这里的售后微信。建议同时配置微信号和二维码,方便手机端直接复制微信号。
|
||||||
|
</Typography.Paragraph>
|
||||||
|
<Form form={form} layout="vertical" onFinish={saveSupportContact} style={{ maxWidth: 760 }}>
|
||||||
|
<Form.Item
|
||||||
|
name="enabled"
|
||||||
|
label="启用售后微信提示"
|
||||||
|
valuePropName="checked"
|
||||||
|
extra="关闭后,冻结账号登录时只提示账号已冻结,不展示售后微信。"
|
||||||
|
>
|
||||||
|
<Switch checkedChildren="启用" unCheckedChildren="关闭" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="wechatId"
|
||||||
|
label="售后微信号"
|
||||||
|
extra="支持填写微信号或手机号;手机端可一键复制后到微信中搜索。"
|
||||||
|
>
|
||||||
|
<Input maxLength={64} placeholder="例如:after_sales_wechat 或 13800138000" />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="wechatQrCodeImageList"
|
||||||
|
label="售后微信二维码"
|
||||||
|
extra="可选。建议上传清晰二维码,方便另一台设备扫码添加。"
|
||||||
|
>
|
||||||
|
<ImageUpload scene="worker-support-contact" scope="admin" maxCount={1} />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="notice"
|
||||||
|
label="冻结提示文案"
|
||||||
|
extra="显示在冻结账号的登录提示中;留空会使用默认文案。"
|
||||||
|
>
|
||||||
|
<Input.TextArea
|
||||||
|
rows={3}
|
||||||
|
maxLength={240}
|
||||||
|
showCount
|
||||||
|
placeholder="账号已被冻结,如有疑问请添加售后微信处理。"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Button type="primary" htmlType="submit" loading={saving}>
|
||||||
|
保存售后微信配置
|
||||||
|
</Button>
|
||||||
|
</Form>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
function AnnouncementCard() {
|
function AnnouncementCard() {
|
||||||
const { message } = App.useApp()
|
const { message } = App.useApp()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
App,
|
App,
|
||||||
Button,
|
Button,
|
||||||
Form,
|
Form,
|
||||||
|
Image,
|
||||||
Input,
|
Input,
|
||||||
Modal,
|
Modal,
|
||||||
Segmented,
|
Segmented,
|
||||||
@@ -26,6 +27,7 @@ import { Navigate, useNavigate } from 'react-router'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
deleteWorkerSessionWithCredentials,
|
deleteWorkerSessionWithCredentials,
|
||||||
|
fetchWorkerSupportContact,
|
||||||
loginWorker,
|
loginWorker,
|
||||||
loginWorkerBySmsCode,
|
loginWorkerBySmsCode,
|
||||||
manageWorkerSessions,
|
manageWorkerSessions,
|
||||||
@@ -35,7 +37,7 @@ import {
|
|||||||
sendWorkerPasswordResetSmsCode,
|
sendWorkerPasswordResetSmsCode,
|
||||||
sendWorkerLoginSmsCode,
|
sendWorkerLoginSmsCode,
|
||||||
} from '@/services/worker'
|
} from '@/services/worker'
|
||||||
import type { WorkerSessionDevice } from '@/types/worker-platform'
|
import type { WorkerSessionDevice, WorkerSupportContactConfig } from '@/types/worker-platform'
|
||||||
import { hasWorkerSession, setWorkerSession } from '@/utils/worker-auth'
|
import { hasWorkerSession, setWorkerSession } from '@/utils/worker-auth'
|
||||||
import { isWorkerPasswordStrong, WORKER_PASSWORD_RULE_MESSAGE } from '@/utils/worker-password'
|
import { isWorkerPasswordStrong, WORKER_PASSWORD_RULE_MESSAGE } from '@/utils/worker-password'
|
||||||
|
|
||||||
@@ -79,6 +81,10 @@ export default function WorkerLoginPage() {
|
|||||||
const [deviceManagerOpen, setDeviceManagerOpen] = useState(false)
|
const [deviceManagerOpen, setDeviceManagerOpen] = useState(false)
|
||||||
const [deviceManagerLoading, setDeviceManagerLoading] = useState(false)
|
const [deviceManagerLoading, setDeviceManagerLoading] = useState(false)
|
||||||
const [managedDevices, setManagedDevices] = useState<WorkerSessionDevice[]>([])
|
const [managedDevices, setManagedDevices] = useState<WorkerSessionDevice[]>([])
|
||||||
|
const [frozenAccountBlocked, setFrozenAccountBlocked] = useState(false)
|
||||||
|
const [supportContact, setSupportContact] = useState<WorkerSupportContactConfig | null>(null)
|
||||||
|
const [supportContactLoading, setSupportContactLoading] = useState(false)
|
||||||
|
const [supportContactError, setSupportContactError] = useState('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (countdown <= 0) return
|
if (countdown <= 0) return
|
||||||
@@ -127,6 +133,9 @@ export default function WorkerLoginPage() {
|
|||||||
await loadManagedDevices(values)
|
await loadManagedDevices(values)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (getWorkerErrorCode(error) === 'worker_rejected') {
|
||||||
|
void loadFrozenSupportContact()
|
||||||
|
}
|
||||||
message.error(error instanceof Error ? error.message : '登录失败')
|
message.error(error instanceof Error ? error.message : '登录失败')
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@@ -164,6 +173,9 @@ export default function WorkerLoginPage() {
|
|||||||
message.success('登录成功')
|
message.success('登录成功')
|
||||||
void navigate('/hall', { replace: true })
|
void navigate('/hall', { replace: true })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (getWorkerErrorCode(error) === 'worker_rejected') {
|
||||||
|
void loadFrozenSupportContact()
|
||||||
|
}
|
||||||
message.error(error instanceof Error ? error.message : '验证码登录失败')
|
message.error(error instanceof Error ? error.message : '验证码登录失败')
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@@ -174,6 +186,21 @@ export default function WorkerLoginPage() {
|
|||||||
return String(loginSmsPhoneInputRef.current?.input?.value || loginSmsPhone).trim()
|
return String(loginSmsPhoneInputRef.current?.input?.value || loginSmsPhone).trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function loadFrozenSupportContact() {
|
||||||
|
setFrozenAccountBlocked(true)
|
||||||
|
setSupportContact(null)
|
||||||
|
setSupportContactError('')
|
||||||
|
setSupportContactLoading(true)
|
||||||
|
try {
|
||||||
|
const response = await fetchWorkerSupportContact()
|
||||||
|
setSupportContact(response.data)
|
||||||
|
} catch (error) {
|
||||||
|
setSupportContactError(error instanceof Error ? error.message : '售后微信加载失败')
|
||||||
|
} finally {
|
||||||
|
setSupportContactLoading(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function loadManagedDevices(values?: { username: string; password: string }) {
|
async function loadManagedDevices(values?: { username: string; password: string }) {
|
||||||
const credentials = values || deviceForm.getFieldsValue()
|
const credentials = values || deviceForm.getFieldsValue()
|
||||||
if (!credentials.username || !credentials.password) {
|
if (!credentials.username || !credentials.password) {
|
||||||
@@ -462,6 +489,61 @@ export default function WorkerLoginPage() {
|
|||||||
</Button>
|
</Button>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
|
{frozenAccountBlocked ? (
|
||||||
|
<Alert
|
||||||
|
showIcon
|
||||||
|
type="warning"
|
||||||
|
closable
|
||||||
|
onClose={() => setFrozenAccountBlocked(false)}
|
||||||
|
message="接单账号已被冻结,无法登录"
|
||||||
|
style={{ marginTop: 20 }}
|
||||||
|
description={
|
||||||
|
<Space direction="vertical" size={10} style={{ width: '100%' }}>
|
||||||
|
{supportContactLoading ? (
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
正在加载售后微信…
|
||||||
|
</Typography.Text>
|
||||||
|
) : supportContact?.enabled ? (
|
||||||
|
<>
|
||||||
|
<Typography.Text>
|
||||||
|
{supportContact.notice ||
|
||||||
|
'账号已被冻结,如有疑问请添加售后微信处理。'}
|
||||||
|
</Typography.Text>
|
||||||
|
{supportContact.wechatId ? (
|
||||||
|
<div>
|
||||||
|
<Typography.Text strong>售后微信:</Typography.Text>
|
||||||
|
<Typography.Text copyable={{ text: supportContact.wechatId }}>
|
||||||
|
{supportContact.wechatId}
|
||||||
|
</Typography.Text>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{supportContact.wechatQrCodeImage ? (
|
||||||
|
<div style={{ width: '100%', textAlign: 'center' }}>
|
||||||
|
<Image
|
||||||
|
width={180}
|
||||||
|
src={
|
||||||
|
supportContact.wechatQrCodeImage.mediumUrl ||
|
||||||
|
supportContact.wechatQrCodeImage.url
|
||||||
|
}
|
||||||
|
alt="售后微信二维码"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Typography.Text type="secondary">
|
||||||
|
售后微信暂未启用,请稍后重试或通过平台其他渠道联系。
|
||||||
|
</Typography.Text>
|
||||||
|
)}
|
||||||
|
{supportContactError ? (
|
||||||
|
<Typography.Text type="danger">
|
||||||
|
{supportContactError}
|
||||||
|
</Typography.Text>
|
||||||
|
) : null}
|
||||||
|
</Space>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -704,3 +786,7 @@ export default function WorkerLoginPage() {
|
|||||||
function isMobileViewport() {
|
function isMobileViewport() {
|
||||||
return typeof window !== 'undefined' && window.innerWidth < 768
|
return typeof window !== 'undefined' && window.innerWidth < 768
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getWorkerErrorCode(error: unknown) {
|
||||||
|
return String((error as { errorCode?: string } | null)?.errorCode || '').trim()
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import type {
|
|||||||
WorkerPlatformNotificationConfig,
|
WorkerPlatformNotificationConfig,
|
||||||
WorkerProductMatchConfig,
|
WorkerProductMatchConfig,
|
||||||
WorkerAnnouncementConfig,
|
WorkerAnnouncementConfig,
|
||||||
|
WorkerSupportContactConfig,
|
||||||
WorkerProductNameSuffixConfig,
|
WorkerProductNameSuffixConfig,
|
||||||
WorkerLevel,
|
WorkerLevel,
|
||||||
WorkerListResponse,
|
WorkerListResponse,
|
||||||
@@ -133,6 +134,17 @@ export function saveAdminWorkerAnnouncement(payload: WorkerAnnouncementConfig) {
|
|||||||
return apiPost<WorkerAnnouncementConfig>('/api/v1/admin/worker-platform/announcement', payload)
|
return apiPost<WorkerAnnouncementConfig>('/api/v1/admin/worker-platform/announcement', payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fetchAdminWorkerSupportContact() {
|
||||||
|
return apiGet<WorkerSupportContactConfig>('/api/v1/admin/worker-platform/support-contact')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function saveAdminWorkerSupportContact(payload: WorkerSupportContactConfig) {
|
||||||
|
return apiPost<WorkerSupportContactConfig>(
|
||||||
|
'/api/v1/admin/worker-platform/support-contact',
|
||||||
|
payload,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function fetchAdminWorkerProductNameSuffix() {
|
export function fetchAdminWorkerProductNameSuffix() {
|
||||||
return apiGet<WorkerProductNameSuffixConfig>('/api/v1/admin/worker-platform/product-name-suffix')
|
return apiGet<WorkerProductNameSuffixConfig>('/api/v1/admin/worker-platform/product-name-suffix')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import type {
|
|||||||
WorkerCancelRequest,
|
WorkerCancelRequest,
|
||||||
WorkerCancelRequestRisk,
|
WorkerCancelRequestRisk,
|
||||||
WorkerAnnouncementConfig,
|
WorkerAnnouncementConfig,
|
||||||
|
WorkerSupportContactConfig,
|
||||||
WorkerProductNameSuffixConfig,
|
WorkerProductNameSuffixConfig,
|
||||||
WorkerProductNameSuffixDisplayConfig,
|
WorkerProductNameSuffixDisplayConfig,
|
||||||
WorkerAcceptanceConfig,
|
WorkerAcceptanceConfig,
|
||||||
@@ -154,6 +155,10 @@ export function fetchWorkerAnnouncement() {
|
|||||||
return apiGet<WorkerAnnouncementConfig>('/api/v1/worker/announcement')
|
return apiGet<WorkerAnnouncementConfig>('/api/v1/worker/announcement')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fetchWorkerSupportContact() {
|
||||||
|
return apiGet<WorkerSupportContactConfig>('/api/v1/worker/support-contact')
|
||||||
|
}
|
||||||
|
|
||||||
/** 商品名来源后缀映射(后台「杂项配置」维护,只返回已启用项),打手端列表/详情/大厅展示用。 */
|
/** 商品名来源后缀映射(后台「杂项配置」维护,只返回已启用项),打手端列表/详情/大厅展示用。 */
|
||||||
export function fetchWorkerProductNameSuffix() {
|
export function fetchWorkerProductNameSuffix() {
|
||||||
return apiGet<WorkerProductNameSuffixDisplayConfig>('/api/v1/worker/product-name-suffix')
|
return apiGet<WorkerProductNameSuffixDisplayConfig>('/api/v1/worker/product-name-suffix')
|
||||||
|
|||||||
@@ -342,6 +342,13 @@ export type WorkerAnnouncementConfig = {
|
|||||||
content: string
|
content: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type WorkerSupportContactConfig = {
|
||||||
|
enabled: boolean
|
||||||
|
wechatId: string
|
||||||
|
wechatQrCodeImage: UploadedFile | null
|
||||||
|
notice: string
|
||||||
|
}
|
||||||
|
|
||||||
export type WorkerProductNameSuffixItem = {
|
export type WorkerProductNameSuffixItem = {
|
||||||
/** 来源标识(精确匹配、不区分大小写),如 91kaquan */
|
/** 来源标识(精确匹配、不区分大小写),如 91kaquan */
|
||||||
source: string
|
source: string
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export const WORKER_PLATFORM_TAB_QUERY_KEYS: Record<string, string[][]> = {
|
|||||||
finance: [['admin-finance-settlements'], ['admin-finance-withdrawals']],
|
finance: [['admin-finance-settlements'], ['admin-finance-withdrawals']],
|
||||||
levels: [['admin-worker-levels']],
|
levels: [['admin-worker-levels']],
|
||||||
notifications: [['admin-notifications']],
|
notifications: [['admin-notifications']],
|
||||||
announcement: [['admin-announcements']],
|
announcement: [['admin-announcements'], ['admin-worker-support-contact']],
|
||||||
'hall-config': [['admin-hall-config']],
|
'hall-config': [['admin-hall-config']],
|
||||||
'risk-control': [['admin-worker-risk-overview'], ['admin-worker-risk-events']],
|
'risk-control': [['admin-worker-risk-overview'], ['admin-worker-risk-events']],
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user