mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import type { AdvertisingCostBatch } from '@/types/advertisingCost';
|
|
|
|
import { openApiRequest } from '@/api/client';
|
|
import { OPEN_API_PATHS } from '@/shared/constants';
|
|
|
|
export interface BatchImportPddGoodsAdFeeItem {
|
|
channelShopId: number;
|
|
feeDate: string;
|
|
goodsId: string;
|
|
feeAmount: number;
|
|
}
|
|
|
|
export interface BatchImportPddGoodsAdFeeRequest {
|
|
items: BatchImportPddGoodsAdFeeItem[];
|
|
}
|
|
|
|
export interface BatchImportPddGoodsAdFeeResult {
|
|
totalCount: number;
|
|
successCount: number;
|
|
failureCount: number;
|
|
successIds?: number[];
|
|
failureRecords?: Array<{
|
|
rowNumber?: number;
|
|
channelShopId?: number;
|
|
goodsId?: string;
|
|
failureReason?: string;
|
|
}>;
|
|
}
|
|
|
|
/** 插件统一模型 → 后端 batch-import 入参(日期取自每条 item;金额须大于 0) */
|
|
export function toBatchImportRequest(
|
|
batch: AdvertisingCostBatch,
|
|
): BatchImportPddGoodsAdFeeRequest {
|
|
return {
|
|
items: batch.items
|
|
.filter((item) => Number(item.feeAmount) > 0)
|
|
.map((item) => ({
|
|
channelShopId: batch.channelShopId,
|
|
feeDate: item.feeDate,
|
|
goodsId: item.goodsId,
|
|
feeAmount: item.feeAmount,
|
|
})),
|
|
};
|
|
}
|
|
|
|
export async function batchImportPddGoodsAdFee(
|
|
batch: AdvertisingCostBatch,
|
|
): Promise<BatchImportPddGoodsAdFeeResult> {
|
|
const body = toBatchImportRequest(batch);
|
|
if (!body.items.length) {
|
|
throw new Error('没有可传入的记录(推广费须大于 0)');
|
|
}
|
|
return openApiRequest<BatchImportPddGoodsAdFeeResult>(
|
|
OPEN_API_PATHS.pddGoodsAdFeeBatchImport,
|
|
{
|
|
method: 'POST',
|
|
body: JSON.stringify(body),
|
|
},
|
|
);
|
|
}
|