mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat(ecom-dmb): 成本同步弹窗新增实时订单数预览,确认前显示受影响订单数量
This commit is contained in:
+12
@@ -87,4 +87,16 @@ public interface OrderService extends IService<OrderPO> {
|
||||
int syncCostsToOrders(Long specId, java.math.BigDecimal productCost,
|
||||
java.math.BigDecimal shippingCost, java.math.BigDecimal otherCost,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 统计在指定时间范围内、且商品规格在列表中的订单数量(与成本同步 UPDATE 条件一致,用于同步前预览)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param specIds 规格ID列表
|
||||
* @param startTime 订单时间起(含)
|
||||
* @param endTime 订单时间止(含)
|
||||
* @return 订单条数
|
||||
*/
|
||||
long countOrdersForCostSync(Long companyId, java.util.List<Long> specIds,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime);
|
||||
}
|
||||
|
||||
+14
@@ -463,4 +463,18 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
return baseMapper.updateCostFields(productCost, shippingCost, otherCost, specId, startTime, endTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countOrdersForCostSync(Long companyId, List<Long> specIds,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime) {
|
||||
if (specIds == null || specIds.isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
Long cnt = baseMapper.selectCount(new LambdaQueryWrapper<OrderPO>()
|
||||
.eq(OrderPO::getCompanyId, companyId)
|
||||
.in(OrderPO::getProductSpecId, specIds)
|
||||
.ge(OrderPO::getOrderTime, startTime)
|
||||
.le(OrderPO::getOrderTime, endTime));
|
||||
return cnt == null ? 0L : cnt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+22
@@ -136,6 +136,28 @@ public class ProductSpecController {
|
||||
return ApiResponse.success("成本同步成功,共更新" + updatedCount + "条订单", updatedCount);
|
||||
}
|
||||
|
||||
@Operation(summary = "统计成本同步将影响的订单数量", description = "根据已选规格与订单时间范围,统计当前公司将更新的订单条数,条件与批量同步一致")
|
||||
@PostMapping("/count-orders-for-cost-sync")
|
||||
@RequirePermission(value = "ecom:product:read", description = "统计成本同步订单数", allowSuper = true)
|
||||
public ApiResponse<Long> countOrdersForCostSync(@Valid @RequestBody BatchSyncCostDTO batchSyncCostDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
List<ProductSpecPO> specs = productSpecService.getByIds(batchSyncCostDTO.getSpecIds());
|
||||
if (specs.isEmpty()) {
|
||||
return ApiResponse.success("统计成功", 0L);
|
||||
}
|
||||
for (ProductSpecPO spec : specs) {
|
||||
if (!spec.getCompanyId().equals(companyId)) {
|
||||
throw new BusinessException("规格不存在,规格ID: " + spec.getId());
|
||||
}
|
||||
}
|
||||
long count = orderService.countOrdersForCostSync(
|
||||
companyId,
|
||||
batchSyncCostDTO.getSpecIds(),
|
||||
batchSyncCostDTO.getStartTime(),
|
||||
batchSyncCostDTO.getEndTime());
|
||||
return ApiResponse.success("统计成功", count);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量同步规格成本到历史订单", description = "批量将多个规格的成本同步到符合时间范围的订单")
|
||||
@PostMapping("/batch-sync-costs-to-orders")
|
||||
@RequirePermission(value = "ecom:product:update", description = "批量同步成本到订单", allowSuper = true)
|
||||
|
||||
@@ -99,3 +99,10 @@ export async function syncCostsToOrdersApi(data: ProductSpecDTO.SyncCost) {
|
||||
export async function batchSyncCostsToOrdersApi(data: ProductSpecDTO.BatchSyncCost) {
|
||||
return requestClient.post<number>('/ec/product-spec/batch-sync-costs-to-orders', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计指定规格与时间范围内将参与成本同步的订单数量(与批量同步匹配规则一致)
|
||||
*/
|
||||
export async function countOrdersForCostSyncApi(data: ProductSpecDTO.BatchSyncCost) {
|
||||
return requestClient.post<number>('/ec/product-spec/count-orders-for-cost-sync', data);
|
||||
}
|
||||
|
||||
+83
-4
@@ -24,6 +24,7 @@ import TextArea from 'ant-design-vue/es/input/TextArea';
|
||||
import { updateProductApi } from '#/api/ecommerce/product';
|
||||
import {
|
||||
batchSyncCostsToOrdersApi,
|
||||
countOrdersForCostSyncApi,
|
||||
getProductSpecsByIdsApi,
|
||||
} from '#/api/ecommerce/product-spec/apis';
|
||||
import type { ProductSpecVO } from '#/api/ecommerce/product-spec/types';
|
||||
@@ -42,10 +43,12 @@ const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 成本同步弹窗
|
||||
const [SyncModal, syncModalApi] = useVbenModal({
|
||||
title: '成本变更确认',
|
||||
title: '成本变更同步确认',
|
||||
class: 'w-[500px]',
|
||||
draggable: true,
|
||||
contentClass: 'px-5 py-4',
|
||||
cancelText: '暂不同步',
|
||||
confirmText: '立即同步',
|
||||
onConfirm: handleSyncConfirm,
|
||||
onCancel: () => {
|
||||
syncModalApi.close();
|
||||
@@ -53,6 +56,66 @@ const [SyncModal, syncModalApi] = useVbenModal({
|
||||
});
|
||||
|
||||
const syncFormData = ref<[string, string] | undefined>(undefined);
|
||||
const pendingCostChangedSpecs = ref<ProductSpecVO.Info[]>([]);
|
||||
const selectedSyncSpecIds = ref<number[]>([]);
|
||||
|
||||
/** 当前时间范围内将参与同步的订单数(null 表示未请求或条件不齐) */
|
||||
const costSyncOrderCount = ref<null | number>(null);
|
||||
const costSyncOrderCountLoading = ref(false);
|
||||
let costSyncCountTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
function scheduleFetchCostSyncOrderCount() {
|
||||
if (costSyncCountTimer) {
|
||||
clearTimeout(costSyncCountTimer);
|
||||
}
|
||||
costSyncCountTimer = setTimeout(() => {
|
||||
costSyncCountTimer = null;
|
||||
void fetchCostSyncOrderCount();
|
||||
}, 300);
|
||||
}
|
||||
|
||||
async function fetchCostSyncOrderCount() {
|
||||
if (
|
||||
!syncFormData.value ||
|
||||
syncFormData.value[0] == null ||
|
||||
syncFormData.value[1] == null
|
||||
) {
|
||||
costSyncOrderCount.value = null;
|
||||
return;
|
||||
}
|
||||
if (selectedSyncSpecIds.value.length === 0) {
|
||||
costSyncOrderCount.value = null;
|
||||
return;
|
||||
}
|
||||
costSyncOrderCountLoading.value = true;
|
||||
try {
|
||||
const [startTime, endTime] = syncFormData.value;
|
||||
costSyncOrderCount.value = await countOrdersForCostSyncApi({
|
||||
specIds: [...selectedSyncSpecIds.value],
|
||||
startTime,
|
||||
endTime,
|
||||
});
|
||||
} catch {
|
||||
costSyncOrderCount.value = null;
|
||||
} finally {
|
||||
costSyncOrderCountLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [...selectedSyncSpecIds.value],
|
||||
() => {
|
||||
scheduleFetchCostSyncOrderCount();
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
syncFormData,
|
||||
() => {
|
||||
scheduleFetchCostSyncOrderCount();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
async function openSyncModal(costChangedSpecIds: number[]) {
|
||||
try {
|
||||
@@ -60,6 +123,7 @@ async function openSyncModal(costChangedSpecIds: number[]) {
|
||||
pendingCostChangedSpecs.value = specs ?? [];
|
||||
selectedSyncSpecIds.value = costChangedSpecIds;
|
||||
syncFormData.value = undefined;
|
||||
costSyncOrderCount.value = null;
|
||||
syncModalApi.open();
|
||||
} catch (error) {
|
||||
console.error('获取规格详情失败:', error);
|
||||
@@ -67,9 +131,6 @@ async function openSyncModal(costChangedSpecIds: number[]) {
|
||||
}
|
||||
}
|
||||
|
||||
const pendingCostChangedSpecs = ref<ProductSpecVO.Info[]>([]);
|
||||
const selectedSyncSpecIds = ref<number[]>([]);
|
||||
|
||||
function toggleSpec(specId: number) {
|
||||
const idx = selectedSyncSpecIds.value.indexOf(specId);
|
||||
if (idx === -1) {
|
||||
@@ -634,6 +695,24 @@ const saveEdit = async () => {
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
show-time
|
||||
/>
|
||||
<div class="sync-order-count mt-2 text-sm text-gray-600 dark:text-gray-400">
|
||||
<template v-if="costSyncOrderCountLoading">正在统计订单数…</template>
|
||||
<template
|
||||
v-else-if="
|
||||
costSyncOrderCount !== null &&
|
||||
syncFormData &&
|
||||
syncFormData[0] &&
|
||||
syncFormData[1] &&
|
||||
selectedSyncSpecIds.length > 0
|
||||
"
|
||||
>
|
||||
当前时间范围内共
|
||||
<strong class="text-gray-900 dark:text-gray-100">{{
|
||||
costSyncOrderCount
|
||||
}}</strong>
|
||||
条订单将更新成本
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</SyncModal>
|
||||
|
||||
+82
-5
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
|
||||
|
||||
import { computed, h, onUnmounted, ref } from 'vue';
|
||||
import { computed, h, onUnmounted, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
@@ -22,6 +22,7 @@ import dayjs from 'dayjs';
|
||||
import { createProductApi, updateProductApi } from '#/api/ecommerce/product';
|
||||
import {
|
||||
batchSyncCostsToOrdersApi,
|
||||
countOrdersForCostSyncApi,
|
||||
getProductSpecsByIdsApi,
|
||||
} from '#/api/ecommerce/product-spec/apis';
|
||||
import type { ProductSpecVO } from '#/api/ecommerce/product-spec/types';
|
||||
@@ -62,16 +63,77 @@ const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
// 成本同步弹窗
|
||||
const [SyncModal, syncModalApi] = useVbenModal({
|
||||
title: '成本变更确认',
|
||||
title: '成本变更同步确认',
|
||||
class: 'w-[500px]',
|
||||
draggable: true,
|
||||
contentClass: 'px-5 py-4',
|
||||
cancelText: '暂不同步',
|
||||
confirmText: '立即同步',
|
||||
onConfirm: handleSyncConfirm,
|
||||
onCancel: () => {
|
||||
syncModalApi.close();
|
||||
},
|
||||
});
|
||||
const syncFormData = ref<[string, string] | undefined>(undefined);
|
||||
const pendingCostChangedSpecs = ref<ProductSpecVO.Info[]>([]);
|
||||
const selectedSyncSpecIds = ref<number[]>([]);
|
||||
|
||||
const costSyncOrderCount = ref<null | number>(null);
|
||||
const costSyncOrderCountLoading = ref(false);
|
||||
let costSyncCountTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
function scheduleFetchCostSyncOrderCount() {
|
||||
if (costSyncCountTimer) {
|
||||
clearTimeout(costSyncCountTimer);
|
||||
}
|
||||
costSyncCountTimer = setTimeout(() => {
|
||||
costSyncCountTimer = null;
|
||||
void fetchCostSyncOrderCount();
|
||||
}, 300);
|
||||
}
|
||||
|
||||
async function fetchCostSyncOrderCount() {
|
||||
if (
|
||||
!syncFormData.value ||
|
||||
syncFormData.value[0] == null ||
|
||||
syncFormData.value[1] == null
|
||||
) {
|
||||
costSyncOrderCount.value = null;
|
||||
return;
|
||||
}
|
||||
if (selectedSyncSpecIds.value.length === 0) {
|
||||
costSyncOrderCount.value = null;
|
||||
return;
|
||||
}
|
||||
costSyncOrderCountLoading.value = true;
|
||||
try {
|
||||
const [startTime, endTime] = syncFormData.value;
|
||||
costSyncOrderCount.value = await countOrdersForCostSyncApi({
|
||||
specIds: [...selectedSyncSpecIds.value],
|
||||
startTime,
|
||||
endTime,
|
||||
});
|
||||
} catch {
|
||||
costSyncOrderCount.value = null;
|
||||
} finally {
|
||||
costSyncOrderCountLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [...selectedSyncSpecIds.value],
|
||||
() => {
|
||||
scheduleFetchCostSyncOrderCount();
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
syncFormData,
|
||||
() => {
|
||||
scheduleFetchCostSyncOrderCount();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
async function openSyncModal(costChangedSpecIds: number[]) {
|
||||
try {
|
||||
@@ -83,16 +145,15 @@ async function openSyncModal(costChangedSpecIds: number[]) {
|
||||
dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
|
||||
dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
|
||||
];
|
||||
costSyncOrderCount.value = null;
|
||||
syncModalApi.open();
|
||||
scheduleFetchCostSyncOrderCount();
|
||||
} catch (error) {
|
||||
console.error('获取规格详情失败:', error);
|
||||
message.error('获取规格详情失败,无法进行成本同步');
|
||||
}
|
||||
}
|
||||
|
||||
const pendingCostChangedSpecs = ref<ProductSpecVO.Info[]>([]);
|
||||
const selectedSyncSpecIds = ref<number[]>([]);
|
||||
|
||||
async function handleSyncConfirm() {
|
||||
if (selectedSyncSpecIds.value.length === 0 || !syncFormData.value) return;
|
||||
try {
|
||||
@@ -785,6 +846,22 @@ onUnmounted(() => {
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
show-time
|
||||
/>
|
||||
<div class="mt-2 text-sm text-gray-500">
|
||||
<template v-if="costSyncOrderCountLoading">正在统计订单数…</template>
|
||||
<template
|
||||
v-else-if="
|
||||
costSyncOrderCount !== null &&
|
||||
syncFormData &&
|
||||
syncFormData[0] &&
|
||||
syncFormData[1] &&
|
||||
selectedSyncSpecIds.length > 0
|
||||
"
|
||||
>
|
||||
当前时间范围内共
|
||||
<strong class="text-gray-800">{{ costSyncOrderCount }}</strong>
|
||||
条订单将更新成本
|
||||
</template>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user