feat: 不收几推广费为0的推广记录

This commit is contained in:
2026-08-16 23:13:41 +08:00
parent 50ce131d60
commit b4455a4788
13 changed files with 43 additions and 25 deletions
+2 -2
View File
@@ -29,9 +29,9 @@ async function main() {
{ {
id: 'pdd-ad-fee', id: 'pdd-ad-fee',
name: '拼多多商品推广费同步', name: '拼多多商品推广费同步',
version: '0.3.9', version: '0.3.10',
description: description:
'从推广总览读取推广费并同步到 BI(浮窗滚动条统一 thin)', '从推广总览读取推广费并同步到 BI(总花费为 0 不记录)',
matchUrlPatterns: [ matchUrlPatterns: [
'*://yingxiao.pinduoduo.com/*', '*://yingxiao.pinduoduo.com/*',
'https://yingxiao.pinduoduo.com/', 'https://yingxiao.pinduoduo.com/',
@@ -27,17 +27,19 @@ export interface BatchImportPddGoodsAdFeeResult {
}>; }>;
} }
/** 插件统一模型 → 后端 batch-import 入参(日期取自每条 item) */ /** 插件统一模型 → 后端 batch-import 入参(日期取自每条 item;金额须大于 0) */
export function toBatchImportRequest( export function toBatchImportRequest(
batch: AdvertisingCostBatch, batch: AdvertisingCostBatch,
): BatchImportPddGoodsAdFeeRequest { ): BatchImportPddGoodsAdFeeRequest {
return { return {
items: batch.items.map((item) => ({ items: batch.items
channelShopId: batch.channelShopId, .filter((item) => Number(item.feeAmount) > 0)
feeDate: item.feeDate, .map((item) => ({
goodsId: item.goodsId, channelShopId: batch.channelShopId,
feeAmount: item.feeAmount, feeDate: item.feeDate,
})), goodsId: item.goodsId,
feeAmount: item.feeAmount,
})),
}; };
} }
@@ -45,6 +47,9 @@ export async function batchImportPddGoodsAdFee(
batch: AdvertisingCostBatch, batch: AdvertisingCostBatch,
): Promise<BatchImportPddGoodsAdFeeResult> { ): Promise<BatchImportPddGoodsAdFeeResult> {
const body = toBatchImportRequest(batch); const body = toBatchImportRequest(batch);
if (!body.items.length) {
throw new Error('没有可传入的记录(推广费须大于 0)');
}
return openApiRequest<BatchImportPddGoodsAdFeeResult>( return openApiRequest<BatchImportPddGoodsAdFeeResult>(
OPEN_API_PATHS.pddGoodsAdFeeBatchImport, OPEN_API_PATHS.pddGoodsAdFeeBatchImport,
{ {
@@ -6,7 +6,7 @@ import { installMainWorldAdapters } from '@/features/runtime/mainWorldAdapters';
import { setFloatingVisible } from '@/content/floating/mount'; import { setFloatingVisible } from '@/content/floating/mount';
const FEATURE_ID = 'pdd-ad-fee'; const FEATURE_ID = 'pdd-ad-fee';
const FEATURE_VERSION = '0.3.9'; const FEATURE_VERSION = '0.3.10';
export interface RemoteFeatureExport { export interface RemoteFeatureExport {
id: string; id: string;
@@ -134,7 +134,8 @@ export function parsePromotionItems(
const cells = Array.from(row.querySelectorAll(':scope > td')); const cells = Array.from(row.querySelectorAll(':scope > td'));
const feeCell = cells[feeCol]; const feeCell = cells[feeCol];
const feeAmount = parseAmount(feeCell?.textContent); const feeAmount = parseAmount(feeCell?.textContent);
if (feeAmount == null) continue; // 总花费为 0 / 空 不记录
if (feeAmount == null || feeAmount <= 0) continue;
seen.add(goodsId); seen.add(goodsId);
items.push({ items.push({
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.adfee.model.dto;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -25,6 +26,7 @@ public class BatchImportPddGoodsAdFeeItemDTO {
private String goodsId; private String goodsId;
@NotNull(message = "广告费金额不能为空") @NotNull(message = "广告费金额不能为空")
@Schema(description = "广告费金额(元)", requiredMode = Schema.RequiredMode.REQUIRED) @Positive(message = "广告费金额须大于0")
@Schema(description = "广告费金额(元),须大于0", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal feeAmount; private BigDecimal feeAmount;
} }
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.adfee.model.dto;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -25,6 +26,7 @@ public class CreatePddGoodsAdFeeDTO {
private LocalDate feeDate; private LocalDate feeDate;
@NotNull(message = "广告费金额不能为空") @NotNull(message = "广告费金额不能为空")
@Schema(description = "广告费金额(元)", requiredMode = Schema.RequiredMode.REQUIRED) @Positive(message = "广告费金额须大于0")
@Schema(description = "广告费金额(元),须大于0", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal feeAmount; private BigDecimal feeAmount;
} }
@@ -3,6 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.adfee.model.dto;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -25,6 +26,7 @@ public class UpdatePddGoodsAdFeeDTO {
private LocalDate feeDate; private LocalDate feeDate;
@NotNull(message = "广告费金额不能为空") @NotNull(message = "广告费金额不能为空")
@Schema(description = "广告费金额(元)", requiredMode = Schema.RequiredMode.REQUIRED) @Positive(message = "广告费金额须大于0")
@Schema(description = "广告费金额(元),须大于0", requiredMode = Schema.RequiredMode.REQUIRED)
private BigDecimal feeAmount; private BigDecimal feeAmount;
} }
@@ -170,8 +170,8 @@ public class PddGoodsAdFeeServiceImpl implements PddGoodsAdFeeService {
if (item.getChannelShopId() == null) { if (item.getChannelShopId() == null) {
throw new BusinessException("渠道店铺ID不能为空"); throw new BusinessException("渠道店铺ID不能为空");
} }
if (item.getFeeAmount() == null || item.getFeeAmount().compareTo(BigDecimal.ZERO) < 0) { if (item.getFeeAmount() == null || item.getFeeAmount().compareTo(BigDecimal.ZERO) <= 0) {
throw new BusinessException("广告费金额不能为空且须大于等于0"); throw new BusinessException("广告费金额须大于0");
} }
if (!StringUtils.hasText(item.getGoodsId())) { if (!StringUtils.hasText(item.getGoodsId())) {
throw new BusinessException("商品ID不能为空"); throw new BusinessException("商品ID不能为空");
@@ -251,8 +251,8 @@ public class PddGoodsAdFeeServiceImpl implements PddGoodsAdFeeService {
} }
private void assertFeeAmount(BigDecimal feeAmount) { private void assertFeeAmount(BigDecimal feeAmount) {
if (feeAmount == null || feeAmount.compareTo(BigDecimal.ZERO) < 0) { if (feeAmount == null || feeAmount.compareTo(BigDecimal.ZERO) <= 0) {
throw new BusinessException("广告费金额不能为空且须大于等于0"); throw new BusinessException("广告费金额不能为空且须大于0");
} }
} }
@@ -26,7 +26,7 @@ public class OpenPddGoodsAdFeeController {
@PostMapping("/batch-import") @PostMapping("/batch-import")
@RequireOpenScope(value = OpenApiScopeConstants.PDD_GOODS_AD_FEE_IMPORT, description = "批量导入拼多多商品广告费") @RequireOpenScope(value = OpenApiScopeConstants.PDD_GOODS_AD_FEE_IMPORT, description = "批量导入拼多多商品广告费")
@Operation(summary = "批量导入拼多多商品广告费", @Operation(summary = "批量导入拼多多商品广告费",
description = "每条需 channelShopId、feeDate、goodsId、feeAmount;同店同商品同日覆盖金额") description = "每条需 channelShopId、feeDate、goodsId、feeAmount(须大于0);同店同商品同日覆盖金额")
public ApiResponse<BatchImportPddGoodsAdFeeResultVO> batchImport( public ApiResponse<BatchImportPddGoodsAdFeeResultVO> batchImport(
@Valid @RequestBody BatchImportPddGoodsAdFeeDTO dto) { @Valid @RequestBody BatchImportPddGoodsAdFeeDTO dto) {
return ApiResponse.success("批量导入完成", pddGoodsAdFeeService.batchImport(dto)); return ApiResponse.success("批量导入完成", pddGoodsAdFeeService.batchImport(dto));
@@ -1,18 +1,18 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"updatedAt": "2026-08-16T14:27:38.290Z", "updatedAt": "2026-08-16T15:10:28.151Z",
"features": [ "features": [
{ {
"id": "pdd-ad-fee", "id": "pdd-ad-fee",
"name": "拼多多商品推广费同步", "name": "拼多多商品推广费同步",
"version": "0.3.9", "version": "0.3.10",
"description": "从推广总览读取推广费并同步到 BI(浮窗滚动条统一 thin)", "description": "从推广总览读取推广费并同步到 BI(总花费为 0 不记录)",
"matchUrlPatterns": [ "matchUrlPatterns": [
"*://yingxiao.pinduoduo.com/*", "*://yingxiao.pinduoduo.com/*",
"https://yingxiao.pinduoduo.com/" "https://yingxiao.pinduoduo.com/"
], ],
"entry": "pdd-ad-fee.js", "entry": "pdd-ad-fee.js",
"sha256": "0ee120f49b6ecbb5c2ed433b087cb2543fad68319183d21c016eb8696e8b417b", "sha256": "a7f3eb7efc7ccff34e3450b3024bfb591bc953a1d2d1bbd3a3146650e9de36c0",
"executionWorld": "main" "executionWorld": "main"
} }
] ]
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -81,6 +81,12 @@ const rules = {
goodsId: [{ required: true, message: '请输入商品ID', trigger: 'blur' }], goodsId: [{ required: true, message: '请输入商品ID', trigger: 'blur' }],
feeAmount: [ feeAmount: [
{ required: true, message: '请输入广告费金额', trigger: 'blur' }, { required: true, message: '请输入广告费金额', trigger: 'blur' },
{
type: 'number',
min: 0.01,
message: '广告费金额须大于0',
trigger: 'blur',
},
], ],
feeDate: [{ required: true, message: '请选择统计日期', trigger: 'change' }], feeDate: [{ required: true, message: '请选择统计日期', trigger: 'change' }],
} as any; } as any;