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 { const body = toBatchImportRequest(batch); if (!body.items.length) { throw new Error('没有可传入的记录(推广费须大于 0)'); } return openApiRequest( OPEN_API_PATHS.pddGoodsAdFeeBatchImport, { method: 'POST', body: JSON.stringify(body), }, ); }