mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:09:20 +08:00
feat: 新增迁品重算
This commit is contained in:
@@ -13,7 +13,7 @@ export namespace BiOrderStatCalcVO {
|
||||
export interface FullTask {
|
||||
id: number;
|
||||
shopId: number;
|
||||
/** MANUAL / CONVERT / COST_SYNC */
|
||||
/** MANUAL / CONVERT / COST_SYNC / SKU_MIGRATE */
|
||||
triggerSource?: string;
|
||||
/** 上游任务 id;含义由 triggerSource 决定 */
|
||||
upstreamTaskId?: number;
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
export namespace SkuMigrateVO {
|
||||
export interface Impact {
|
||||
id: number;
|
||||
skuId: number;
|
||||
fromProductId: number;
|
||||
toProductId: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
status: string;
|
||||
createTime?: string;
|
||||
appliedTime?: string;
|
||||
applyBatchId?: string;
|
||||
}
|
||||
|
||||
export interface ApplyTaskBrief {
|
||||
applyTaskId: number;
|
||||
shopId: number;
|
||||
biCalcTaskId?: number;
|
||||
dateFrom: string;
|
||||
dateTo: string;
|
||||
totalDays: number;
|
||||
status: string;
|
||||
createTime?: string;
|
||||
}
|
||||
|
||||
export interface ApplyResult {
|
||||
applyBatchId: string;
|
||||
impactCount: number;
|
||||
taskCount: number;
|
||||
tasks: ApplyTaskBrief[];
|
||||
}
|
||||
}
|
||||
|
||||
/** 待重算迁品影响面 */
|
||||
export async function listPendingSkuMigrateImpactsApi() {
|
||||
return requestClient.get<SkuMigrateVO.Impact[]>(
|
||||
'/ec/sku-migrate/impacts/pending',
|
||||
);
|
||||
}
|
||||
|
||||
/** 一键创建 BI 全量重算任务 */
|
||||
export async function applyPendingSkuMigrateImpactsApi() {
|
||||
return requestClient.post<SkuMigrateVO.ApplyResult>(
|
||||
'/ec/sku-migrate/apply-pending',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './apis';
|
||||
+15
@@ -25,6 +25,7 @@ import { uploadFile } from '#/utils/upload-file';
|
||||
import CategoryFormModal from '#/views/ec/product/category/components/CategoryFormModal.vue';
|
||||
import ProductCostSyncToOrdersModal from './ProductCostSyncToOrdersModal.vue';
|
||||
import ProductSkuCostDrawer from './ProductSkuCostDrawer.vue';
|
||||
import ProductSkuMigrateImpactModal from './ProductSkuMigrateImpactModal.vue';
|
||||
import ProductSkuMigrateModal from './ProductSkuMigrateModal.vue';
|
||||
|
||||
interface Emits {
|
||||
@@ -68,6 +69,9 @@ const productSkuCostDrawerRef = ref<InstanceType<
|
||||
const productSkuMigrateModalRef = ref<InstanceType<
|
||||
typeof ProductSkuMigrateModal
|
||||
> | null>(null);
|
||||
const productSkuMigrateImpactModalRef = ref<InstanceType<
|
||||
typeof ProductSkuMigrateImpactModal
|
||||
> | null>(null);
|
||||
|
||||
async function openSyncModal(skuIds: number[]) {
|
||||
await productCostSyncModalRef.value?.open(skuIds, {
|
||||
@@ -582,6 +586,10 @@ function openMigrateModal() {
|
||||
);
|
||||
}
|
||||
|
||||
function openMigrateImpactModal() {
|
||||
productSkuMigrateImpactModalRef.value?.open();
|
||||
}
|
||||
|
||||
function onMigrateSuccess(product: ProductVO.Info) {
|
||||
applySkusFromProduct(product);
|
||||
emit('success');
|
||||
@@ -1073,6 +1081,12 @@ onUnmounted(() => {
|
||||
>
|
||||
迁入他品 SKU
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isEdit && currentProductData?.id"
|
||||
@click="openMigrateImpactModal"
|
||||
>
|
||||
迁品待重算
|
||||
</Button>
|
||||
<Button type="primary" @click="addSku">
|
||||
<template #icon>
|
||||
<PlusIcon class="h-4 w-4" />
|
||||
@@ -1122,5 +1136,6 @@ onUnmounted(() => {
|
||||
ref="productSkuMigrateModalRef"
|
||||
@success="onMigrateSuccess"
|
||||
/>
|
||||
<ProductSkuMigrateImpactModal ref="productSkuMigrateImpactModalRef" />
|
||||
<CategoryFormModal ref="categoryFormModalRef" @success="reloadCategoryTree" />
|
||||
</template>
|
||||
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<script lang="ts" setup>
|
||||
import type { SkuMigrateVO } from '#/api/ec/sku-migrate';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Alert, Button, Table, message } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
applyPendingSkuMigrateImpactsApi,
|
||||
listPendingSkuMigrateImpactsApi,
|
||||
} from '#/api/ec/sku-migrate';
|
||||
|
||||
defineOptions({ name: 'ProductSkuMigrateImpactModal' });
|
||||
|
||||
const [SyncModal, syncModalApi] = useVbenModal({
|
||||
title: '迁品待重算',
|
||||
class: 'w-[800px] max-w-[calc(100vw-2rem)]',
|
||||
draggable: true,
|
||||
contentClass: 'px-5 py-4 min-h-[360px]',
|
||||
showCancelButton: true,
|
||||
cancelText: '关闭',
|
||||
showConfirmButton: false,
|
||||
});
|
||||
|
||||
const loading = ref(false);
|
||||
const applying = ref(false);
|
||||
const pending = ref<SkuMigrateVO.Impact[]>([]);
|
||||
const lastResult = ref<SkuMigrateVO.ApplyResult | null>(null);
|
||||
|
||||
const columns = [
|
||||
{ title: 'SKU ID', dataIndex: 'skuId', key: 'skuId', width: 90 },
|
||||
{
|
||||
title: '迁出商品',
|
||||
dataIndex: 'fromProductId',
|
||||
key: 'fromProductId',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '迁入商品',
|
||||
dataIndex: 'toProductId',
|
||||
key: 'toProductId',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: '影响区间',
|
||||
key: 'range',
|
||||
customRender: ({ record }: { record: SkuMigrateVO.Impact }) =>
|
||||
`${record.dateFrom} ~ ${record.dateTo}`,
|
||||
},
|
||||
];
|
||||
|
||||
async function reload() {
|
||||
loading.value = true;
|
||||
lastResult.value = null;
|
||||
try {
|
||||
pending.value = (await listPendingSkuMigrateImpactsApi()) ?? [];
|
||||
} catch {
|
||||
pending.value = [];
|
||||
message.error('加载迁品影响面失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function open() {
|
||||
syncModalApi.open();
|
||||
await reload();
|
||||
}
|
||||
|
||||
async function handleApply() {
|
||||
if (pending.value.length === 0) {
|
||||
message.info('没有待重算的影响面');
|
||||
return;
|
||||
}
|
||||
applying.value = true;
|
||||
try {
|
||||
const result = await applyPendingSkuMigrateImpactsApi();
|
||||
lastResult.value = result ?? null;
|
||||
message.success(
|
||||
`已创建 ${result?.taskCount ?? 0} 个店铺 BI 重算任务(影响面 ${result?.impactCount ?? 0} 条)`,
|
||||
);
|
||||
await reload();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
applying.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<SyncModal>
|
||||
<Alert
|
||||
type="info"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
message="迁品后会记入待重算影响面。确认归属无误后一键按店创建 BI 全量任务,按日 FULL 纠正商品维统计(不改订单明细)。"
|
||||
/>
|
||||
<div class="mb-3 flex items-center justify-between gap-2">
|
||||
<span class="text-muted-foreground text-sm">
|
||||
待重算 {{ pending.length }} 条
|
||||
</span>
|
||||
<div class="flex gap-2">
|
||||
<Button :loading="loading" @click="reload">刷新</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:loading="applying"
|
||||
:disabled="pending.length === 0"
|
||||
@click="handleApply"
|
||||
>
|
||||
一键重算 BI
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Table
|
||||
size="small"
|
||||
row-key="id"
|
||||
:loading="loading"
|
||||
:columns="columns"
|
||||
:data-source="pending"
|
||||
:pagination="false"
|
||||
/>
|
||||
<div v-if="lastResult" class="text-muted-foreground mt-3 text-sm">
|
||||
批次 {{ lastResult.applyBatchId }} · 任务 {{ lastResult.taskCount }} 个
|
||||
</div>
|
||||
</SyncModal>
|
||||
</template>
|
||||
+1
-1
@@ -84,7 +84,7 @@ async function confirmMigrate(sku: ProductSkuVO.Info) {
|
||||
migratingSkuId.value = sku.id;
|
||||
try {
|
||||
const product = await migrateSkuToProductApi(targetProductId.value, sku.id);
|
||||
message.success('SKU 已迁入');
|
||||
message.success('SKU 已迁入,已记入迁品待重算影响面');
|
||||
emit('success', product);
|
||||
close();
|
||||
} finally {
|
||||
|
||||
+10
@@ -200,6 +200,16 @@ function taskOriginTag(
|
||||
: '成本同步触发',
|
||||
};
|
||||
}
|
||||
if (source === 'SKU_MIGRATE') {
|
||||
return {
|
||||
color: 'cyan' as const,
|
||||
text: '迁品重算',
|
||||
tip:
|
||||
upstreamTaskId != null
|
||||
? `上游迁品任务 #${upstreamTaskId}`
|
||||
: '迁品账本一键触发',
|
||||
};
|
||||
}
|
||||
if (source === 'CONVERT' || (upstreamTaskId != null && source !== 'MANUAL')) {
|
||||
return {
|
||||
color: 'blue' as const,
|
||||
|
||||
Reference in New Issue
Block a user