mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 06:29:20 +08:00
feat: 创建商品时同步提示新增规格的成本;优化成本同步弹框日期范围交互
- 新增 CreateProductResultDTO:创建商品响应含 specIdsCostChangedWithLinkedOrders - ProductService.createProduct:新增规格(编码非空、三项成本至少一项大于 0、且有关联订单)时纳入同步提示 - ProductService.updateProduct:合并成本变更规格与新增规格中有关联订单的 ID集合 - OrderService:新增 companyHasOrdersForSpec() 查询单个规格是否存在关联订单 - BatchSyncCostDTO:注释明确 startTime/endTime 为含边界的 LocalDateTime 字符串 - 前端成本同步弹窗:日期选择器改为纯日期格式(YYYY-MM-DD),提交时自动补 00:00:00 / 23:59:59 - ProductFormModal:创建商品后若有待同步规格则自动弹出成本同步确认框
This commit is contained in:
@@ -77,13 +77,13 @@ export namespace ProductSpecDTO {
|
||||
endTime: string;
|
||||
}
|
||||
|
||||
/** 批量同步规格成本到订单 */
|
||||
/** 批量同步规格成本到订单(按订单 orderTime,起止为含时分秒的 LocalDateTime 字符串) */
|
||||
export interface BatchSyncCost {
|
||||
/** 规格ID列表 */
|
||||
specIds: number[];
|
||||
/** 订单开始时间 */
|
||||
/** 订单时间下限(含),如 `2024-01-01 00:00:00` */
|
||||
startTime: string;
|
||||
/** 订单结束时间 */
|
||||
/** 订单时间上限(含),如 `2024-01-31 23:59:59` */
|
||||
endTime: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,10 @@ export async function getProductPageApi(
|
||||
* 创建商品
|
||||
*/
|
||||
export async function createProductApi(data: ProductDTO.Create) {
|
||||
return requestClient.post<ProductVO.Info>('/ec/product/create', data);
|
||||
return requestClient.post<ProductVO.CreateProductResult>(
|
||||
'/ec/product/create',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,13 +36,20 @@ export namespace ProductVO {
|
||||
/** 更新商品响应 */
|
||||
export interface UpdateProductResult {
|
||||
/**
|
||||
* 成本已变更且当前公司在库中存在关联订单的规格ID列表(用于提示同步成本到订单)
|
||||
* 需提示同步:成本已变更且有关联订单;或新增规格(编码非空、商品/运费/其他成本至少一项大于 0)且有关联订单
|
||||
*/
|
||||
specIdsCostChangedWithLinkedOrders: number[];
|
||||
/** 更新后的商品完整信息 */
|
||||
product: ProductVO.Info;
|
||||
}
|
||||
|
||||
/** 创建商品响应 */
|
||||
export interface CreateProductResult {
|
||||
/** 新增规格:编码非空、至少一项成本大于 0、且有关联订单的规格 ID */
|
||||
specIdsCostChangedWithLinkedOrders: number[];
|
||||
product: ProductVO.Info;
|
||||
}
|
||||
|
||||
/** 商品规格信息 */
|
||||
export interface SpecInfo {
|
||||
/** 规格ID */
|
||||
|
||||
+22
-11
@@ -20,10 +20,22 @@ type ProductCostSyncModalEntry = 'after-save' | 'manual';
|
||||
interface ProductCostSyncOpenOptions {
|
||||
/** 保存后提示 / 用户主动同步 */
|
||||
entry?: ProductCostSyncModalEntry;
|
||||
/** 打开时预填时间范围;不传则清空由用户选择 */
|
||||
/** 打开时预填日期范围 `YYYY-MM-DD`;不传则清空由用户选择 */
|
||||
initialDateRange?: [string, string];
|
||||
}
|
||||
|
||||
/** 将选中的日期范围转为接口所需 LocalDateTime 字符串(起日 00:00:00,止日 23:59:59) */
|
||||
function dateRangeToApiTimes(range: [string, string]): {
|
||||
endTime: string;
|
||||
startTime: string;
|
||||
} {
|
||||
const [startDate, endDate] = range;
|
||||
return {
|
||||
startTime: `${startDate} 00:00:00`,
|
||||
endTime: `${endDate} 23:59:59`,
|
||||
};
|
||||
}
|
||||
|
||||
const [SyncModal, syncModalApi] = useVbenModal({
|
||||
title: '成本变更同步确认',
|
||||
class: 'w-[720px] max-w-[calc(100vw-2rem)]',
|
||||
@@ -68,7 +80,7 @@ async function fetchCostSyncOrderCount() {
|
||||
}
|
||||
costSyncOrderCountLoading.value = true;
|
||||
try {
|
||||
const [startTime, endTime] = range;
|
||||
const { startTime, endTime } = dateRangeToApiTimes(range);
|
||||
costSyncOrderCount.value = await countOrdersForCostSyncApi({
|
||||
specIds: [...selectedSyncSpecIds.value],
|
||||
startTime,
|
||||
@@ -139,16 +151,16 @@ async function handleSyncConfirm() {
|
||||
}
|
||||
const range = syncFormData.value;
|
||||
if (!range?.[0] || !range[1]) {
|
||||
message.warning('请选择同步时间范围');
|
||||
message.warning('请选择同步日期范围');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
syncModalApi.setState?.({ confirmLoading: true });
|
||||
const [startDate, endDate] = range;
|
||||
const { startTime, endTime } = dateRangeToApiTimes(range);
|
||||
const totalUpdated = await batchSyncCostsToOrdersApi({
|
||||
specIds: selectedSyncSpecIds.value,
|
||||
startTime: startDate,
|
||||
endTime: endDate,
|
||||
startTime,
|
||||
endTime,
|
||||
});
|
||||
message.success(`成本同步完成,共更新 ${totalUpdated ?? 0} 条订单`);
|
||||
syncModalApi.close?.();
|
||||
@@ -239,13 +251,12 @@ defineExpose({ open });
|
||||
</div>
|
||||
|
||||
<div class="time-range-section">
|
||||
<label class="section-label">同步时间范围</label>
|
||||
<label class="section-label">同步日期范围</label>
|
||||
<DatePicker.RangePicker
|
||||
v-model:value="syncFormData"
|
||||
class="w-full"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
show-time
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
/>
|
||||
<div
|
||||
class="sync-order-count mt-2 text-sm text-gray-600 dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
@@ -260,7 +271,7 @@ defineExpose({ open });
|
||||
selectedSyncSpecIds.length > 0
|
||||
"
|
||||
>
|
||||
当前时间范围内共
|
||||
当前日期范围内共
|
||||
<strong class="text-gray-900 dark:text-[hsl(0deg_0%_95%)]">{{
|
||||
costSyncOrderCount
|
||||
}}</strong>
|
||||
|
||||
+6
-3
@@ -65,8 +65,8 @@ async function openSyncModal(specIds: number[]) {
|
||||
await productCostSyncModalRef.value?.open(specIds, {
|
||||
entry: 'after-save',
|
||||
initialDateRange: [
|
||||
dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
|
||||
dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
|
||||
dayjs().startOf('day').format('YYYY-MM-DD'),
|
||||
dayjs().endOf('day').format('YYYY-MM-DD'),
|
||||
],
|
||||
});
|
||||
}
|
||||
@@ -342,9 +342,12 @@ async function handleSubmit() {
|
||||
specs: specs.value.map(({ _clientKey: _c, id: _id, ...rest }) => rest),
|
||||
}),
|
||||
};
|
||||
await createProductApi(createData);
|
||||
const createResult = await createProductApi(createData);
|
||||
if (specs.value.length > 0) {
|
||||
message.success('商品和规格创建成功');
|
||||
if (createResult.specIdsCostChangedWithLinkedOrders?.length > 0) {
|
||||
void openSyncModal(createResult.specIdsCostChangedWithLinkedOrders);
|
||||
}
|
||||
} else {
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user