From b37cdb0d540a6c01ca8ac1d678ea8c6dbc82c333 Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Wed, 16 Sep 2026 22:21:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8B=BC=E5=A4=9A?= =?UTF-8?q?=E5=A4=9A=E8=8D=89=E7=A8=BF=E7=AE=B1=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel_pdd_goods_publish_desk_design.sql | 86 ++++- ...15c__pdd_publish_draft_platform_commit.sql | 5 + .../PddGoodsPublishDeskController.java | 6 + .../model/po/PddGoodsPublishDraftPO.java | 11 + .../model/vo/PddGoodsPublishDraftVO.java | 3 + .../service/PddGoodsPublishDeskService.java | 3 + .../impl/PddGoodsPublishDeskServiceImpl.java | 73 ++++- .../goods/service/PddGoodsPublishService.java | 9 + .../impl/PddGoodsPublishServiceImpl.java | 298 ++++++++++++------ .../channel/pdd/pop/PddPopApiTypes.java | 2 + .../goods/PddGoodsPublishPopApiClient.java | 217 ++++++++++++- .../service/impl/FeedbackServiceImpl.java | 2 +- .../src/api/channel/pdd/goods/apis.ts | 7 + .../channel/pdd/goods/types/publish-desk.ts | 3 + .../channel/pdd/components/PddShopColPage.vue | 2 +- .../components/PddGoodsPublishEditor.vue | 100 +++++- .../views/channel/pdd/goods/publish/edit.vue | 2 +- .../views/channel/pdd/goods/publish/index.vue | 97 +++++- 18 files changed, 792 insertions(+), 134 deletions(-) create mode 100644 ecom-dmb-backend/sql/migration/V20260915c__pdd_publish_draft_platform_commit.sql diff --git a/ecom-dmb-backend/sql/design/channel/pdd/channel_pdd_goods_publish_desk_design.sql b/ecom-dmb-backend/sql/design/channel/pdd/channel_pdd_goods_publish_desk_design.sql index bf3d753a..1662f8a7 100644 --- a/ecom-dmb-backend/sql/design/channel/pdd/channel_pdd_goods_publish_desk_design.sql +++ b/ecom-dmb-backend/sql/design/channel/pdd/channel_pdd_goods_publish_desk_design.sql @@ -1,2 +1,84 @@ --- 拼多多发布工作台表设计(与 V20260912 migration 一致,供文档查阅) --- channel_pdd_goods_publish_draft / job / job_item +-- 拼多多发布工作台表设计(供文档查阅,与 migration 终态一致) +-- V20260912__channel_pdd_goods_publish_desk.sql 建表 +-- V20260915c__pdd_publish_draft_platform_commit.sql 平台草稿关联字段 +-- +-- 表: +-- channel_pdd_goods_publish_draft 系统草稿(唯一工作区) +-- channel_pdd_goods_publish_job 批量发布任务 +-- channel_pdd_goods_publish_job_item 任务明细 +-- +-- 约定: +-- 1) 系统草稿为主;拼多多草稿箱是导出结果(pdd_goods_commit_id 等) +-- 2) payload_json = { editorState, publishPayload? } +-- 3) 跨店克隆不复制 pdd_goods_commit_id / pdd_goods_id / pdd_draft_pushed_at +-- 4) 正式上架仍走 pdd.goods.add;推平台草稿走 edit/submit.goods.commit +-- ======================================== + +-- ======================================== +-- 系统草稿(发布工作台) +-- ======================================== +CREATE TABLE IF NOT EXISTS `channel_pdd_goods_publish_draft` ( + `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键', + `company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID', + `pdd_shop_id` bigint UNSIGNED NULL COMMENT '渠道店铺ID(可空=未分配)', + `title` varchar(500) NOT NULL DEFAULT '' COMMENT '草稿标题(展示用)', + `cat_id` bigint UNSIGNED NULL COMMENT '叶子类目', + `sku_count` int NOT NULL DEFAULT 0 COMMENT 'SKU 组合数快照', + `status` varchar(32) NOT NULL DEFAULT 'EDITING' COMMENT 'EDITING/NEED_CHECK/READY/PUBLISHING/FAILED/PUBLISHED', + `payload_json` json NULL COMMENT '编辑器状态+可选 publishPayload', + `source_draft_id` bigint UNSIGNED NULL COMMENT '克隆来源草稿', + `last_error` varchar(1000) NULL COMMENT '最近发布/推送失败原因', + `pdd_goods_commit_id` bigint UNSIGNED NULL COMMENT '拼多多草稿 goods_commit_id(最近一次推送)', + `pdd_goods_id` bigint UNSIGNED NULL COMMENT '拼多多商品 goods_id(草稿阶段可能为空)', + `pdd_draft_pushed_at` datetime NULL COMMENT '最近推送到平台草稿箱时间', + `created_by` bigint UNSIGNED NULL COMMENT '创建人', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `idx_pdd_pub_draft_company_shop` (`company_id`, `pdd_shop_id`, `status`), + KEY `idx_pdd_pub_draft_company_status` (`company_id`, `status`), + CONSTRAINT `fk_pdd_pub_draft_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='拼多多商品发布系统草稿'; + +-- ======================================== +-- 批量发布任务 +-- ======================================== +CREATE TABLE IF NOT EXISTS `channel_pdd_goods_publish_job` ( + `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT, + `company_id` bigint UNSIGNED NOT NULL, + `status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT 'PENDING/RUNNING/SUCCESS/PARTIAL/FAILED', + `total_count` int NOT NULL DEFAULT 0, + `success_count` int NOT NULL DEFAULT 0, + `fail_count` int NOT NULL DEFAULT 0, + `message` varchar(1000) NULL, + `created_by` bigint UNSIGNED NULL, + `started_at` datetime NULL, + `finished_at` datetime NULL, + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `idx_pdd_pub_job_company` (`company_id`, `create_time`), + CONSTRAINT `fk_pdd_pub_job_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='拼多多商品批量发布任务'; + +-- ======================================== +-- 批量发布任务明细 +-- ======================================== +CREATE TABLE IF NOT EXISTS `channel_pdd_goods_publish_job_item` ( + `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT, + `job_id` bigint UNSIGNED NOT NULL, + `company_id` bigint UNSIGNED NOT NULL, + `draft_id` bigint UNSIGNED NOT NULL, + `pdd_shop_id` bigint UNSIGNED NULL, + `title` varchar(500) NOT NULL DEFAULT '', + `status` varchar(32) NOT NULL DEFAULT 'PENDING' COMMENT 'PENDING/RUNNING/SUCCESS/FAILED', + `goods_id` varchar(64) NULL COMMENT '发布成功后的拼多多 goodsId', + `error_message` varchar(1000) NULL, + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `idx_pdd_pub_job_item_job` (`job_id`, `status`), + KEY `idx_pdd_pub_job_item_draft` (`draft_id`), + CONSTRAINT `fk_pdd_pub_job_item_job` FOREIGN KEY (`job_id`) REFERENCES `channel_pdd_goods_publish_job` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_pdd_pub_job_item_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='拼多多商品批量发布任务明细'; diff --git a/ecom-dmb-backend/sql/migration/V20260915c__pdd_publish_draft_platform_commit.sql b/ecom-dmb-backend/sql/migration/V20260915c__pdd_publish_draft_platform_commit.sql new file mode 100644 index 00000000..b6a04aef --- /dev/null +++ b/ecom-dmb-backend/sql/migration/V20260915c__pdd_publish_draft_platform_commit.sql @@ -0,0 +1,5 @@ +-- 系统草稿关联拼多多平台草稿(最近一次推送) +ALTER TABLE `channel_pdd_goods_publish_draft` + ADD COLUMN `pdd_goods_commit_id` bigint UNSIGNED NULL COMMENT '拼多多草稿 goods_commit_id' AFTER `last_error`, + ADD COLUMN `pdd_goods_id` bigint UNSIGNED NULL COMMENT '拼多多商品 goods_id(草稿阶段可能为空)' AFTER `pdd_goods_commit_id`, + ADD COLUMN `pdd_draft_pushed_at` datetime NULL COMMENT '最近推送到平台草稿箱时间' AFTER `pdd_goods_id`; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/controller/PddGoodsPublishDeskController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/controller/PddGoodsPublishDeskController.java index cc509485..2eb88a5b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/controller/PddGoodsPublishDeskController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/controller/PddGoodsPublishDeskController.java @@ -76,6 +76,12 @@ public class PddGoodsPublishDeskController { return ApiResponse.success("删除成功", null); } + @PostMapping("/drafts/{id}/push-platform") + @RequirePermission(value = "channel:pdd:goods:create", description = "推送到拼多多草稿箱", allowSuper = true) + public ApiResponse pushPlatformDraft(@PathVariable Long id) { + return ApiResponse.success("已推送到拼多多草稿箱", deskService.pushPlatformDraft(id)); + } + @PostMapping("/drafts/clone") @RequirePermission(value = "channel:pdd:goods:create", description = "一键克隆发布草稿", allowSuper = true) public ApiResponse> cloneDraft(@Valid @RequestBody PddPublishDeskCloneDTO dto) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/model/po/PddGoodsPublishDraftPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/model/po/PddGoodsPublishDraftPO.java index ff5561b6..d188f426 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/model/po/PddGoodsPublishDraftPO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/model/po/PddGoodsPublishDraftPO.java @@ -52,6 +52,17 @@ public class PddGoodsPublishDraftPO { @TableField("last_error") private String lastError; + /** 最近一次推送到拼多多草稿箱的 commitId */ + @TableField("pdd_goods_commit_id") + private Long pddGoodsCommitId; + + /** 平台可能返回的 goodsId;草稿阶段常为空 */ + @TableField("pdd_goods_id") + private Long pddGoodsId; + + @TableField("pdd_draft_pushed_at") + private LocalDateTime pddDraftPushedAt; + @TableField("created_by") private Long createdBy; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/model/vo/PddGoodsPublishDraftVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/model/vo/PddGoodsPublishDraftVO.java index e687bdea..8c0b3bf9 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/model/vo/PddGoodsPublishDraftVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/model/vo/PddGoodsPublishDraftVO.java @@ -20,6 +20,9 @@ public class PddGoodsPublishDraftVO { private String payloadJson; private Long sourceDraftId; private String lastError; + private Long pddGoodsCommitId; + private Long pddGoodsId; + private LocalDateTime pddDraftPushedAt; private Long createdBy; private LocalDateTime createTime; private LocalDateTime updateTime; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/service/PddGoodsPublishDeskService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/service/PddGoodsPublishDeskService.java index 37062b35..0da37b4e 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/service/PddGoodsPublishDeskService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/service/PddGoodsPublishDeskService.java @@ -38,4 +38,7 @@ public interface PddGoodsPublishDeskService { /** 重试任务中失败的明细 */ PddGoodsPublishJobVO retryFailedItems(Long jobId); + + /** 将系统草稿推送到拼多多草稿箱并回写 commitId */ + PddGoodsPublishDraftVO pushPlatformDraft(Long id); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/service/impl/PddGoodsPublishDeskServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/service/impl/PddGoodsPublishDeskServiceImpl.java index 9c483a39..e4a55e9b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/service/impl/PddGoodsPublishDeskServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/publishdesk/service/impl/PddGoodsPublishDeskServiceImpl.java @@ -12,6 +12,9 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import top.xyquan.ecomdmbbackend.common.exception.BusinessException; import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddGoodsPublishDTO; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddGoodsPublishResultVO; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsPublishService; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper.PddGoodsPublishDraftMapper; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper.PddGoodsPublishJobItemMapper; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.mapper.PddGoodsPublishJobMapper; @@ -33,6 +36,7 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.mapper.PddShopMapper; import top.xyquan.ecomdmbbackend.modules.channel.pdd.shop.model.po.PddShopPO; import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -42,7 +46,7 @@ import java.util.Set; import java.util.stream.Collectors; /** - * 发布工作台:草稿持久化、克隆、创建异步发布任务。 + * 发布工作台:系统草稿持久化、克隆、推送平台草稿、批量发布任务。 */ @Service @RequiredArgsConstructor @@ -62,6 +66,7 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic private final PddShopMapper pddShopMapper; private final CurrentUserContext currentUserContext; private final PddGoodsPublishJobRunner jobRunner; + private final PddGoodsPublishService publishService; private final ObjectMapper objectMapper; @Override @@ -325,6 +330,69 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic return getJob(jobId); } + @Override + public PddGoodsPublishDraftVO pushPlatformDraft(Long id) { + PddGoodsPublishDraftPO po = requireDraft(id); + if (po.getPddShopId() == null) { + throw new BusinessException("请先为系统草稿分配渠道店铺"); + } + if (PddGoodsPublishDraftPO.STATUS_PUBLISHING.equals(po.getStatus())) { + throw new BusinessException("发布中的草稿不可推送到平台草稿箱"); + } + PddGoodsPublishDTO payload; + try { + payload = extractPublishPayload(po); + } catch (BusinessException e) { + throw e; + } catch (Exception e) { + throw new BusinessException("草稿发布数据解析失败:" + e.getMessage()); + } + if (payload.getCatId() == null) { + throw new BusinessException("缺少叶子类目,请先在编辑页补全后再推送"); + } + payload.setPddShopId(po.getPddShopId()); + try { + PddGoodsPublishResultVO result = publishService.pushPlatformDraft( + payload, po.getPddGoodsCommitId(), po.getPddGoodsId()); + po.setPddGoodsCommitId(result.getGoodsCommitId()); + po.setPddGoodsId(result.getGoodsId()); + po.setPddDraftPushedAt(LocalDateTime.now()); + po.setLastError(null); + draftMapper.updateById(po); + return toDraftVo(po, loadShopNamesForOne(po)); + } catch (BusinessException e) { + po.setLastError(trimError(e.getMessage())); + draftMapper.updateById(po); + throw e; + } catch (Exception e) { + po.setLastError(trimError(e.getMessage())); + draftMapper.updateById(po); + throw new BusinessException("推送到拼多多草稿箱失败:" + e.getMessage()); + } + } + + private String trimError(String msg) { + if (!StringUtils.hasText(msg)) { + return "推送到拼多多草稿箱失败"; + } + return msg.length() > 1000 ? msg.substring(0, 1000) : msg; + } + + private PddGoodsPublishDTO extractPublishPayload(PddGoodsPublishDraftPO draft) throws Exception { + if (!StringUtils.hasText(draft.getPayloadJson())) { + throw new BusinessException("系统草稿缺少内容,请先在编辑页保存并生成可推送数据"); + } + JsonNode root = objectMapper.readTree(draft.getPayloadJson()); + JsonNode payload = root.get("publishPayload"); + if (payload == null || payload.isNull() || !payload.isObject()) { + throw new BusinessException("尚未生成可推送数据,请先在编辑页点击「推送到拼多多草稿箱」或「保存并标记可发布」"); + } + if (payload instanceof ObjectNode on && draft.getPddShopId() != null) { + on.put("pddShopId", draft.getPddShopId()); + } + return objectMapper.treeToValue(payload, PddGoodsPublishDTO.class); + } + private String rewritePayloadForShop(String payloadJson, Long targetShopId, boolean clearShopBound) { if (!StringUtils.hasText(payloadJson)) { return payloadJson; @@ -417,6 +485,9 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic vo.setPayloadJson(po.getPayloadJson()); vo.setSourceDraftId(po.getSourceDraftId()); vo.setLastError(po.getLastError()); + vo.setPddGoodsCommitId(po.getPddGoodsCommitId()); + vo.setPddGoodsId(po.getPddGoodsId()); + vo.setPddDraftPushedAt(po.getPddDraftPushedAt()); vo.setCreatedBy(po.getCreatedBy()); vo.setCreateTime(po.getCreateTime()); vo.setUpdateTime(po.getUpdateTime()); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsPublishService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsPublishService.java index db88b70a..a8f333a0 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsPublishService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsPublishService.java @@ -43,4 +43,13 @@ public interface PddGoodsPublishService { String transferImage(PddPublishTransferImageDTO dto); PddGoodsPublishResultVO publish(PddGoodsPublishDTO dto); + + /** + * 推送到拼多多草稿箱:图转传 + commit,不入库渠道商品。 + * + * @param existingCommitId 系统草稿上已挂的平台 commitId,可空 + * @param existingGoodsId 已挂的平台 goodsId,可空;与 commitId 同时有效时走覆盖保存 + */ + PddGoodsPublishResultVO pushPlatformDraft( + PddGoodsPublishDTO dto, Long existingCommitId, Long existingGoodsId); } 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 76af10c2..b0ab7a6a 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 @@ -57,7 +57,7 @@ import java.util.Objects; import java.util.stream.Collectors; /** - * 拼多多商品发布:元数据 + 图转传 + add + 按主商品入库。 + * 拼多多商品发布:元数据 + 图转传 + add / 平台草稿。 */ @Slf4j @Service @@ -270,104 +270,9 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService { Long companyId = currentUserContext.getCurrentCompanyId(); ShopAuth ctx = requireShopAuth(dto.getPddShopId()); - ProductPO primary = productMapper.selectById(dto.getPrimaryProductId()); - if (primary == null || !Objects.equals(primary.getCompanyId(), companyId)) { - throw new BusinessException("主内部商品不存在或不属于当前公司"); - } - if (!StringUtils.hasText(primary.getProductCode())) { - throw new BusinessException("主内部商品缺少商品编码,无法写入 out_goods_id"); - } - - List skuIds = dto.getSkus().stream() - .map(PddGoodsPublishSkuDTO::getInternalSkuId) - .filter(Objects::nonNull) - .distinct() - .collect(Collectors.toList()); - Map skuById = new HashMap<>(); - if (!skuIds.isEmpty()) { - List skus = productSkuService.getByIds(skuIds); - if (skus == null || skus.size() != skuIds.size()) { - throw new BusinessException("部分内部SKU不存在"); - } - for (ProductSkuPO sku : skus) { - if (!Objects.equals(sku.getCompanyId(), companyId)) { - throw new BusinessException("内部SKU不属于当前公司 skuId=" + sku.getId()); - } - skuById.put(sku.getId(), sku); - } - } - try { - List carousel = resolveImages(companyId, ctx, dto.getCarouselImages()); - List detail = resolveImages(companyId, ctx, dto.getDetailImages()); - String mainImage = null; - if (StringUtils.hasText(dto.getImageUrl())) { - mainImage = resolveOneImage(companyId, ctx, dto.getImageUrl().trim()); - } - - List skuAdds = new ArrayList<>(); - for (PddGoodsPublishSkuDTO skuDto : dto.getSkus()) { - ProductSkuPO internal = skuDto.getInternalSkuId() == null - ? null - : skuById.get(skuDto.getInternalSkuId()); - String outSkuSn = resolveOutSkuSn(skuDto, internal); - String thumb = resolveOneImage(companyId, ctx, skuDto.getThumbImage()); - List sps = new ArrayList<>(); - if (skuDto.getSkuProperties() != null) { - for (PddGoodsPublishSkuPropertyDTO sp : skuDto.getSkuProperties()) { - if (sp == null) { - continue; - } - sps.add(new PddGoodsPublishPopApiClient.SkuPropertyItem( - sp.getRefPid(), sp.getVid(), sp.getValue(), sp.getPunit())); - } - } - skuAdds.add(new PddGoodsPublishPopApiClient.SkuAddItem( - skuDto.getIsOnsale() == null ? 1 : skuDto.getIsOnsale(), - 999L, - skuDto.getMultiPriceFen(), - skuDto.getPriceFen(), - skuDto.getQuantity(), - skuDto.getWeight(), - thumb, - outSkuSn, - normalizeSpecIdList(skuDto.getSpecIdList()), - sps)); - } - - List goodsProps = new ArrayList<>(); - if (dto.getGoodsProperties() != null) { - for (PddGoodsPublishPropertyDTO p : dto.getGoodsProperties()) { - if (p == null) { - continue; - } - goodsProps.add(new PddGoodsPublishPopApiClient.GoodsPropertyItem( - p.getRefPid(), p.getVid(), p.getValue(), p.getValueUnit(), p.getTemplatePid(), - p.getParentSpecId(), p.getSpecId(), p.getImgUrl(), p.getNote(), p.getGroupId())); - } - } - PddGoodsPublishPopApiClient.GoodsAddCommand command = - new PddGoodsPublishPopApiClient.GoodsAddCommand( - dto.getGoodsName().trim(), - dto.getGoodsDesc(), - dto.getCatId(), - dto.getCostTemplateId(), - 0, - 1, - dto.getMarketPriceFen(), - dto.getShipmentLimitSecond(), - dto.getIsFolt(), - dto.getIsPreSale(), - dto.getIsRefundable(), - dto.getSecondHand(), - dto.getTwoPiecesDiscount() == null ? 95 : dto.getTwoPiecesDiscount(), - carousel, - detail, - primary.getProductCode().trim(), - mainImage, - goodsProps, - skuAdds); + assembleAddCommand(dto, companyId, ctx, true); PddGoodsPublishPopApiClient.GoodsAddResult addResult = publishPopApiClient.addGoods(ctx.mallId(), ctx.accessToken(), command); @@ -378,6 +283,11 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService { throw new BusinessException("发布成功但拉取商品详情为空 goodsId=" + addResult.goodsId()); } + ProductPO primary = productMapper.selectById(dto.getPrimaryProductId()); + if (primary == null || !Objects.equals(primary.getCompanyId(), companyId)) { + throw new BusinessException("主内部商品不存在或不属于当前公司"); + } + // 主商品下补缺失 SKU(外商品已有 sku_code 会跳过,不挪绑) productAutoCreateService.ensureMissingSkus(companyId, primary.getId(), detailInfo); pddGoodsService.upsertFromGoodsDetail( @@ -408,37 +318,215 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService { } } + @Override + public PddGoodsPublishResultVO pushPlatformDraft( + PddGoodsPublishDTO dto, Long existingCommitId, Long existingGoodsId) { + if (dto == null || dto.getCatId() == null) { + throw new BusinessException("叶子类目不能为空"); + } + Long companyId = currentUserContext.getCurrentCompanyId(); + ShopAuth ctx = requireShopAuth(dto.getPddShopId()); + try { + PddGoodsPublishPopApiClient.GoodsAddCommand command = + assembleAddCommand(dto, companyId, ctx, false); + PddGoodsPublishPopApiClient.GoodsAddResult popResult; + if (existingCommitId != null && existingGoodsId != null && existingGoodsId > 0) { + popResult = publishPopApiClient.submitGoodsCommitSave( + ctx.mallId(), ctx.accessToken(), command, existingCommitId, existingGoodsId); + } else { + popResult = publishPopApiClient.editGoodsCommit(ctx.mallId(), ctx.accessToken(), command); + } + PddGoodsPublishResultVO result = new PddGoodsPublishResultVO(); + result.setGoodsCommitId(popResult.goodsCommitId()); + Long goodsId = popResult.goodsId(); + result.setGoodsId(goodsId != null && goodsId > 0 ? goodsId : null); + result.setMatchedSpuId(popResult.matchedSpuId()); + log.info("拼多多草稿推送成功 companyId={} shopId={} commitId={} goodsId={}", + companyId, ctx.shop().getId(), popResult.goodsCommitId(), result.getGoodsId()); + return result; + } catch (BusinessException e) { + throw e; + } catch (Exception e) { + throw wrapPop("推送到拼多多草稿箱失败", e); + } + } + + /** + * 组装 POP 商品命令。strict=true 走发布强校验;false 仅要求能组包,缺图/SKU 交给平台报错。 + */ + private PddGoodsPublishPopApiClient.GoodsAddCommand assembleAddCommand( + PddGoodsPublishDTO dto, Long companyId, ShopAuth ctx, boolean strict) throws Exception { + String outGoodsId = null; + if (dto.getPrimaryProductId() != null) { + ProductPO primary = productMapper.selectById(dto.getPrimaryProductId()); + if (primary == null || !Objects.equals(primary.getCompanyId(), companyId)) { + if (strict) { + throw new BusinessException("主内部商品不存在或不属于当前公司"); + } + } else if (StringUtils.hasText(primary.getProductCode())) { + outGoodsId = primary.getProductCode().trim(); + } else if (strict) { + throw new BusinessException("主内部商品缺少商品编码,无法写入 out_goods_id"); + } + } else if (strict) { + throw new BusinessException("主内部商品不能为空"); + } + + List skuDtos = dto.getSkus() == null ? List.of() : dto.getSkus(); + if (strict && skuDtos.isEmpty()) { + throw new BusinessException("SKU列表不能为空"); + } + + List skuIds = skuDtos.stream() + .map(PddGoodsPublishSkuDTO::getInternalSkuId) + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toList()); + Map skuById = new HashMap<>(); + if (!skuIds.isEmpty()) { + List skus = productSkuService.getByIds(skuIds); + if (strict && (skus == null || skus.size() != skuIds.size())) { + throw new BusinessException("部分内部SKU不存在"); + } + if (skus != null) { + for (ProductSkuPO sku : skus) { + if (!Objects.equals(sku.getCompanyId(), companyId)) { + if (strict) { + throw new BusinessException("内部SKU不属于当前公司 skuId=" + sku.getId()); + } + continue; + } + skuById.put(sku.getId(), sku); + } + } + } + + List carousel = resolveImages(companyId, ctx, dto.getCarouselImages(), strict); + List detail = resolveImages(companyId, ctx, dto.getDetailImages(), strict); + String mainImage = null; + if (StringUtils.hasText(dto.getImageUrl())) { + mainImage = resolveOneImage(companyId, ctx, dto.getImageUrl().trim(), strict); + } + + List skuAdds = new ArrayList<>(); + for (PddGoodsPublishSkuDTO skuDto : skuDtos) { + ProductSkuPO internal = skuDto.getInternalSkuId() == null + ? null + : skuById.get(skuDto.getInternalSkuId()); + String outSkuSn = resolveOutSkuSn(skuDto, internal, strict); + String thumb = resolveOneImage(companyId, ctx, skuDto.getThumbImage(), strict); + List sps = new ArrayList<>(); + if (skuDto.getSkuProperties() != null) { + for (PddGoodsPublishSkuPropertyDTO sp : skuDto.getSkuProperties()) { + if (sp == null) { + continue; + } + sps.add(new PddGoodsPublishPopApiClient.SkuPropertyItem( + sp.getRefPid(), sp.getVid(), sp.getValue(), sp.getPunit())); + } + } + String specIdList = skuDto.getSpecIdList(); + if (StringUtils.hasText(specIdList)) { + specIdList = normalizeSpecIdList(specIdList); + } else if (strict) { + throw new BusinessException("规格列表不能为空"); + } + skuAdds.add(new PddGoodsPublishPopApiClient.SkuAddItem( + skuDto.getIsOnsale() == null ? 1 : skuDto.getIsOnsale(), + 999L, + skuDto.getMultiPriceFen(), + skuDto.getPriceFen(), + skuDto.getQuantity(), + skuDto.getWeight(), + thumb, + outSkuSn, + specIdList, + sps)); + } + + List goodsProps = new ArrayList<>(); + if (dto.getGoodsProperties() != null) { + for (PddGoodsPublishPropertyDTO p : dto.getGoodsProperties()) { + if (p == null) { + continue; + } + goodsProps.add(new PddGoodsPublishPopApiClient.GoodsPropertyItem( + p.getRefPid(), p.getVid(), p.getValue(), p.getValueUnit(), p.getTemplatePid(), + p.getParentSpecId(), p.getSpecId(), p.getImgUrl(), p.getNote(), p.getGroupId())); + } + } + + String goodsName = dto.getGoodsName() == null ? null : dto.getGoodsName().trim(); + if (strict && !StringUtils.hasText(goodsName)) { + throw new BusinessException("商品标题不能为空"); + } + + return new PddGoodsPublishPopApiClient.GoodsAddCommand( + goodsName, + dto.getGoodsDesc(), + dto.getCatId(), + dto.getCostTemplateId(), + 0, + 1, + dto.getMarketPriceFen(), + dto.getShipmentLimitSecond(), + dto.getIsFolt(), + dto.getIsPreSale(), + dto.getIsRefundable(), + dto.getSecondHand(), + dto.getTwoPiecesDiscount() == null ? 95 : dto.getTwoPiecesDiscount(), + carousel, + detail, + outGoodsId, + mainImage, + goodsProps, + skuAdds); + } + /** 优先手填 outSkuSn;否则用内部 sku_code。 */ - private static String resolveOutSkuSn(PddGoodsPublishSkuDTO skuDto, ProductSkuPO internal) { + private static String resolveOutSkuSn(PddGoodsPublishSkuDTO skuDto, ProductSkuPO internal, boolean strict) { if (StringUtils.hasText(skuDto.getOutSkuSn())) { return skuDto.getOutSkuSn().trim(); } if (internal != null && StringUtils.hasText(internal.getSkuCode())) { return internal.getSkuCode().trim(); } - throw new BusinessException("SKU商家编码不能为空:请选择内部SKU或手填编码"); + if (strict) { + throw new BusinessException("SKU商家编码不能为空:请选择内部SKU或手填编码"); + } + return null; } - private List resolveImages(Long companyId, ShopAuth ctx, List refs) throws Exception { + private List resolveImages(Long companyId, ShopAuth ctx, List refs, boolean strict) + throws Exception { if (refs == null || refs.isEmpty()) { - throw new BusinessException("图片列表不能为空"); + if (strict) { + throw new BusinessException("图片列表不能为空"); + } + return List.of(); } List urls = new ArrayList<>(); for (String ref : refs) { if (!StringUtils.hasText(ref)) { continue; } - urls.add(resolveOneImage(companyId, ctx, ref.trim())); + String url = resolveOneImage(companyId, ctx, ref.trim(), strict); + if (StringUtils.hasText(url)) { + urls.add(url); + } } - if (urls.isEmpty()) { + if (urls.isEmpty() && strict) { throw new BusinessException("图片列表不能为空"); } return urls; } - private String resolveOneImage(Long companyId, ShopAuth ctx, String ref) throws Exception { + private String resolveOneImage(Long companyId, ShopAuth ctx, String ref, boolean strict) throws Exception { if (!StringUtils.hasText(ref)) { - throw new BusinessException("图片引用不能为空"); + if (strict) { + throw new BusinessException("图片引用不能为空"); + } + return null; } String s = ref.trim(); if (looksLikeUrl(s)) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/PddPopApiTypes.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/PddPopApiTypes.java index f1268eb1..e2d8879d 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/PddPopApiTypes.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/PddPopApiTypes.java @@ -20,6 +20,8 @@ public final class PddPopApiTypes { public static final String GOODS_DETAIL_GET = "pdd.goods.detail.get"; public static final String GOODS_LIST_GET = "pdd.goods.list.get"; public static final String GOODS_ADD = "pdd.goods.add"; + public static final String GOODS_EDIT_GOODS_COMMIT = "pdd.goods.edit.goods.commit"; + public static final String GOODS_SUBMIT_GOODS_COMMIT = "pdd.goods.submit.goods.commit"; public static final String GOODS_IMAGE_UPLOAD = "pdd.goods.image.upload"; public static final String GOODS_AUTHORIZATION_CATS = "pdd.goods.authorization.cats"; /** 平台全量类目树(无需 accessToken) */ 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 822f20a6..5fb5fd8d 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 @@ -1,6 +1,8 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.goods; import com.pdd.pop.sdk.http.api.pop.request.PddGoodsAddRequest; +import com.pdd.pop.sdk.http.api.pop.request.PddGoodsEditGoodsCommitRequest; +import com.pdd.pop.sdk.http.api.pop.request.PddGoodsSubmitGoodsCommitRequest; import com.pdd.pop.sdk.http.api.pop.request.PddGoodsAuthorizationCatsRequest; import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatTemplateGetRequest; import com.pdd.pop.sdk.http.api.pop.request.PddGoodsImageUploadRequest; @@ -9,6 +11,8 @@ import com.pdd.pop.sdk.http.api.pop.request.PddGoodsSpecGetRequest; import com.pdd.pop.sdk.http.api.pop.request.PddGoodsSpecIdGetRequest; import com.pdd.pop.sdk.http.api.pop.request.PddOneExpressCostTemplateRequest; import com.pdd.pop.sdk.http.api.pop.response.PddGoodsAddResponse; +import com.pdd.pop.sdk.http.api.pop.response.PddGoodsEditGoodsCommitResponse; +import com.pdd.pop.sdk.http.api.pop.response.PddGoodsSubmitGoodsCommitResponse; import com.pdd.pop.sdk.http.api.pop.response.PddGoodsAuthorizationCatsResponse; import com.pdd.pop.sdk.http.api.pop.response.PddGoodsCatTemplateGetResponse; import com.pdd.pop.sdk.http.api.pop.response.PddGoodsImageUploadResponse; @@ -28,7 +32,7 @@ import java.util.Collections; import java.util.List; /** - * 商品发布域 POP:类目/运费模板/属性模板/规格/传图/新增。 + * 商品发布域 POP:类目/运费模板/属性模板/规格/传图/新增/平台草稿。 */ @Slf4j @Component @@ -169,6 +173,46 @@ public class PddGoodsPublishPopApiClient { }); } + /** 新增或编辑拼多多草稿箱(无 commitId)。 */ + public GoodsAddResult editGoodsCommit(Long mallId, String accessToken, GoodsAddCommand command) + throws Exception { + if (command == null) { + throw new BusinessException("草稿参数不能为空"); + } + return invokeSupport.invoke(PddPopApiTypes.GOODS_EDIT_GOODS_COMMIT, mallId, client -> { + PddGoodsEditGoodsCommitRequest request = toEditCommitRequest(command); + PddGoodsEditGoodsCommitResponse response = client.syncInvoke(request, accessToken); + invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_EDIT_GOODS_COMMIT); + var body = response.getGoodsUpdateResponse(); + if (body == null || body.getGoodsCommitId() == null) { + throw new BusinessException("拼多多草稿未返回 goods_commit_id"); + } + return new GoodsAddResult(body.getGoodsId(), body.getGoodsCommitId(), body.getMatchedSpuId()); + }); + } + + /** 覆盖已有平台草稿并仅保存(operate_type=1,不提交上架)。 */ + public GoodsAddResult submitGoodsCommitSave( + Long mallId, String accessToken, GoodsAddCommand command, Long goodsCommitId, Long goodsId) + throws Exception { + if (command == null) { + throw new BusinessException("草稿参数不能为空"); + } + if (goodsCommitId == null || goodsId == null || goodsId <= 0) { + throw new BusinessException("覆盖平台草稿需要有效的 goods_commit_id 与 goods_id"); + } + return invokeSupport.invoke(PddPopApiTypes.GOODS_SUBMIT_GOODS_COMMIT, mallId, client -> { + PddGoodsSubmitGoodsCommitRequest request = toSubmitCommitRequest(command, goodsCommitId, goodsId); + PddGoodsSubmitGoodsCommitResponse response = client.syncInvoke(request, accessToken); + invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_SUBMIT_GOODS_COMMIT); + var body = response.getGoodsUpdateResponse(); + if (body == null || body.getGoodsCommitId() == null) { + throw new BusinessException("拼多多草稿未返回 goods_commit_id"); + } + return new GoodsAddResult(body.getGoodsId(), body.getGoodsCommitId(), body.getMatchedSpuId()); + }); + } + private PddGoodsAddRequest toAddRequest(GoodsAddCommand cmd) { PddGoodsAddRequest request = new PddGoodsAddRequest(); request.setGoodsName(cmd.goodsName()); @@ -237,6 +281,177 @@ public class PddGoodsPublishPopApiClient { return request; } + private PddGoodsEditGoodsCommitRequest toEditCommitRequest(GoodsAddCommand cmd) { + PddGoodsEditGoodsCommitRequest request = new PddGoodsEditGoodsCommitRequest(); + request.setGoodsName(cmd.goodsName()); + request.setGoodsDesc(cmd.goodsDesc()); + request.setCatId(cmd.catId()); + request.setCostTemplateId(cmd.costTemplateId()); + request.setCountryId(cmd.countryId() == null ? 0 : cmd.countryId()); + request.setGoodsType(cmd.goodsType() == null ? 1 : cmd.goodsType()); + request.setMarketPrice(cmd.marketPrice()); + request.setShipmentLimitSecond(cmd.shipmentLimitSecond()); + request.setIsFolt(cmd.isFolt()); + request.setIsPreSale(cmd.isPreSale()); + request.setIsRefundable(cmd.isRefundable()); + request.setSecondHand(cmd.secondHand()); + request.setCarouselGallery(cmd.carouselGallery()); + request.setDetailGallery(cmd.detailGallery()); + request.setOutGoodsId(cmd.outGoodsId()); + request.setImageUrl(cmd.imageUrl()); + if (cmd.twoPiecesDiscount() != null) { + request.setTwoPiecesDiscount(cmd.twoPiecesDiscount()); + } + if (cmd.goodsProperties() != null && !cmd.goodsProperties().isEmpty()) { + List props = new ArrayList<>(); + for (GoodsPropertyItem p : cmd.goodsProperties()) { + PddGoodsEditGoodsCommitRequest.GoodsPropertiesItem item = + new PddGoodsEditGoodsCommitRequest.GoodsPropertiesItem(); + item.setRefPid(p.refPid()); + item.setVid(p.vid()); + item.setValue(p.value()); + item.setValueUnit(p.valueUnit()); + item.setTemplatePid(p.templatePid()); + item.setParentSpecId(p.parentSpecId()); + item.setSpecId(p.specId()); + item.setImgUrl(p.imgUrl()); + item.setNote(p.note()); + item.setGroupId(p.groupId()); + props.add(item); + } + request.setGoodsProperties(props); + } + if (cmd.skuList() != null && !cmd.skuList().isEmpty()) { + List skuList = new ArrayList<>(); + for (SkuAddItem sku : cmd.skuList()) { + PddGoodsEditGoodsCommitRequest.SkuListItem item = + new PddGoodsEditGoodsCommitRequest.SkuListItem(); + item.setIsOnsale(sku.isOnsale() == null ? 1 : sku.isOnsale()); + item.setLimitQuantity(sku.limitQuantity() == null ? 999L : sku.limitQuantity()); + item.setMultiPrice(sku.multiPrice()); + item.setPrice(sku.price()); + item.setQuantity(sku.quantity()); + item.setWeight(sku.weight()); + item.setThumbUrl(sku.thumbUrl()); + item.setOutSkuSn(sku.outSkuSn()); + item.setSpecIdList(sku.specIdList()); + if (sku.skuProperties() != null && !sku.skuProperties().isEmpty()) { + List sps = new ArrayList<>(); + for (SkuPropertyItem sp : sku.skuProperties()) { + PddGoodsEditGoodsCommitRequest.SkuListItemSkuPropertiesItem spi = + new PddGoodsEditGoodsCommitRequest.SkuListItemSkuPropertiesItem(); + spi.setRefPid(sp.refPid()); + spi.setVid(sp.vid()); + spi.setValue(sp.value()); + spi.setPunit(sp.punit()); + sps.add(spi); + } + item.setSkuProperties(sps); + } + skuList.add(item); + } + request.setSkuList(skuList); + } + return request; + } + + private PddGoodsSubmitGoodsCommitRequest toSubmitCommitRequest( + GoodsAddCommand cmd, Long goodsCommitId, Long goodsId) { + PddGoodsSubmitGoodsCommitRequest request = new PddGoodsSubmitGoodsCommitRequest(); + request.setGoodsCommitId(goodsCommitId); + request.setGoodsId(goodsId); + request.setOperateType(1); + request.setGoodsName(cmd.goodsName()); + request.setGoodsDesc(cmd.goodsDesc()); + request.setCatId(cmd.catId()); + request.setCostTemplateId(cmd.costTemplateId()); + request.setCountryId(cmd.countryId() == null ? 0 : cmd.countryId()); + request.setGoodsType(cmd.goodsType() == null ? 1 : cmd.goodsType()); + request.setMarketPrice(cmd.marketPrice()); + request.setShipmentLimitSecond(cmd.shipmentLimitSecond()); + request.setIsFolt(cmd.isFolt()); + request.setIsPreSale(cmd.isPreSale()); + request.setIsRefundable(cmd.isRefundable()); + request.setSecondHand(cmd.secondHand()); + request.setCarouselGallery(cmd.carouselGallery()); + request.setDetailGallery(cmd.detailGallery()); + request.setOutGoodsId(cmd.outGoodsId()); + request.setImageUrl(cmd.imageUrl()); + if (cmd.twoPiecesDiscount() != null) { + request.setTwoPiecesDiscount(cmd.twoPiecesDiscount()); + } + if (cmd.goodsProperties() != null && !cmd.goodsProperties().isEmpty()) { + List props = new ArrayList<>(); + for (GoodsPropertyItem p : cmd.goodsProperties()) { + PddGoodsSubmitGoodsCommitRequest.GoodsPropertiesItem item = + new PddGoodsSubmitGoodsCommitRequest.GoodsPropertiesItem(); + item.setRefPid(p.refPid()); + item.setVid(p.vid()); + item.setValue(p.value()); + item.setValueUnit(p.valueUnit()); + item.setTemplatePid(p.templatePid()); + item.setParentSpecId(p.parentSpecId()); + item.setSpecId(p.specId()); + item.setImgUrl(p.imgUrl()); + item.setNote(p.note()); + item.setGroupId(p.groupId()); + props.add(item); + } + request.setGoodsProperties(props); + } + if (cmd.skuList() != null && !cmd.skuList().isEmpty()) { + List skuList = new ArrayList<>(); + for (SkuAddItem sku : cmd.skuList()) { + PddGoodsSubmitGoodsCommitRequest.SkuListItem item = + new PddGoodsSubmitGoodsCommitRequest.SkuListItem(); + item.setIsOnsale(sku.isOnsale() == null ? 1 : sku.isOnsale()); + item.setLimitQuantity(sku.limitQuantity() == null ? 999L : sku.limitQuantity()); + item.setMultiPrice(sku.multiPrice()); + item.setPrice(sku.price()); + item.setQuantity(sku.quantity()); + item.setWeight(sku.weight()); + item.setThumbUrl(sku.thumbUrl()); + item.setOutSkuSn(sku.outSkuSn()); + item.setSpecIdList(parseSpecIdLongs(sku.specIdList())); + if (sku.skuProperties() != null && !sku.skuProperties().isEmpty()) { + List sps = new ArrayList<>(); + for (SkuPropertyItem sp : sku.skuProperties()) { + PddGoodsSubmitGoodsCommitRequest.SkuListItemSkuPropertiesItem spi = + new PddGoodsSubmitGoodsCommitRequest.SkuListItemSkuPropertiesItem(); + spi.setRefPid(sp.refPid()); + spi.setVid(sp.vid()); + spi.setValue(sp.value()); + spi.setPunit(sp.punit()); + sps.add(spi); + } + item.setSkuProperties(sps); + } + skuList.add(item); + } + request.setSkuList(skuList); + } + return request; + } + + private static List parseSpecIdLongs(String specIdList) { + if (!StringUtils.hasText(specIdList)) { + return null; + } + String s = specIdList.trim(); + if (s.startsWith("[")) { + s = s.substring(1, s.endsWith("]") ? s.length() - 1 : s.length()); + } + List ids = new ArrayList<>(); + for (String part : s.split(",")) { + String p = part.trim(); + if (p.isEmpty()) { + continue; + } + ids.add(Long.parseLong(p)); + } + return ids.isEmpty() ? null : ids; + } + private List mapAuthCats(PddGoodsAuthorizationCatsResponse response) { if (response == null || response.getGoodsAuthCatsGetResponse() == null || response.getGoodsAuthCatsGetResponse().getGoodsCatsList() == null) { diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/feedback/service/impl/FeedbackServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/feedback/service/impl/FeedbackServiceImpl.java index e4ffc372..884a8048 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/feedback/service/impl/FeedbackServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/sys/feedback/service/impl/FeedbackServiceImpl.java @@ -568,7 +568,7 @@ public class FeedbackServiceImpl implements FeedbackService { if (CollectionUtils.isEmpty(fileIds)) { return Collections.emptyMap(); } - List files = sysFileMapper.selectBatchIds(fileIds); + List files = sysFileMapper.selectByIds(fileIds); Map map = new HashMap<>(); for (SysFilePO file : files) { if (file == null || file.getId() == null || file.getDeleteTime() != null) { diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts index 507844b2..359da611 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts @@ -166,6 +166,13 @@ export async function deletePddPublishDeskDraftApi(id: number) { return requestClient.delete(`/channel/pdd/goods/publish-desk/drafts/${id}`); } +/** 将系统草稿推送到拼多多草稿箱 */ +export async function pushPddPublishDeskDraftApi(id: number) { + return requestClient.post( + `/channel/pdd/goods/publish-desk/drafts/${id}/push-platform`, + ); +} + export async function clonePddPublishDeskDraftApi( data: PddPublishDeskDTO.Clone, ) { diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish-desk.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish-desk.ts index 7f50aba4..6ca1f527 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish-desk.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish-desk.ts @@ -49,6 +49,9 @@ export namespace PddPublishDeskVO { payloadJson?: string; sourceDraftId?: number; lastError?: string; + pddGoodsCommitId?: number; + pddGoodsId?: number; + pddDraftPushedAt?: string; createdBy?: number; createTime?: string; updateTime?: string; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/components/PddShopColPage.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/components/PddShopColPage.vue index ac145f15..4c3023bc 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/components/PddShopColPage.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/components/PddShopColPage.vue @@ -23,7 +23,7 @@ withDefaults( resizable?: boolean; splitHandle?: boolean; splitLine?: boolean; - /** 店铺待发草稿数 */ + /** 店铺系统草稿数 */ draftCountByShopId?: Record; showUnassignedFilter?: boolean; unassignedCount?: number; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishEditor.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishEditor.vue index 50e62eaf..742259de 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishEditor.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishEditor.vue @@ -60,6 +60,7 @@ import { listPddPublishLogisticsApi, listPddPublishParentSpecsApi, publishPddGoodsApi, + pushPddPublishDeskDraftApi, updatePddPublishDeskDraftApi, } from '#/api/channel/pdd/goods'; import { @@ -113,6 +114,7 @@ const hasDraft = defineModel('hasDraft', { default: false }); /** 点击遮罩时的去向询问 */ const dismissChoiceVisible = ref(false); const draftSaving = ref(false); +const platformPushing = ref(false); const boundDraftId = ref(null); /** 外层 Modal / 页面壳通过 open 控制;编辑器本身不持有 vben Modal */ @@ -2686,15 +2688,26 @@ async function hydrateFromDraft(id: number) { } } -/** 保存工作台草稿;markReady=true 时写入 publishPayload 供批量发布 */ -async function saveDeskDraft(markReady: boolean) { +/** 保存系统草稿;markReady=true 时写入 publishPayload 供批量发布 */ +async function saveDeskDraft( + markReady: boolean, + extras?: { includePublishPayload?: boolean; silentSuccess?: boolean }, +): Promise<{ id: number; hasPayload: boolean } | null> { if (!form.pddShopId) { message.warning('请先选择渠道店铺'); - return; + return null; } const title = form.goodsName.trim() || '未命名草稿'; + const includePayload = markReady || extras?.includePublishPayload === true; draftSaving.value = true; - const hide = message.loading(markReady ? '生成可发布数据…' : '保存草稿…', 0); + const hide = message.loading( + markReady + ? '生成可发布数据…' + : includePayload + ? '保存系统草稿…' + : '保存系统草稿…', + 0, + ); try { // 普通保存也上传图片,否则下次打开无法回填(未上传的合并一次签名) const pendingThumbs = skuRows.value @@ -2722,19 +2735,26 @@ async function saveDeskDraft(markReady: boolean) { }); let publishPayload: PddGoodsPublishDTO.Publish | undefined; - if (markReady) { - if (!validateForm()) { - return; + if (includePayload) { + if (markReady && !validateForm()) { + return null; } const thumbFileIdBySkuKey = new Map(); for (const [k, v] of thumbBySkuKey) { thumbFileIdBySkuKey.set(k, v.fileId); } - publishPayload = await buildPublishPayload( - carouselFiles.map((f) => f.fileId), - detailFiles.map((f) => f.fileId), - thumbFileIdBySkuKey, - ); + try { + publishPayload = await buildPublishPayload( + carouselFiles.map((f) => f.fileId), + detailFiles.map((f) => f.fileId), + thumbFileIdBySkuKey, + ); + } catch (e: any) { + if (markReady) { + throw e; + } + // 推送场景:先落系统草稿,调用方再提示无法推送 + } } const payloadJson = JSON.stringify({ @@ -2801,15 +2821,58 @@ async function saveDeskDraft(markReady: boolean) { : await createPddPublishDeskDraftApi(body); boundDraftId.value = saved.id; emit('draft-saved', saved.id); - message.success(markReady ? '已保存为可发布草稿' : '草稿已保存'); + if (!extras?.silentSuccess) { + message.success(markReady ? '已保存为可发布草稿' : '系统草稿已保存'); + } + return { id: saved.id, hasPayload: !!publishPayload }; } catch (e: any) { - message.error(e?.message || '保存草稿失败'); + message.error(e?.message || '保存系统草稿失败'); + return null; } finally { hide(); draftSaving.value = false; } } +/** 先落系统草稿(尽量带 publishPayload),再推送到拼多多草稿箱 */ +async function pushToPlatformDraft() { + if (!form.pddShopId) { + message.warning('请先选择渠道店铺'); + return; + } + if (!form.catId) { + message.warning('请先选择叶子类目'); + return; + } + platformPushing.value = true; + try { + const saved = await saveDeskDraft(false, { + includePublishPayload: true, + silentSuccess: true, + }); + if (!saved) return; + if (!saved.hasPayload) { + message.error('未能生成可推送数据,请补全规格、价格与图片后再试'); + return; + } + const hide = message.loading('推送到拼多多草稿箱…', 0); + try { + const vo = await pushPddPublishDeskDraftApi(saved.id); + message.success( + vo.pddGoodsCommitId + ? `已推送到拼多多草稿箱(ID ${vo.pddGoodsCommitId})` + : '已推送到拼多多草稿箱', + ); + } finally { + hide(); + } + } catch (e: any) { + message.error(e?.message || '推送到拼多多草稿箱失败'); + } finally { + platformPushing.value = false; + } +} + async function handleSubmit() { if (!validateForm()) return; submitting.value = true; @@ -3718,7 +3781,7 @@ onBeforeUnmount(() => { {{ variant === 'page' ? '返回' : '取消' }} +