mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 17:09:19 +08:00
feat: 完成初版拼多多订单同步
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { PddOrderSyncVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 按成交日同步一天拼多多订单
|
||||
*/
|
||||
export async function syncPddOrdersByDayApi(data: {
|
||||
shopId: number;
|
||||
confirmDate: string;
|
||||
}) {
|
||||
return requestClient.post<PddOrderSyncVO.Result>('/ec/pdd/order/sync/day', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增量同步
|
||||
*/
|
||||
export async function syncPddOrdersIncrementalApi(shopId: number) {
|
||||
return requestClient.post<PddOrderSyncVO.Result>(
|
||||
'/ec/pdd/order/sync/incremental',
|
||||
undefined,
|
||||
{ params: { shopId } },
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1 @@
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 拼多多订单同步 VO
|
||||
*/
|
||||
export namespace PddOrderSyncVO {
|
||||
export interface Result {
|
||||
mode: string;
|
||||
shopId: number;
|
||||
fetchedCount: number;
|
||||
upsertedCount: number;
|
||||
skippedCount: number;
|
||||
errors?: string[];
|
||||
}
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { DatePicker, Form, message, Radio } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
syncPddOrdersByDayApi,
|
||||
syncPddOrdersIncrementalApi,
|
||||
} from '#/api/ecommerce/pdd/order-sync';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const shop = ref<null | ShopVO.Info>(null);
|
||||
const loading = ref(false);
|
||||
const mode = ref<'day' | 'incremental'>('day');
|
||||
const confirmDate = ref<Dayjs>(dayjs().subtract(1, 'day'));
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[480px]',
|
||||
onCancel() {
|
||||
modalApi.close();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
const modalTitle = computed(() =>
|
||||
shop.value ? `同步拼多多订单 - ${shop.value.name}` : '同步拼多多订单',
|
||||
);
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!shop.value) return;
|
||||
if (mode.value === 'day' && !confirmDate.value) {
|
||||
message.warning('请选择成交日期');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
loading.value = true;
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
const result =
|
||||
mode.value === 'day'
|
||||
? await syncPddOrdersByDayApi({
|
||||
shopId: shop.value.id,
|
||||
confirmDate: confirmDate.value.format('YYYY-MM-DD'),
|
||||
})
|
||||
: await syncPddOrdersIncrementalApi(shop.value.id);
|
||||
|
||||
const errHint =
|
||||
result.errors && result.errors.length > 0
|
||||
? `;注意:${result.errors[0]}`
|
||||
: '';
|
||||
message.success(
|
||||
`同步完成:拉取 ${result.fetchedCount},入库 ${result.upsertedCount}${errHint}`,
|
||||
);
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
} catch (error) {
|
||||
console.error('同步拼多多订单失败:', error);
|
||||
message.error('同步拼多多订单失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
function open(record: ShopVO.Info) {
|
||||
shop.value = record;
|
||||
mode.value = 'day';
|
||||
confirmDate.value = dayjs().subtract(1, 'day');
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" content-class="px-5 py-4">
|
||||
<Form layout="vertical">
|
||||
<Form.Item label="同步方式">
|
||||
<Radio.Group v-model:value="mode">
|
||||
<Radio value="day">按成交日同步一天</Radio>
|
||||
<Radio value="incremental">增量同步(状态变更)</Radio>
|
||||
</Radio.Group>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
v-if="mode === 'day'"
|
||||
label="成交日期"
|
||||
extra="按拼多多成交时间(confirm_time)拉取该自然日订单,写入外部订单表"
|
||||
>
|
||||
<DatePicker
|
||||
v-model:value="confirmDate"
|
||||
class="w-full"
|
||||
:allow-clear="false"
|
||||
format="YYYY-MM-DD"
|
||||
/>
|
||||
</Form.Item>
|
||||
<p v-else class="text-xs text-slate-500">
|
||||
按订单更新时间拉取自上次游标以来的变更,用于发货/售后等状态同步。
|
||||
</p>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -17,6 +17,7 @@ import { getPddAuthorizeUrlApi } from '#/api/ecommerce/pdd/auth';
|
||||
import { getActivePlatformsApi } from '#/api/ecommerce/platform';
|
||||
import { deleteShopApi, getShopPageApi } from '#/api/ecommerce/shop';
|
||||
|
||||
import PddOrderSyncModal from './components/PddOrderSyncModal.vue';
|
||||
import PddShopDetailModal from './components/PddShopDetailModal.vue';
|
||||
import ShopFormModal from './components/ShopFormModal.vue';
|
||||
|
||||
@@ -32,6 +33,7 @@ const loading = ref(false);
|
||||
const authorizing = ref(false);
|
||||
const shopFormModalRef = ref();
|
||||
const pddShopDetailModalRef = ref();
|
||||
const pddOrderSyncModalRef = ref();
|
||||
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
@@ -88,7 +90,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 360,
|
||||
minWidth: 420,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
@@ -278,6 +280,14 @@ function handleViewExternalShop(record: ShopVO.Info) {
|
||||
pddShopDetailModalRef.value?.open(record.pddShop, record.name);
|
||||
}
|
||||
|
||||
function handleSyncPddOrders(record: ShopVO.Info) {
|
||||
if (!hasExternalShop(record)) {
|
||||
message.warning('请先完成拼多多授权绑定后再同步订单');
|
||||
return;
|
||||
}
|
||||
pddOrderSyncModalRef.value?.open(record);
|
||||
}
|
||||
|
||||
function clearAuthPoll() {
|
||||
if (authPollTimer) {
|
||||
clearInterval(authPollTimer);
|
||||
@@ -403,6 +413,13 @@ onUnmounted(() => {
|
||||
>
|
||||
外部店铺
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isPddShop(row) && hasExternalShop(row)"
|
||||
size="small"
|
||||
@click="handleSyncPddOrders(row)"
|
||||
>
|
||||
同步订单
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isPddShop(row)"
|
||||
size="small"
|
||||
@@ -426,6 +443,7 @@ onUnmounted(() => {
|
||||
|
||||
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
|
||||
<PddShopDetailModal ref="pddShopDetailModalRef" />
|
||||
<PddOrderSyncModal ref="pddOrderSyncModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user