新增:半自动履约工作台与虎牙客户授权流程
- 新增 153 半自动履约迁移、后台任务接口与客户履约接口 - 接入虎牙 Connector 登录会话、绑定与一次性 CK 注入票据 - 新增后台半自动履约页面和客户履约入口 - 完善手工履约配置、成本确认事务与运行时连接器配置 - 同步权威文档、环境示例、部署脚本和迁移展示逻辑
This commit is contained in:
@@ -41,6 +41,8 @@ import { productSourceFilterSql } from './cost-center-mappers.js'
|
||||
|
||||
export const MANUAL_PLATFORM_KEYS = ['nanhang', 'lewan', 'rock', 'fund_cash', 'on_account'] as const
|
||||
export type ManualPlatformKey = (typeof MANUAL_PLATFORM_KEYS)[number]
|
||||
export const SEMI_AUTO_PLATFORM_KEYS = ['huya', 'weibo'] as const
|
||||
export type SemiAutoPlatform = (typeof SEMI_AUTO_PLATFORM_KEYS)[number]
|
||||
|
||||
/**
|
||||
* 积分换算率(分/积分),**按平台不同**:
|
||||
@@ -109,6 +111,9 @@ type ManualSkuRow = {
|
||||
config_canonical_product_id: number | null
|
||||
config_enabled: boolean | null
|
||||
config_channels_json: unknown
|
||||
config_semi_auto_enabled: boolean | null
|
||||
config_semi_auto_platform: string | null
|
||||
config_semi_auto_config_json: unknown
|
||||
}
|
||||
|
||||
type ManualChannelConfig = {
|
||||
@@ -344,7 +349,10 @@ export async function listManualSkus(input: Record<string, unknown> = {}) {
|
||||
cfg.cost_mode AS config_cost_mode,
|
||||
COALESCE(cfg.canonical_product_id, p.id) AS config_canonical_product_id,
|
||||
cfg.enabled AS config_enabled,
|
||||
cfg.channels_json AS config_channels_json
|
||||
cfg.channels_json AS config_channels_json,
|
||||
cfg.semi_auto_enabled AS config_semi_auto_enabled,
|
||||
cfg.semi_auto_platform AS config_semi_auto_platform,
|
||||
cfg.semi_auto_config_json AS config_semi_auto_config_json
|
||||
FROM product_catalog p
|
||||
JOIN internal_skus product_sku ON product_sku.id = p.internal_sku_id
|
||||
LEFT JOIN LATERAL (
|
||||
@@ -458,6 +466,7 @@ export async function saveManualFulfillmentConfig(payload: JsonObject) {
|
||||
)
|
||||
const enabled = payload.enabled === false ? false : true
|
||||
const note = optionalText(payload.note, 300)
|
||||
const semiAuto = normalizeSemiAutoConfig(payload)
|
||||
|
||||
// 消耗积分为 0 = 成本不固定,客服确认履约时手填。
|
||||
const costMode = primaryChannel.costMode
|
||||
@@ -546,7 +555,11 @@ export async function saveManualFulfillmentConfig(payload: JsonObject) {
|
||||
`UPDATE manual_fulfillment_configs
|
||||
SET sku_key = $2, canonical_product_id = $3, platform_key = $4,
|
||||
credit_quantity = $5, cost_mode = $6, enabled = $7, note = $8,
|
||||
channels_json = $9::jsonb, updated_at = $10
|
||||
channels_json = $9::jsonb,
|
||||
semi_auto_enabled = $10,
|
||||
semi_auto_platform = $11,
|
||||
semi_auto_config_json = $12::jsonb,
|
||||
updated_at = $13
|
||||
WHERE id = $1
|
||||
RETURNING *`,
|
||||
[
|
||||
@@ -559,14 +572,22 @@ export async function saveManualFulfillmentConfig(payload: JsonObject) {
|
||||
enabled,
|
||||
note,
|
||||
JSON.stringify(channels),
|
||||
semiAuto.enabled,
|
||||
semiAuto.platform,
|
||||
JSON.stringify(semiAuto.config),
|
||||
now,
|
||||
],
|
||||
)
|
||||
: await client.query(
|
||||
`INSERT INTO manual_fulfillment_configs (
|
||||
sku_key, canonical_product_id, platform_key, credit_quantity,
|
||||
cost_mode, enabled, note, channels_json, created_at, updated_at
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8::jsonb, $9, $9)
|
||||
cost_mode, enabled, note, channels_json,
|
||||
semi_auto_enabled, semi_auto_platform, semi_auto_config_json,
|
||||
created_at, updated_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, $8::jsonb,
|
||||
$9, $10, $11::jsonb, $12, $12
|
||||
)
|
||||
RETURNING *`,
|
||||
[
|
||||
skuKey,
|
||||
@@ -577,6 +598,9 @@ export async function saveManualFulfillmentConfig(payload: JsonObject) {
|
||||
enabled,
|
||||
note,
|
||||
JSON.stringify(channels),
|
||||
semiAuto.enabled,
|
||||
semiAuto.platform,
|
||||
JSON.stringify(semiAuto.config),
|
||||
now,
|
||||
],
|
||||
)
|
||||
@@ -1046,6 +1070,9 @@ export async function getManualFulfillmentConfig(skuKey: string) {
|
||||
enabled: boolean
|
||||
note: string
|
||||
channels_json: unknown
|
||||
semi_auto_enabled: boolean
|
||||
semi_auto_platform: string
|
||||
semi_auto_config_json: unknown
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}>(
|
||||
@@ -1174,6 +1201,9 @@ function mapManualSku(row: ManualSkuRow, unitPrices: Record<ManualPlatformKey, n
|
||||
? Number(row.config_canonical_product_id)
|
||||
: null,
|
||||
enabled: row.config_enabled !== false,
|
||||
semiAutoEnabled: row.config_semi_auto_enabled === true,
|
||||
semiAutoPlatform: String(row.config_semi_auto_platform || ''),
|
||||
semiAutoConfig: normalizeStoredSemiAutoConfig(row.config_semi_auto_config_json),
|
||||
channels: mapConfiguredChannels(channels, unitPrices),
|
||||
}
|
||||
: null,
|
||||
@@ -1191,6 +1221,9 @@ function mapManualConfig(
|
||||
enabled: boolean
|
||||
note: string
|
||||
channels_json: unknown
|
||||
semi_auto_enabled: boolean
|
||||
semi_auto_platform: string
|
||||
semi_auto_config_json: unknown
|
||||
created_at: string
|
||||
updated_at: string
|
||||
},
|
||||
@@ -1211,6 +1244,9 @@ function mapManualConfig(
|
||||
costFen: calculateManualCostFen(creditQuantity, unitPriceFen),
|
||||
creditUnitPriceFen: unitPriceFen,
|
||||
enabled: row.enabled,
|
||||
semiAutoEnabled: row.semi_auto_enabled === true,
|
||||
semiAutoPlatform: String(row.semi_auto_platform || ''),
|
||||
semiAutoConfig: normalizeStoredSemiAutoConfig(row.semi_auto_config_json),
|
||||
channels: mapConfiguredChannels(channels, unitPrices),
|
||||
note: row.note || '',
|
||||
createdAt: row.created_at,
|
||||
@@ -1218,6 +1254,73 @@ function mapManualConfig(
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeSemiAutoConfig(payload: JsonObject): {
|
||||
enabled: boolean
|
||||
platform: SemiAutoPlatform | ''
|
||||
config: Record<string, unknown>
|
||||
} {
|
||||
const enabled = payload.semiAutoEnabled === true || payload.semi_auto_enabled === true
|
||||
const platform = String(payload.semiAutoPlatform ?? payload.semi_auto_platform ?? '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
if (!enabled) {
|
||||
return { enabled: false, platform: '', config: {} }
|
||||
}
|
||||
if (!(SEMI_AUTO_PLATFORM_KEYS as readonly string[]).includes(platform)) {
|
||||
throw createHttpError('半自动履约平台无效', {
|
||||
statusCode: 400,
|
||||
errorCode: 'manual_config_semi_auto_platform_invalid',
|
||||
})
|
||||
}
|
||||
const rawConfig = payload.semiAutoConfig ?? payload.semi_auto_config
|
||||
const config =
|
||||
rawConfig && typeof rawConfig === 'object' && !Array.isArray(rawConfig)
|
||||
? (rawConfig as Record<string, unknown>)
|
||||
: {}
|
||||
return {
|
||||
enabled: true,
|
||||
platform: platform as SemiAutoPlatform,
|
||||
config: {
|
||||
pageTitle: String(config.pageTitle || '')
|
||||
.trim()
|
||||
.slice(0, 60),
|
||||
pageDescription: String(config.pageDescription || '')
|
||||
.trim()
|
||||
.slice(0, 500),
|
||||
loginInstructions: String(config.loginInstructions || '')
|
||||
.trim()
|
||||
.slice(0, 1000),
|
||||
bindingInstructions: String(config.bindingInstructions || '')
|
||||
.trim()
|
||||
.slice(0, 1000),
|
||||
browserTargets: Array.isArray(config.browserTargets)
|
||||
? config.browserTargets
|
||||
.filter((item): item is Record<string, unknown> =>
|
||||
Boolean(item && typeof item === 'object'),
|
||||
)
|
||||
.slice(0, 10)
|
||||
.map((item) => ({
|
||||
key: String(item.key || '')
|
||||
.trim()
|
||||
.slice(0, 40),
|
||||
label: String(item.label || '')
|
||||
.trim()
|
||||
.slice(0, 60),
|
||||
url: String(item.url || '')
|
||||
.trim()
|
||||
.slice(0, 1000),
|
||||
}))
|
||||
.filter((item) => item.key && item.url)
|
||||
: [],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeStoredSemiAutoConfig(value: unknown): Record<string, unknown> {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return {}
|
||||
return value as Record<string, unknown>
|
||||
}
|
||||
|
||||
function normalizePlatformKey(value: unknown): ManualPlatformKey {
|
||||
const text = String(value || '').trim()
|
||||
if (!MANUAL_PLATFORM_KEYS.includes(text as ManualPlatformKey)) {
|
||||
|
||||
Reference in New Issue
Block a user