From bd400647551fc8b4eff45b88ca32ab7f0eece61e Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Wed, 9 Sep 2026 14:53:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E6=8B=BC=E5=A4=9A?= =?UTF-8?q?=E5=A4=9A=E5=95=86=E5=93=81=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/dto/publish/PddGoodsPublishDTO.java | 12 +++++- .../dto/publish/PddGoodsPublishSkuDTO.java | 4 +- .../impl/PddGoodsPublishServiceImpl.java | 1 + .../goods/support/PddGoodsImageTransfer.java | 37 +++++++++++++++++-- .../goods/PddGoodsPublishPopApiClient.java | 4 +- .../api/channel/pdd/goods/types/publish.ts | 2 + .../goods/components/PddGoodsPublishModal.vue | 27 ++++++++++++-- 7 files changed, 77 insertions(+), 10 deletions(-) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishDTO.java index a5b04456..e1a17f28 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishDTO.java @@ -1,6 +1,8 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish; import jakarta.validation.Valid; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; @@ -33,7 +35,7 @@ public class PddGoodsPublishDTO { private Long costTemplateId; /** 参考价,单位分 */ - @NotNull(message = "市场价不能为空") + @NotNull(message = "参考价不能为空") private Long marketPriceFen; /** 承诺发货时间(秒),如 86400 / 172800 */ @@ -52,6 +54,14 @@ public class PddGoodsPublishDTO { @NotNull(message = "是否二手不能为空") private Boolean secondHand; + /** + * 满2件折扣:0-100,0 取消,95=95折;默认 95。 + */ + @NotNull(message = "满两件折扣不能为空") + @Min(value = 0, message = "满两件折扣范围为0-100") + @Max(value = 100, message = "满两件折扣范围为0-100") + private Integer twoPiecesDiscount = 95; + /** 轮播图:本系统 fileId,或已是拼多多 CDN 的 URL */ @NotEmpty(message = "轮播图不能为空") private List carouselImages; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishSkuDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishSkuDTO.java index be5d87ef..79dbf4d8 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishSkuDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddGoodsPublishSkuDTO.java @@ -26,8 +26,8 @@ public class PddGoodsPublishSkuDTO { @NotNull(message = "单买价不能为空") private Long priceFen; - /** 团购价,分 */ - @NotNull(message = "团购价不能为空") + /** 拼单价,分 */ + @NotNull(message = "拼单价不能为空") private Long multiPriceFen; @NotNull(message = "库存不能为空") diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java index a21a5e29..336fc349 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java @@ -322,6 +322,7 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService { dto.getIsPreSale(), dto.getIsRefundable(), dto.getSecondHand(), + dto.getTwoPiecesDiscount() == null ? 95 : dto.getTwoPiecesDiscount(), carousel, detail, primary.getProductCode().trim(), diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/support/PddGoodsImageTransfer.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/support/PddGoodsImageTransfer.java index 7e359b9f..1897a2d3 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/support/PddGoodsImageTransfer.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/support/PddGoodsImageTransfer.java @@ -19,7 +19,9 @@ import java.util.Objects; import java.util.Set; /** - * 本系统 fileId → 读字节 → Base64 → 拼多多商品图上传。 + * 本系统 fileId → 读字节 → 校验魔数 → data URI Base64 → 拼多多商品图上传。 + *

拼多多 image 参数需带 {@code data:image/jpeg;base64,} / {@code data:image/png;base64,} 前缀, + * 仅传裸 Base64 常报「图片格式错误」。 */ @Slf4j @Component @@ -64,8 +66,37 @@ public class PddGoodsImageTransfer { if (bytes.length > MAX_BYTES) { throw new BusinessException("图片超过1MB限制,无法上传到拼多多"); } - String base64 = Base64.getEncoder().encodeToString(bytes); - return publishPopApiClient.uploadImageBase64(mallId, accessToken, base64); + String dataUri = toPddImageDataUri(bytes); + return publishPopApiClient.uploadImageBase64(mallId, accessToken, dataUri); + } + + /** + * 按文件魔数识别 JPEG/PNG,并拼成拼多多要求的 data URI Base64。 + */ + static String toPddImageDataUri(byte[] bytes) { + String mime = detectImageMime(bytes); + if (mime == null) { + throw new BusinessException("图片内容不是合法的 JPG/PNG(扩展名可能与实际格式不符,如 WebP/HEIC)"); + } + return "data:" + mime + ";base64," + Base64.getEncoder().encodeToString(bytes); + } + + /** JPEG: FF D8 …;PNG: 89 50 4E 47 */ + static String detectImageMime(byte[] bytes) { + if (bytes == null || bytes.length < 3) { + return null; + } + if ((bytes[0] & 0xFF) == 0xFF && (bytes[1] & 0xFF) == 0xD8) { + return "image/jpeg"; + } + if (bytes.length >= 8 + && (bytes[0] & 0xFF) == 0x89 + && bytes[1] == 0x50 + && bytes[2] == 0x4E + && bytes[3] == 0x47) { + return "image/png"; + } + return null; } private void assertImageAllowed(SysFileVO file) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/goods/PddGoodsPublishPopApiClient.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/goods/PddGoodsPublishPopApiClient.java index 541278b6..822f20a6 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/goods/PddGoodsPublishPopApiClient.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/goods/PddGoodsPublishPopApiClient.java @@ -134,7 +134,7 @@ public class PddGoodsPublishPopApiClient { }); } - /** 上传商品图(入参已是 base64)。 */ + /** 上传商品图(入参为带 data URI 前缀的 base64,如 data:image/jpeg;base64,...)。 */ public String uploadImageBase64(Long mallId, String accessToken, String imageBase64) throws Exception { if (!StringUtils.hasText(imageBase64)) { throw new BusinessException("图片内容不能为空"); @@ -187,6 +187,7 @@ public class PddGoodsPublishPopApiClient { request.setDetailGallery(cmd.detailGallery()); request.setOutGoodsId(cmd.outGoodsId()); request.setImageUrl(cmd.imageUrl()); + request.setTwoPiecesDiscount(cmd.twoPiecesDiscount() == null ? 95 : cmd.twoPiecesDiscount()); if (cmd.goodsProperties() != null && !cmd.goodsProperties().isEmpty()) { List props = new ArrayList<>(); for (GoodsPropertyItem p : cmd.goodsProperties()) { @@ -498,6 +499,7 @@ public class PddGoodsPublishPopApiClient { Boolean isPreSale, Boolean isRefundable, Boolean secondHand, + Integer twoPiecesDiscount, List carouselGallery, List detailGallery, String outGoodsId, diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish.ts index 5130637d..be33acaf 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish.ts @@ -13,6 +13,8 @@ export namespace PddGoodsPublishDTO { isPreSale: boolean; isRefundable: boolean; secondHand: boolean; + /** 满2件折扣 0-100,默认 95 */ + twoPiecesDiscount: number; /** fileId 字符串或已转传的 URL */ carouselImages: string[]; detailImages: string[]; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue index 73e8fefe..a0fc6186 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue @@ -208,6 +208,7 @@ const form = reactive({ isPreSale: false, isRefundable: true, secondHand: false, + twoPiecesDiscount: 95, goodsPropValues: {} as Record, }); @@ -284,7 +285,7 @@ const skuTableColumns = computed(() => [ })), { title: '商家编码', key: 'code', width: 300 }, { title: '单买价', key: 'price', width: 120 }, - { title: '团购价', key: 'multi', width: 120 }, + { title: '拼单价', key: 'multi', width: 120 }, { title: '库存', key: 'qty', width: 100 }, { title: '重量g', key: 'weight', width: 100 }, { title: '缩略图', key: 'thumb', width: 100 }, @@ -1314,7 +1315,15 @@ function validateForm(): boolean { return false; } if (form.marketPriceYuan == null) { - message.warning('请填写市场价'); + message.warning('请填写参考价'); + return false; + } + if ( + form.twoPiecesDiscount == null || + form.twoPiecesDiscount < 0 || + form.twoPiecesDiscount > 100 + ) { + message.warning('请填写满两件折扣(0-100,95表示95折)'); return false; } for (const p of nonSaleProps.value) { @@ -1489,6 +1498,7 @@ async function buildPublishPayload( isPreSale: form.isPreSale, isRefundable: form.isRefundable, secondHand: form.secondHand, + twoPiecesDiscount: form.twoPiecesDiscount, carouselImages: carouselFileIds.map(String), detailImages: detailFileIds.map(String), goodsProperties, @@ -1550,6 +1560,7 @@ function resetAll() { form.isPreSale = false; form.isRefundable = true; form.secondHand = false; + form.twoPiecesDiscount = 95; clearLocalImages(); form.goodsPropValues = {}; clearSkuRows(); @@ -1785,7 +1796,7 @@ onBeforeUnmount(() => {

- + { ]" /> + + +