feat(pdd): 原生内嵌拼多多多店铺订单同步子服务与anti-content纯算引擎
1. 纯算引擎 (pdd-anti-content.ts): - 100% 纯 TypeScript 原生还原 0as anti-content 算法,零 npm 依赖(仅基于 Node.js 原生 zlib 与 crypto)。 - 包含 22 个环境特征 Tag TLV 组包、zlib 标准压缩、4 字节尾部扰动盐与 64 字符动态位移 Base64 编码,单次耗时 < 0.1ms。 2. MMS 接口客户端与数据映射 (pdd-client.ts, pdd-order-mapper.ts): - 基于原生 fetch 实现高可用 MMS 请求,支持拼多多网关毫秒级服务器时间校准 (/api/server/_stm)。 - 实现拼多多订单状态与字段规范映射为平台 SourceOrderEvent,精准保留买家留言与充值账号信息。 3. 多店铺配置与防风控错峰调度 (pdd-source-config-service.ts, pdd-sync-service.ts): - 支持多店铺账号配置持久化(PostgreSQL app_config_entries 与本地 JSON 双模兜底)。 - 实现店铺间轻量错峰拉取机制,避免并发峰值触发平台 40002 频控。 4. 内存级自动进单与派单流转: - 拉取新订单后在 Node.js 内存中直接调用 upsertOrderFromSource(),自动完成 orders/order_items 入库、商品规则匹配与打手大厅工单 (work_orders) 实时广播。 5. 调度器与管理端 API (scheduler-service.ts, platform-config/pdd.ts): - 注册 pdd_order_sync 定时任务(默认 20s 轮询),提供管理端店铺配置查看、保存、删除及手动立即同步接口。 - 所有新增代码均遵循中英双语注释规范,并通过类型检查与单元测试。
This commit is contained in:
@@ -8,6 +8,7 @@ import ninetyoneRouter from './platform-config/ninetyone.js'
|
||||
import notificationsRouter from './platform-config/notifications.js'
|
||||
import fulfillmentRoutingRouter from './platform-config/fulfillment-routing.js'
|
||||
import affiliateDashRouter from './platform-config/affiliate-dash.js'
|
||||
import pddRouter from './platform-config/pdd.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
@@ -19,5 +20,6 @@ router.use('/platform-config', ninetyoneRouter)
|
||||
router.use('/platform-config', fulfillmentRoutingRouter)
|
||||
router.use('/platform-config', cloudtentaclesRouter)
|
||||
router.use('/platform-config', affiliateDashRouter)
|
||||
router.use('/platform-config', pddRouter)
|
||||
|
||||
export default router
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/**
|
||||
* Pinduoduo Admin Platform Config Routes
|
||||
* 拼多多平台管理端配置与手动同步路由
|
||||
*/
|
||||
|
||||
import { Router } from 'express'
|
||||
import { createJsonHandler } from '../session.js'
|
||||
import type { JsonRecord, JsonObject } from '../../../types/json.js'
|
||||
import {
|
||||
getPddSourcesConfig,
|
||||
savePddSourcesConfig,
|
||||
savePddStore,
|
||||
deletePddStore,
|
||||
getPddStoreById,
|
||||
} from '../../../services/platforms/pdd/pdd-source-config-service.js'
|
||||
import {
|
||||
syncAllPddStores,
|
||||
syncStoreOrders,
|
||||
} from '../../../services/platforms/pdd/pdd-sync-service.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
/**
|
||||
* GET /platform-config/pdd
|
||||
* Get complete PDD configuration and store list.
|
||||
* 读取拼多多全局配置及所有店铺列表。
|
||||
*/
|
||||
router.get(
|
||||
'/pdd',
|
||||
createJsonHandler(() => getPddSourcesConfig(), {
|
||||
successMessage: 'ok',
|
||||
errorMessage: '读取拼多多配置失败',
|
||||
scope: '[admin/platform-config/pdd]',
|
||||
}),
|
||||
)
|
||||
|
||||
/**
|
||||
* POST /platform-config/pdd
|
||||
* Save full PDD configuration.
|
||||
* 保存拼多多全局配置。
|
||||
*/
|
||||
router.post(
|
||||
'/pdd',
|
||||
createJsonHandler((req) => savePddSourcesConfig(req.body), {
|
||||
successMessage: '拼多多配置已保存',
|
||||
errorMessage: '保存拼多多配置失败',
|
||||
scope: '[admin/platform-config/pdd]',
|
||||
audit: (_req, data) => {
|
||||
const result = data as JsonRecord
|
||||
return {
|
||||
action: 'platform_pdd_config_updated',
|
||||
targetType: 'platform_config',
|
||||
targetId: 'pdd',
|
||||
data: {
|
||||
enabled: result?.enabled !== false,
|
||||
storeCount: Array.isArray(result?.stores) ? result.stores.length : 0,
|
||||
},
|
||||
}
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
/**
|
||||
* POST /platform-config/pdd/stores/:shopId
|
||||
* Add or update a single PDD store configuration.
|
||||
* 新增或更新单个拼多多店铺配置。
|
||||
*/
|
||||
router.post(
|
||||
'/pdd/stores/:shopId',
|
||||
createJsonHandler((req) => savePddStore(req.params.shopId, (req.body || {}) as JsonObject), {
|
||||
successMessage: '拼多多店铺配置已更新',
|
||||
errorMessage: '更新拼多多店铺配置失败',
|
||||
scope: '[admin/platform-config/pdd/stores/:shopId]',
|
||||
audit: (req) => ({
|
||||
action: 'platform_pdd_store_updated',
|
||||
targetType: 'platform_store',
|
||||
targetId: String(req.params.shopId || ''),
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
/**
|
||||
* DELETE /platform-config/pdd/stores/:shopId
|
||||
* Delete a PDD store.
|
||||
* 删除指定拼多多店铺。
|
||||
*/
|
||||
router.delete(
|
||||
'/pdd/stores/:shopId',
|
||||
createJsonHandler((req) => deletePddStore(req.params.shopId), {
|
||||
successMessage: '拼多多店铺已删除',
|
||||
errorMessage: '删除拼多多店铺失败',
|
||||
scope: '[admin/platform-config/pdd/stores/:shopId]',
|
||||
audit: (req) => ({
|
||||
action: 'platform_pdd_store_deleted',
|
||||
targetType: 'platform_store',
|
||||
targetId: String(req.params.shopId || ''),
|
||||
}),
|
||||
}),
|
||||
)
|
||||
|
||||
/**
|
||||
* POST /platform-config/pdd/sync
|
||||
* Manually trigger order sync for all stores or a specific store.
|
||||
* 手动触发拼多多订单同步(支持指定 shopId 或全店铺)。
|
||||
*/
|
||||
router.post(
|
||||
'/pdd/sync',
|
||||
createJsonHandler(
|
||||
async (req) => {
|
||||
const body = (req.body || {}) as { shopId?: string; pageSize?: number }
|
||||
const shopId = String(body.shopId || '').trim()
|
||||
|
||||
if (shopId) {
|
||||
const store = getPddStoreById(shopId)
|
||||
if (!store) {
|
||||
throw createHttpError(`店铺不存在: ${shopId}`, {
|
||||
statusCode: 404,
|
||||
errorCode: 'pdd_store_not_found',
|
||||
})
|
||||
}
|
||||
return syncStoreOrders(store, { pageSize: body.pageSize || 10 })
|
||||
}
|
||||
|
||||
return syncAllPddStores({ pageSize: body.pageSize || 10 })
|
||||
},
|
||||
{
|
||||
successMessage: '拼多多同步已触发',
|
||||
errorMessage: '触发拼多多同步失败',
|
||||
scope: '[admin/platform-config/pdd/sync]',
|
||||
audit: (req) => ({
|
||||
action: 'platform_pdd_manual_sync_triggered',
|
||||
targetType: 'platform_sync',
|
||||
targetId: String((req.body as { shopId?: string })?.shopId || 'all'),
|
||||
}),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user