feat(pdd-sync): 默认拉取已发货订单并支持配置单次拉单上限与抓取状态

This commit is contained in:
yml2213
2026-09-12 15:16:39 +08:00
parent 121c2a452c
commit ffa3374483
8 changed files with 135 additions and 40 deletions
@@ -31,6 +31,7 @@ import {
Modal,
Popconfirm,
Row,
Select,
Space,
Spin,
Statistic,
@@ -76,6 +77,8 @@ export function PddPlatformPanel() {
const [config, setConfig] = useState<AdminPddConfig>({
enabled: true,
pollIntervalSeconds: 20,
orderType: 2,
pageSize: 50,
stores: [],
})
@@ -144,13 +147,18 @@ export function PddPlatformPanel() {
async function handleSyncAll() {
setSyncingAll(true)
try {
const response = await triggerAdminPddSync()
const response = await triggerAdminPddSync({
pageSize: config.pageSize || 50,
orderType: config.orderType ?? 2,
})
const data = response?.data as AdminPddSyncAllResponse | undefined
if (data && Array.isArray(data.results)) {
const totalFetched = data.results.reduce((acc, r) => acc + (r.fetchedCount || 0), 0)
const totalUpserted = data.results.reduce((acc, r) => acc + (r.upsertedCount || 0), 0)
const statusLabel =
config.orderType === 1 ? '待发货' : config.orderType === 0 ? '全部' : '已发货'
showSuccess(
`全量店铺同步完成:共抓取 ${totalFetched} 笔,入库/更新 ${totalUpserted} 笔待发货订单`,
`全量店铺【${statusLabel}】同步完成:共抓取 ${totalFetched} 笔,入库/更新 ${totalUpserted} 笔订单`,
)
} else {
showSuccess('全量店铺同步完成')
@@ -169,7 +177,11 @@ export function PddPlatformPanel() {
async function handleSyncSingleStore(store: AdminPddStoreItem) {
setSyncingShopId(store.shopId)
try {
const response = await triggerAdminPddSync({ shopId: store.shopId })
const response = await triggerAdminPddSync({
shopId: store.shopId,
pageSize: config.pageSize || 50,
orderType: config.orderType ?? 2,
})
const data = response?.data as AdminPddSyncResult | undefined
if (data) {
showSuccess(
@@ -206,7 +218,7 @@ export function PddPlatformPanel() {
}))
if (result.valid) {
showSuccess(
`【${store.shopName}】Cookie 校验通过,在线待发货订单数: ${result.totalOrders ?? 0}`,
`【${store.shopName}】Cookie 校验通过,在售/历史订单总数: ${result.totalOrders ?? 0}`,
)
} else {
showError(`【${store.shopName}】Cookie 校验未通过: ${result.message}`)
@@ -458,7 +470,7 @@ export function PddPlatformPanel() {
return (
<Space direction="vertical" size={2}>
<Tag icon={<CheckCircleOutlined />} color="success">
有效 (待发货: {testRes.totalOrders ?? 0})
有效 (在售/历史: {testRes.totalOrders ?? 0})
</Tag>
{testRes.testedAt && (
<Text type="secondary" style={{ fontSize: '11px' }}>
@@ -501,7 +513,9 @@ export function PddPlatformPanel() {
测试CK
</Button>
</Tooltip>
<Tooltip title="立即从拼多多 MMS 抓取待发货订单并同步至总平台">
<Tooltip
title={`立即从拼多多 MMS 抓取【${config.orderType === 1 ? '待发货' : config.orderType === 0 ? '全部' : '已发货'}】订单并同步至总平台`}
>
<Button
size="small"
icon={<ReloadOutlined />}
@@ -541,6 +555,9 @@ export function PddPlatformPanel() {
)
}
const orderTypeDesc =
config.orderType === 1 ? '待发货' : config.orderType === 0 ? '全部订单' : '已发货'
return (
<section className="platform-panel-stack">
{/* Metrics Dashboard / 状态指标概览卡片 */}
@@ -636,7 +653,7 @@ export function PddPlatformPanel() {
}}
>
<Statistic
title={<span style={{ color: '#64748b' }}>错峰轮询频次</span>}
title={<span style={{ color: '#64748b' }}>调度频次与拉单范围</span>}
value={config.pollIntervalSeconds}
suffix={<span style={{ fontSize: 14, color: '#8c8c8c' }}>秒 / 轮</span>}
valueStyle={{ color: '#722ed1', fontWeight: 600, fontSize: 20 }}
@@ -651,8 +668,11 @@ export function PddPlatformPanel() {
}}
>
<Text type="secondary" style={{ fontSize: 12 }}>
多店铺平滑均摊时间片
单次拉取 {config.pageSize || 50} 单
</Text>
<Tag color="purple" style={{ margin: 0, fontSize: 11 }}>
{orderTypeDesc}
</Tag>
</div>
</Card>
</Col>
@@ -715,7 +735,7 @@ export function PddPlatformPanel() {
}
>
<Row gutter={[24, 16]} align="middle">
<Col xs={24} sm={8}>
<Col xs={24} sm={12} md={6}>
<Space direction="vertical" size={4}>
<Text strong>自动拉单调度状态</Text>
<Space align="center">
@@ -730,29 +750,73 @@ export function PddPlatformPanel() {
</Space>
</Col>
<Col xs={24} sm={16}>
<Col xs={24} sm={12} md={6}>
<Space direction="vertical" size={4} style={{ width: '100%' }}>
<Text strong>抓取订单状态</Text>
<Select
value={config.orderType ?? 2}
style={{ width: '100%' }}
onChange={(val) => setConfig((prev) => ({ ...prev, orderType: Number(val) }))}
options={[
{ value: 2, label: '已发货 (默认推荐)' },
{ value: 1, label: '待发货' },
{ value: 0, label: '全部订单' },
]}
/>
</Space>
</Col>
<Col xs={24} sm={12} md={6}>
<Space direction="vertical" size={4} style={{ width: '100%' }}>
<Text strong>错峰轮询间隔</Text>
<Space align="center" wrap>
<InputNumber
min={10}
max={3600}
addonAfter="秒"
value={config.pollIntervalSeconds}
onChange={(val) =>
setConfig((prev) => ({
...prev,
pollIntervalSeconds: Number(val || 20),
}))
}
/>
<Text type="secondary" style={{ fontSize: 12 }}>
(建议 15~30 秒。多店铺自动平滑错峰拉取待发货订单,保证准实时入库且防止高频风控)
</Text>
</Space>
<InputNumber
min={10}
max={3600}
style={{ width: '100%' }}
addonAfter="秒"
value={config.pollIntervalSeconds}
onChange={(val) =>
setConfig((prev) => ({
...prev,
pollIntervalSeconds: Number(val || 20),
}))
}
/>
</Space>
</Col>
<Col xs={24} sm={12} md={6}>
<Space direction="vertical" size={4} style={{ width: '100%' }}>
<Text strong>单次拉单上限 (pageSize)</Text>
<InputNumber
min={10}
max={100}
style={{ width: '100%' }}
addonAfter="单/次"
value={config.pageSize ?? 50}
onChange={(val) =>
setConfig((prev) => ({
...prev,
pageSize: Number(val || 50),
}))
}
/>
</Space>
</Col>
</Row>
<Alert
type="info"
showIcon
style={{ marginTop: 14 }}
message={
<span>
当前拉单规则:默认抓取<strong>【{orderTypeDesc}】</strong>订单,单次拉取最新
<strong>【{config.pageSize || 50}】</strong>单并错峰均摊。
</span>
}
description="当拼多多买家下单并完成虚拟发货(或服务市场工具发货为已发货)后,系统将自动拉取入库并派发至打手大厅;您也可以随时点击右侧【立即拉单】即时手动触发增量抓取。"
/>
</Card>
{/* Stores CRUD Table Card / 拼多多店铺管理表格卡片 */}
@@ -911,7 +975,7 @@ export function PddPlatformPanel() {
<div>{modalTestResult.message}</div>
{modalTestResult.totalOrders !== undefined && (
<div style={{ marginTop: 4, fontWeight: 500 }}>
当前在线待发货订单数: {modalTestResult.totalOrders} 笔
当前在线在售/历史订单总数: {modalTestResult.totalOrders} 笔
</div>
)}
</div>
@@ -41,7 +41,9 @@ export function testAdminPddCookie(payload: {
return apiPost<AdminPddTestCookieResult>('/api/v1/admin/platform-config/pdd/test-cookie', payload)
}
export function triggerAdminPddSync(payload: { shopId?: string; pageSize?: number } = {}) {
export function triggerAdminPddSync(
payload: { shopId?: string; pageSize?: number; orderType?: number } = {},
) {
return apiPost<AdminPddSyncAllResponse | AdminPddSyncResult>(
'/api/v1/admin/platform-config/pdd/sync',
payload,
@@ -16,6 +16,8 @@ export interface AdminPddStoreItem {
export interface AdminPddConfig {
enabled: boolean
pollIntervalSeconds: number
orderType?: number // 0: 全部, 1: 待发货, 2: 已发货 (默认 2)
pageSize?: number // 单次拉取单数 (默认 50)
stores: AdminPddStoreItem[]
}