feat(pdd-ui): 新增管理后台拼多多店铺CRUD与Cookie有效性实时检测功能
1. 订单快照优化 (pdd-order-mapper.ts): - 在 item_snapshot_json 中完整保留拼多多原始报文快照全量字段,确保无信息截断。 2. 后端 Cookie 有效性校验接口 (pdd-client.ts, platform-config/pdd.ts): - 新增 PddClient.testCookie 与 POST /api/v1/admin/platform-config/pdd/test-cookie 接口。 - 支持通过轻量接口请求即时测试 Cookie 合法性,精准识别有效状态(返回在线订单数)与失效/频控状态。 3. 前端管理面板开发 (PddPlatformPanel.tsx, AdminPlatformShopsPage.tsx): - 在平台配置页面新增【拼多多 (PDD)】专属 Tab 面板。 - 提供拼多多全局同步开关与轮询间隔配置。 - 支持店铺完整 CRUD:添加店铺、编辑店铺、删除店铺、启用/停用切换。 - 支持弹窗内即时【测试此 Cookie 有效性】(无需先保存即可验证)及列表行内一键测活与单店铺立即同步。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Pinduoduo Admin Platform Config Routes
|
||||
* 拼多多平台管理端配置与手动同步路由
|
||||
* 拼多多平台管理端配置、店铺 CRUD 与 CK 有效性校验路由
|
||||
*/
|
||||
|
||||
import { Router } from 'express'
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
syncAllPddStores,
|
||||
syncStoreOrders,
|
||||
} from '../../../services/platforms/pdd/pdd-sync-service.js'
|
||||
import { testPddCookie } from '../../../services/platforms/pdd/pdd-client.js'
|
||||
import { createHttpError } from '../../../utils/http.js'
|
||||
|
||||
const router = Router()
|
||||
@@ -68,16 +69,19 @@ router.post(
|
||||
*/
|
||||
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 || ''),
|
||||
}),
|
||||
}),
|
||||
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 || ''),
|
||||
}),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -99,6 +103,53 @@ router.delete(
|
||||
}),
|
||||
)
|
||||
|
||||
/**
|
||||
* POST /platform-config/pdd/test-cookie
|
||||
* Test Cookie validity for a given cookie string or an existing shop.
|
||||
* 测试拼多多 Cookie 有效性(支持直接传入 Cookie 字符串或指定 shopId)。
|
||||
*/
|
||||
router.post(
|
||||
'/pdd/test-cookie',
|
||||
createJsonHandler(
|
||||
async (req) => {
|
||||
const body = (req.body || {}) as {
|
||||
cookie?: string
|
||||
userAgent?: string
|
||||
shopId?: string
|
||||
}
|
||||
|
||||
let cookie = String(body.cookie || '').trim()
|
||||
let userAgent = body.userAgent
|
||||
|
||||
if (!cookie && body.shopId) {
|
||||
const store = getPddStoreById(body.shopId)
|
||||
if (!store) {
|
||||
throw createHttpError(`店铺不存在: ${body.shopId}`, {
|
||||
statusCode: 404,
|
||||
errorCode: 'pdd_store_not_found',
|
||||
})
|
||||
}
|
||||
cookie = store.cookie
|
||||
userAgent = userAgent || store.userAgent
|
||||
}
|
||||
|
||||
if (!cookie) {
|
||||
throw createHttpError('请提供待测试的 Cookie 字符串或指定有效的 shopId', {
|
||||
statusCode: 400,
|
||||
errorCode: 'pdd_cookie_required',
|
||||
})
|
||||
}
|
||||
|
||||
return testPddCookie({ cookie, userAgent })
|
||||
},
|
||||
{
|
||||
successMessage: 'Cookie 校验执行完成',
|
||||
errorMessage: 'Cookie 校验失败',
|
||||
scope: '[admin/platform-config/pdd/test-cookie]',
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
/**
|
||||
* POST /platform-config/pdd/sync
|
||||
* Manually trigger order sync for all stores or a specific store.
|
||||
|
||||
Reference in New Issue
Block a user