mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 拼多多商品发布(goods.add)及发布后详情入库绑定主商品
This commit is contained in:
+95
@@ -0,0 +1,95 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.controller;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddGoodsPublishDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishCostTemplateDetailQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishCatTemplateQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishLogisticsQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishShopCatQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishSpecIdCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishSpecQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishTransferImageDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddGoodsPublishResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCostTemplateDetailVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCatTemplateVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCatVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishLogisticsPageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishParentSpecVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishSpecIdVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsPublishService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 拼多多商品发布(上行 add + 详情入库),权限复用 create。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/channel/pdd/goods/publish")
|
||||
public class PddGoodsPublishController {
|
||||
|
||||
private final PddGoodsPublishService publishService;
|
||||
|
||||
public PddGoodsPublishController(PddGoodsPublishService publishService) {
|
||||
this.publishService = publishService;
|
||||
}
|
||||
|
||||
@PostMapping("/meta/cats")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<List<PddPublishCatVO>> listAuthCats(@Valid @RequestBody PddPublishShopCatQueryDTO query) {
|
||||
return ApiResponse.success("获取成功", publishService.listAuthCats(query));
|
||||
}
|
||||
|
||||
@PostMapping("/meta/logistics-templates")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<PddPublishLogisticsPageVO> listLogistics(
|
||||
@Valid @RequestBody PddPublishLogisticsQueryDTO query) {
|
||||
return ApiResponse.success("获取成功", publishService.listLogisticsTemplates(query));
|
||||
}
|
||||
|
||||
@PostMapping("/meta/logistics-template-detail")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<PddPublishCostTemplateDetailVO> getLogisticsTemplateDetail(
|
||||
@Valid @RequestBody PddPublishCostTemplateDetailQueryDTO query) {
|
||||
return ApiResponse.success("获取成功", publishService.getCostTemplateDetail(query));
|
||||
}
|
||||
|
||||
@PostMapping("/meta/cat-template")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<PddPublishCatTemplateVO> getCatTemplate(
|
||||
@Valid @RequestBody PddPublishCatTemplateQueryDTO query) {
|
||||
return ApiResponse.success("获取成功", publishService.getCatTemplate(query));
|
||||
}
|
||||
|
||||
@PostMapping("/meta/specs")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<List<PddPublishParentSpecVO>> listParentSpecs(
|
||||
@Valid @RequestBody PddPublishSpecQueryDTO query) {
|
||||
return ApiResponse.success("获取成功", publishService.listParentSpecs(query));
|
||||
}
|
||||
|
||||
@PostMapping("/meta/spec-id")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<PddPublishSpecIdVO> createSpecId(@Valid @RequestBody PddPublishSpecIdCreateDTO dto) {
|
||||
return ApiResponse.success("生成成功", publishService.createSpecId(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/transfer-image")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<Map<String, String>> transferImage(@Valid @RequestBody PddPublishTransferImageDTO dto) {
|
||||
String url = publishService.transferImage(dto);
|
||||
return ApiResponse.success("转传成功", Map.of("imageUrl", url));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<PddGoodsPublishResultVO> publish(@Valid @RequestBody PddGoodsPublishDTO dto) {
|
||||
return ApiResponse.success("发布成功", publishService.publish(dto));
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 拼多多商品发布入参(上行 add,非本地镜像 CreatePddGoodsDTO)。
|
||||
*/
|
||||
@Data
|
||||
public class PddGoodsPublishDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
/** 渠道商品绑定的主内部商品 */
|
||||
@NotNull(message = "主内部商品不能为空")
|
||||
private Long primaryProductId;
|
||||
|
||||
@NotBlank(message = "商品标题不能为空")
|
||||
private String goodsName;
|
||||
|
||||
private String goodsDesc;
|
||||
|
||||
@NotNull(message = "叶子类目不能为空")
|
||||
private Long catId;
|
||||
|
||||
@NotNull(message = "运费模板不能为空")
|
||||
private Long costTemplateId;
|
||||
|
||||
/** 参考价,单位分 */
|
||||
@NotNull(message = "市场价不能为空")
|
||||
private Long marketPriceFen;
|
||||
|
||||
/** 承诺发货时间(秒),如 86400 / 172800 */
|
||||
@NotNull(message = "发货时限不能为空")
|
||||
private Long shipmentLimitSecond;
|
||||
|
||||
@NotNull(message = "假一赔十不能为空")
|
||||
private Boolean isFolt;
|
||||
|
||||
@NotNull(message = "是否预售不能为空")
|
||||
private Boolean isPreSale;
|
||||
|
||||
@NotNull(message = "7天无理由不能为空")
|
||||
private Boolean isRefundable;
|
||||
|
||||
@NotNull(message = "是否二手不能为空")
|
||||
private Boolean secondHand;
|
||||
|
||||
/** 轮播图:本系统 fileId,或已是拼多多 CDN 的 URL */
|
||||
@NotEmpty(message = "轮播图不能为空")
|
||||
private List<String> carouselImages;
|
||||
|
||||
/** 详情图 */
|
||||
@NotEmpty(message = "详情图不能为空")
|
||||
private List<String> detailImages;
|
||||
|
||||
/** 活动主图(可选):fileId 或 URL */
|
||||
private String imageUrl;
|
||||
|
||||
/** 商品属性(类目模板非销售属性) */
|
||||
private List<@Valid PddGoodsPublishPropertyDTO> goodsProperties;
|
||||
|
||||
@NotEmpty(message = "SKU列表不能为空")
|
||||
@Valid
|
||||
private List<PddGoodsPublishSkuDTO> skus;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 商品级属性(对应 goods_properties)。
|
||||
*/
|
||||
@Data
|
||||
public class PddGoodsPublishPropertyDTO {
|
||||
|
||||
private Long refPid;
|
||||
private Long vid;
|
||||
private String value;
|
||||
private String valueUnit;
|
||||
private Long templatePid;
|
||||
private Long parentSpecId;
|
||||
private Long specId;
|
||||
private String imgUrl;
|
||||
private String note;
|
||||
private Integer groupId;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 发布 SKU:可选绑定内部 SKU,或手填商家编码 outSkuSn。
|
||||
*/
|
||||
@Data
|
||||
public class PddGoodsPublishSkuDTO {
|
||||
|
||||
/** 可选:选择内部 SKU 时带出编码;手填时可空 */
|
||||
private Long internalSkuId;
|
||||
|
||||
/**
|
||||
* 商家 SKU 编码(out_sku_sn)。
|
||||
* 未选内部 SKU 时必填;已选内部 SKU 时可覆盖,默认用内部 sku_code。
|
||||
*/
|
||||
private String outSkuSn;
|
||||
|
||||
/** 单买价,分 */
|
||||
@NotNull(message = "单买价不能为空")
|
||||
private Long priceFen;
|
||||
|
||||
/** 团购价,分 */
|
||||
@NotNull(message = "团购价不能为空")
|
||||
private Long multiPriceFen;
|
||||
|
||||
@NotNull(message = "库存不能为空")
|
||||
private Long quantity;
|
||||
|
||||
/** 重量,克 */
|
||||
@NotNull(message = "重量不能为空")
|
||||
private Long weight;
|
||||
|
||||
/** 缩略图:fileId 或 URL */
|
||||
@NotBlank(message = "SKU缩略图不能为空")
|
||||
private String thumbImage;
|
||||
|
||||
/** 规格 ID 列表 JSON,如 [20,5] */
|
||||
@NotBlank(message = "规格列表不能为空")
|
||||
private String specIdList;
|
||||
|
||||
private Integer isOnsale = 1;
|
||||
|
||||
@Valid
|
||||
private List<PddGoodsPublishSkuPropertyDTO> skuProperties;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* SKU 销售属性(对应 sku_properties)。
|
||||
*/
|
||||
@Data
|
||||
public class PddGoodsPublishSkuPropertyDTO {
|
||||
|
||||
@NotNull(message = "sku属性refPid不能为空")
|
||||
private Long refPid;
|
||||
|
||||
@NotNull(message = "sku属性vid不能为空")
|
||||
private Long vid;
|
||||
|
||||
private String value;
|
||||
|
||||
private String punit;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishCatTemplateQueryDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
@NotNull(message = "类目ID不能为空")
|
||||
private Long catId;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishCostTemplateDetailQueryDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
@NotNull(message = "运费模板ID不能为空")
|
||||
private Long costTemplateId;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishLogisticsQueryDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
private Integer page = 1;
|
||||
|
||||
private Integer pageSize = 50;
|
||||
|
||||
/** 0 新发布(默认) */
|
||||
private Integer goodsStatus = 0;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishShopCatQueryDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
/** 默认 0 顶级 */
|
||||
private Long parentCatId = 0L;
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishSpecIdCreateDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
@NotNull(message = "父规格ID不能为空")
|
||||
private Long parentSpecId;
|
||||
|
||||
@NotBlank(message = "规格值不能为空")
|
||||
private String specName;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishSpecQueryDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
@NotNull(message = "叶子类目ID不能为空")
|
||||
private Long catId;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishTransferImageDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long pddShopId;
|
||||
|
||||
@NotNull(message = "文件ID不能为空")
|
||||
private Long fileId;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsVO;
|
||||
|
||||
/**
|
||||
* 发布成功结果:渠道商品 + 平台返回序列号。
|
||||
*/
|
||||
@Data
|
||||
public class PddGoodsPublishResultVO {
|
||||
|
||||
private Long goodsId;
|
||||
private Long goodsCommitId;
|
||||
private Long matchedSpuId;
|
||||
private PddGoodsVO goods;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PddPublishCatPropertyVO {
|
||||
|
||||
private Long templatePid;
|
||||
private String name;
|
||||
private String nameAlias;
|
||||
private Long refPid;
|
||||
private Long specId;
|
||||
private Long parentId;
|
||||
private Boolean required;
|
||||
private Boolean sale;
|
||||
private Integer controlType;
|
||||
private Integer feature;
|
||||
private Integer valueType;
|
||||
private String valueUnit;
|
||||
private Integer inputMaxNum;
|
||||
private Integer chooseMaxNum;
|
||||
private List<PddPublishCatPropertyValueVO> values;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PddPublishCatPropertyValueVO {
|
||||
|
||||
private Long vid;
|
||||
private String value;
|
||||
private Long specId;
|
||||
private String extendInfo;
|
||||
private Boolean parent;
|
||||
private List<Long> parentVids;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PddPublishCatTemplateVO {
|
||||
|
||||
private Long id;
|
||||
private Long maxSkuNum;
|
||||
private Long inputMaxSpecNum;
|
||||
private Long singleSpecValueNum;
|
||||
private Boolean singleItem;
|
||||
private List<PddPublishCatPropertyVO> properties;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 可发布类目节点。
|
||||
*/
|
||||
@Data
|
||||
public class PddPublishCatVO {
|
||||
|
||||
private Long catId;
|
||||
private String catName;
|
||||
private Boolean leaf;
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 运费模板详情(发布页预览用)。
|
||||
*/
|
||||
@Data
|
||||
public class PddPublishCostTemplateDetailVO {
|
||||
|
||||
private Long templateId;
|
||||
private String templateName;
|
||||
/** 0 按件 / 1 按重 */
|
||||
private Integer costType;
|
||||
private String costTypeLabel;
|
||||
private Integer shipProvinceId;
|
||||
private Integer shipCityId;
|
||||
private Integer shipDistrictId;
|
||||
/** 0 不支持 / 1 送货入户 / 2 送货入户并安装 */
|
||||
private Integer additionalServiceType;
|
||||
private String additionalServiceLabel;
|
||||
/** 是否顺丰包邮(平台字段原值) */
|
||||
private Integer sfFreeType;
|
||||
private Boolean sfFree;
|
||||
private Boolean freeDeliverHouse;
|
||||
private List<ProvinceItem> freeProvinces;
|
||||
private List<PaidRegionItem> paidRegions;
|
||||
private List<DeliverHouseAreaItem> freeDeliverHouseAreas;
|
||||
|
||||
@Data
|
||||
public static class ProvinceItem {
|
||||
private Long provinceId;
|
||||
private String province;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PaidRegionItem {
|
||||
private List<ProvinceItem> provinces;
|
||||
private String provincesText;
|
||||
private Long firstStandard;
|
||||
private Long firstCostFen;
|
||||
private String firstCostYuan;
|
||||
private Long addStandard;
|
||||
private Long addCostFen;
|
||||
private String addCostYuan;
|
||||
private Boolean freeByCountEnabled;
|
||||
private Long freeMinCount;
|
||||
private Boolean freeByAmountEnabled;
|
||||
private Long freeMinAmountFen;
|
||||
private String freeMinAmountYuan;
|
||||
private String freeRuleText;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DeliverHouseAreaItem {
|
||||
private String province;
|
||||
private String city;
|
||||
private String town;
|
||||
private String areaText;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PddPublishLogisticsPageVO {
|
||||
|
||||
private Integer totalCount;
|
||||
private List<PddPublishLogisticsTemplateVO> templates;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishLogisticsTemplateVO {
|
||||
|
||||
private Long templateId;
|
||||
private String templateName;
|
||||
private Integer costType;
|
||||
private Integer lastUpdatedTime;
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishParentSpecVO {
|
||||
|
||||
private Long catId;
|
||||
private Long parentSpecId;
|
||||
private String parentSpecName;
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PddPublishSpecIdVO {
|
||||
|
||||
private Long parentSpecId;
|
||||
private String specName;
|
||||
private Long specId;
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service;
|
||||
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddGoodsPublishDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishCatTemplateQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishCostTemplateDetailQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishLogisticsQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishShopCatQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishSpecIdCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishSpecQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishTransferImageDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddGoodsPublishResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCatTemplateVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCatVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCostTemplateDetailVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishLogisticsPageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishParentSpecVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishSpecIdVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 拼多多商品发布编排:元数据查询、图片转传、add + 详情入库。
|
||||
*/
|
||||
public interface PddGoodsPublishService {
|
||||
|
||||
List<PddPublishCatVO> listAuthCats(PddPublishShopCatQueryDTO query);
|
||||
|
||||
PddPublishLogisticsPageVO listLogisticsTemplates(PddPublishLogisticsQueryDTO query);
|
||||
|
||||
PddPublishCostTemplateDetailVO getCostTemplateDetail(PddPublishCostTemplateDetailQueryDTO query);
|
||||
|
||||
PddPublishCatTemplateVO getCatTemplate(PddPublishCatTemplateQueryDTO query);
|
||||
|
||||
List<PddPublishParentSpecVO> listParentSpecs(PddPublishSpecQueryDTO query);
|
||||
|
||||
PddPublishSpecIdVO createSpecId(PddPublishSpecIdCreateDTO dto);
|
||||
|
||||
String transferImage(PddPublishTransferImageDTO dto);
|
||||
|
||||
PddGoodsPublishResultVO publish(PddGoodsPublishDTO dto);
|
||||
}
|
||||
+641
@@ -0,0 +1,641 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.po.PddAuthPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.service.PddAuthTokenService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.mapper.PddGoodsMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddGoodsPublishDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddGoodsPublishPropertyDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddGoodsPublishSkuDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddGoodsPublishSkuPropertyDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishCostTemplateDetailQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishCatTemplateQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishLogisticsQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishShopCatQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishSpecIdCreateDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishSpecQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.PddPublishTransferImageDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.po.PddGoodsPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddGoodsPublishResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCatPropertyVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCatPropertyValueVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCostTemplateDetailVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCatTemplateVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishCatVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishLogisticsPageVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishLogisticsTemplateVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishParentSpecVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish.PddPublishSpecIdVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsPublishService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.support.PddGoodsImageTransfer;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.order.convert.service.PddProductAutoCreateService;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.PddAuthFailureException;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.goods.PddGoodsPopApiClient;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.goods.PddGoodsPublishPopApiClient;
|
||||
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.modules.ec.product.mapper.ProductMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.po.ProductPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.model.po.ProductSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.sku.service.ProductSkuService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 拼多多商品发布:元数据 + 图转传 + add + 按主商品入库。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
|
||||
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final PddShopMapper pddShopMapper;
|
||||
private final PddAuthTokenService authTokenService;
|
||||
private final PddGoodsPublishPopApiClient publishPopApiClient;
|
||||
private final PddGoodsPopApiClient goodsPopApiClient;
|
||||
private final PddGoodsImageTransfer imageTransfer;
|
||||
private final ProductMapper productMapper;
|
||||
private final ProductSkuService productSkuService;
|
||||
private final PddGoodsService pddGoodsService;
|
||||
private final PddGoodsMapper pddGoodsMapper;
|
||||
private final PddProductAutoCreateService productAutoCreateService;
|
||||
|
||||
public PddGoodsPublishServiceImpl(CurrentUserContext currentUserContext,
|
||||
PddShopMapper pddShopMapper,
|
||||
PddAuthTokenService authTokenService,
|
||||
PddGoodsPublishPopApiClient publishPopApiClient,
|
||||
PddGoodsPopApiClient goodsPopApiClient,
|
||||
PddGoodsImageTransfer imageTransfer,
|
||||
ProductMapper productMapper,
|
||||
ProductSkuService productSkuService,
|
||||
PddGoodsService pddGoodsService,
|
||||
PddGoodsMapper pddGoodsMapper,
|
||||
PddProductAutoCreateService productAutoCreateService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.pddShopMapper = pddShopMapper;
|
||||
this.authTokenService = authTokenService;
|
||||
this.publishPopApiClient = publishPopApiClient;
|
||||
this.goodsPopApiClient = goodsPopApiClient;
|
||||
this.imageTransfer = imageTransfer;
|
||||
this.productMapper = productMapper;
|
||||
this.productSkuService = productSkuService;
|
||||
this.pddGoodsService = pddGoodsService;
|
||||
this.pddGoodsMapper = pddGoodsMapper;
|
||||
this.productAutoCreateService = productAutoCreateService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PddPublishCatVO> listAuthCats(PddPublishShopCatQueryDTO query) {
|
||||
ShopAuth ctx = requireShopAuth(query.getPddShopId());
|
||||
try {
|
||||
List<PddGoodsPublishPopApiClient.AuthCatItem> items = publishPopApiClient.listAuthorizationCats(
|
||||
ctx.mallId(), ctx.accessToken(), query.getParentCatId());
|
||||
return items.stream().map(i -> {
|
||||
PddPublishCatVO vo = new PddPublishCatVO();
|
||||
vo.setCatId(i.catId());
|
||||
vo.setCatName(i.catName());
|
||||
vo.setLeaf(i.leaf());
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("查询可发布类目失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PddPublishLogisticsPageVO listLogisticsTemplates(PddPublishLogisticsQueryDTO query) {
|
||||
ShopAuth ctx = requireShopAuth(query.getPddShopId());
|
||||
try {
|
||||
var page = publishPopApiClient.listLogisticsTemplates(
|
||||
ctx.mallId(), ctx.accessToken(),
|
||||
query.getPage() == null ? 1 : query.getPage(),
|
||||
query.getPageSize() == null ? 50 : query.getPageSize(),
|
||||
query.getGoodsStatus());
|
||||
PddPublishLogisticsPageVO vo = new PddPublishLogisticsPageVO();
|
||||
vo.setTotalCount(page.totalCount());
|
||||
List<PddPublishLogisticsTemplateVO> list = new ArrayList<>();
|
||||
for (var t : page.templates()) {
|
||||
PddPublishLogisticsTemplateVO item = new PddPublishLogisticsTemplateVO();
|
||||
item.setTemplateId(t.templateId());
|
||||
item.setTemplateName(t.templateName());
|
||||
item.setCostType(t.costType());
|
||||
item.setLastUpdatedTime(t.lastUpdatedTime());
|
||||
list.add(item);
|
||||
}
|
||||
vo.setTemplates(list);
|
||||
return vo;
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("查询运费模板失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PddPublishCostTemplateDetailVO getCostTemplateDetail(PddPublishCostTemplateDetailQueryDTO query) {
|
||||
ShopAuth ctx = requireShopAuth(query.getPddShopId());
|
||||
try {
|
||||
var detail = publishPopApiClient.fetchCostTemplateDetail(
|
||||
ctx.mallId(), ctx.accessToken(), query.getCostTemplateId());
|
||||
return mapCostTemplateDetail(detail);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("查询运费模板详情失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PddPublishCatTemplateVO getCatTemplate(PddPublishCatTemplateQueryDTO query) {
|
||||
ShopAuth ctx = requireShopAuth(query.getPddShopId());
|
||||
try {
|
||||
var tpl = publishPopApiClient.getCatTemplate(ctx.mallId(), ctx.accessToken(), query.getCatId());
|
||||
return mapCatTemplate(tpl);
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("查询类目属性模板失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PddPublishParentSpecVO> listParentSpecs(PddPublishSpecQueryDTO query) {
|
||||
ShopAuth ctx = requireShopAuth(query.getPddShopId());
|
||||
try {
|
||||
return publishPopApiClient.listParentSpecs(ctx.mallId(), ctx.accessToken(), query.getCatId())
|
||||
.stream()
|
||||
.map(s -> {
|
||||
PddPublishParentSpecVO vo = new PddPublishParentSpecVO();
|
||||
vo.setCatId(s.catId());
|
||||
vo.setParentSpecId(s.parentSpecId());
|
||||
vo.setParentSpecName(s.parentSpecName());
|
||||
return vo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("查询父规格失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PddPublishSpecIdVO createSpecId(PddPublishSpecIdCreateDTO dto) {
|
||||
ShopAuth ctx = requireShopAuth(dto.getPddShopId());
|
||||
try {
|
||||
var r = publishPopApiClient.createSpecId(
|
||||
ctx.mallId(), ctx.accessToken(), dto.getParentSpecId(), dto.getSpecName());
|
||||
PddPublishSpecIdVO vo = new PddPublishSpecIdVO();
|
||||
vo.setParentSpecId(r.parentSpecId());
|
||||
vo.setSpecName(r.specName());
|
||||
vo.setSpecId(r.specId());
|
||||
return vo;
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("生成规格ID失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String transferImage(PddPublishTransferImageDTO dto) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ShopAuth ctx = requireShopAuth(dto.getPddShopId());
|
||||
try {
|
||||
return imageTransfer.transfer(companyId, ctx.mallId(), ctx.accessToken(), dto.getFileId());
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("图片转传拼多多失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public PddGoodsPublishResultVO publish(PddGoodsPublishDTO dto) {
|
||||
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<Long> skuIds = dto.getSkus().stream()
|
||||
.map(PddGoodsPublishSkuDTO::getInternalSkuId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
Map<Long, ProductSkuPO> skuById = new HashMap<>();
|
||||
if (!skuIds.isEmpty()) {
|
||||
List<ProductSkuPO> 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<String> carousel = resolveImages(companyId, ctx, dto.getCarouselImages());
|
||||
List<String> detail = resolveImages(companyId, ctx, dto.getDetailImages());
|
||||
String mainImage = null;
|
||||
if (StringUtils.hasText(dto.getImageUrl())) {
|
||||
mainImage = resolveOneImage(companyId, ctx, dto.getImageUrl().trim());
|
||||
}
|
||||
|
||||
List<PddGoodsPublishPopApiClient.SkuAddItem> 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<PddGoodsPublishPopApiClient.SkuPropertyItem> 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<PddGoodsPublishPopApiClient.GoodsPropertyItem> 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(),
|
||||
carousel,
|
||||
detail,
|
||||
primary.getProductCode().trim(),
|
||||
mainImage,
|
||||
goodsProps,
|
||||
skuAdds);
|
||||
|
||||
PddGoodsPublishPopApiClient.GoodsAddResult addResult =
|
||||
publishPopApiClient.addGoods(ctx.mallId(), ctx.accessToken(), command);
|
||||
|
||||
PddGoodsPopApiClient.GoodsDetail detailInfo = goodsPopApiClient.fetchGoodsInformation(
|
||||
ctx.mallId(), ctx.accessToken(), addResult.goodsId());
|
||||
if (detailInfo == null || detailInfo.goodsId() == null) {
|
||||
throw new BusinessException("发布成功但拉取商品详情为空 goodsId=" + addResult.goodsId());
|
||||
}
|
||||
|
||||
// 主商品下补缺失 SKU(外商品已有 sku_code 会跳过,不挪绑)
|
||||
productAutoCreateService.ensureMissingSkus(companyId, primary.getId(), detailInfo);
|
||||
pddGoodsService.upsertFromGoodsDetail(
|
||||
companyId, ctx.shop().getId(), ctx.mallId(), primary.getId(), detailInfo);
|
||||
|
||||
PddGoodsPO local = pddGoodsMapper.selectOne(new LambdaQueryWrapper<PddGoodsPO>()
|
||||
.eq(PddGoodsPO::getCompanyId, companyId)
|
||||
.eq(PddGoodsPO::getShopId, ctx.shop().getId())
|
||||
.eq(PddGoodsPO::getGoodsId, String.valueOf(addResult.goodsId()))
|
||||
.last("LIMIT 1"));
|
||||
if (local == null || local.getId() == null) {
|
||||
throw new BusinessException("渠道商品入库失败 goodsId=" + addResult.goodsId());
|
||||
}
|
||||
PddGoodsVO goodsVo = pddGoodsService.getPddGoodsDetail(local.getId());
|
||||
|
||||
PddGoodsPublishResultVO result = new PddGoodsPublishResultVO();
|
||||
result.setGoodsId(addResult.goodsId());
|
||||
result.setGoodsCommitId(addResult.goodsCommitId());
|
||||
result.setMatchedSpuId(addResult.matchedSpuId());
|
||||
result.setGoods(goodsVo);
|
||||
log.info("拼多多商品发布成功 companyId={} shopId={} goodsId={} primaryProductId={}",
|
||||
companyId, ctx.shop().getId(), addResult.goodsId(), primary.getId());
|
||||
return result;
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw wrapPop("发布拼多多商品失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/** 优先手填 outSkuSn;否则用内部 sku_code。 */
|
||||
private static String resolveOutSkuSn(PddGoodsPublishSkuDTO skuDto, ProductSkuPO internal) {
|
||||
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或手填编码");
|
||||
}
|
||||
|
||||
private List<String> resolveImages(Long companyId, ShopAuth ctx, List<String> refs) throws Exception {
|
||||
if (refs == null || refs.isEmpty()) {
|
||||
throw new BusinessException("图片列表不能为空");
|
||||
}
|
||||
List<String> urls = new ArrayList<>();
|
||||
for (String ref : refs) {
|
||||
if (!StringUtils.hasText(ref)) {
|
||||
continue;
|
||||
}
|
||||
urls.add(resolveOneImage(companyId, ctx, ref.trim()));
|
||||
}
|
||||
if (urls.isEmpty()) {
|
||||
throw new BusinessException("图片列表不能为空");
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
private String resolveOneImage(Long companyId, ShopAuth ctx, String ref) throws Exception {
|
||||
if (!StringUtils.hasText(ref)) {
|
||||
throw new BusinessException("图片引用不能为空");
|
||||
}
|
||||
String s = ref.trim();
|
||||
if (looksLikeUrl(s)) {
|
||||
return s;
|
||||
}
|
||||
Long fileId;
|
||||
try {
|
||||
fileId = Long.parseLong(s);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new BusinessException("无效的图片引用: " + s);
|
||||
}
|
||||
return imageTransfer.transfer(companyId, ctx.mallId(), ctx.accessToken(), fileId);
|
||||
}
|
||||
|
||||
private static boolean looksLikeUrl(String s) {
|
||||
String lower = s.toLowerCase();
|
||||
return lower.startsWith("http://") || lower.startsWith("https://");
|
||||
}
|
||||
|
||||
private static String normalizeSpecIdList(String raw) {
|
||||
if (!StringUtils.hasText(raw)) {
|
||||
throw new BusinessException("规格列表不能为空");
|
||||
}
|
||||
String s = raw.trim();
|
||||
if (!s.startsWith("[")) {
|
||||
// 允许逗号分隔:20,5 → [20,5]
|
||||
String[] parts = s.split(",");
|
||||
StringBuilder sb = new StringBuilder("[");
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
if (i > 0) {
|
||||
sb.append(',');
|
||||
}
|
||||
sb.append(parts[i].trim());
|
||||
}
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private PddPublishCostTemplateDetailVO mapCostTemplateDetail(
|
||||
PddGoodsPublishPopApiClient.CostTemplateDetail detail) {
|
||||
PddPublishCostTemplateDetailVO vo = new PddPublishCostTemplateDetailVO();
|
||||
vo.setTemplateId(detail.templateId());
|
||||
vo.setTemplateName(detail.templateName());
|
||||
vo.setCostType(detail.costType());
|
||||
vo.setCostTypeLabel(detail.costType() != null && detail.costType() == 1 ? "按重量计费" : "按件计费");
|
||||
vo.setShipProvinceId(detail.shipProvinceId());
|
||||
vo.setShipCityId(detail.shipCityId());
|
||||
vo.setShipDistrictId(detail.shipDistrictId());
|
||||
vo.setAdditionalServiceType(detail.additionalServiceType());
|
||||
vo.setAdditionalServiceLabel(switch (detail.additionalServiceType() == null
|
||||
? 0 : detail.additionalServiceType()) {
|
||||
case 1 -> "支持送货入户";
|
||||
case 2 -> "支持送货入户并安装";
|
||||
default -> "不支持送货入户";
|
||||
});
|
||||
vo.setSfFreeType(detail.sfFreeType());
|
||||
vo.setSfFree(detail.sfFreeType() != null && detail.sfFreeType() != 0);
|
||||
vo.setFreeDeliverHouse(detail.freeDeliverHouse());
|
||||
|
||||
List<PddPublishCostTemplateDetailVO.ProvinceItem> freeProvinces = new ArrayList<>();
|
||||
if (detail.freeProvinces() != null) {
|
||||
for (var p : detail.freeProvinces()) {
|
||||
PddPublishCostTemplateDetailVO.ProvinceItem item =
|
||||
new PddPublishCostTemplateDetailVO.ProvinceItem();
|
||||
item.setProvinceId(p.provinceId());
|
||||
item.setProvince(p.province());
|
||||
freeProvinces.add(item);
|
||||
}
|
||||
}
|
||||
vo.setFreeProvinces(freeProvinces);
|
||||
|
||||
boolean byWeight = detail.costType() != null && detail.costType() == 1;
|
||||
List<PddPublishCostTemplateDetailVO.PaidRegionItem> paid = new ArrayList<>();
|
||||
if (detail.paidRegions() != null) {
|
||||
for (var r : detail.paidRegions()) {
|
||||
PddPublishCostTemplateDetailVO.PaidRegionItem item =
|
||||
new PddPublishCostTemplateDetailVO.PaidRegionItem();
|
||||
List<PddPublishCostTemplateDetailVO.ProvinceItem> provinces = new ArrayList<>();
|
||||
StringBuilder names = new StringBuilder();
|
||||
if (r.provinces() != null) {
|
||||
for (var p : r.provinces()) {
|
||||
PddPublishCostTemplateDetailVO.ProvinceItem pi =
|
||||
new PddPublishCostTemplateDetailVO.ProvinceItem();
|
||||
pi.setProvinceId(p.provinceId());
|
||||
pi.setProvince(p.province());
|
||||
provinces.add(pi);
|
||||
if (StringUtils.hasText(p.province())) {
|
||||
if (names.length() > 0) {
|
||||
names.append('、');
|
||||
}
|
||||
names.append(p.province());
|
||||
}
|
||||
}
|
||||
}
|
||||
item.setProvinces(provinces);
|
||||
item.setProvincesText(names.toString());
|
||||
item.setFirstStandard(r.firstStandard());
|
||||
item.setFirstCostFen(r.firstCostFen());
|
||||
item.setFirstCostYuan(fenToYuan(r.firstCostFen()));
|
||||
item.setAddStandard(r.addStandard());
|
||||
item.setAddCostFen(r.addCostFen());
|
||||
item.setAddCostYuan(fenToYuan(r.addCostFen()));
|
||||
item.setFreeByCountEnabled(r.freeByCountEnabled());
|
||||
item.setFreeMinCount(r.freeMinCount());
|
||||
item.setFreeByAmountEnabled(r.freeByAmountEnabled());
|
||||
item.setFreeMinAmountFen(r.freeMinAmountFen());
|
||||
item.setFreeMinAmountYuan(fenToYuan(r.freeMinAmountFen()));
|
||||
item.setFreeRuleText(buildFreeRuleText(r, byWeight));
|
||||
paid.add(item);
|
||||
}
|
||||
}
|
||||
vo.setPaidRegions(paid);
|
||||
|
||||
List<PddPublishCostTemplateDetailVO.DeliverHouseAreaItem> houseAreas = new ArrayList<>();
|
||||
if (detail.freeDeliverHouseAreas() != null) {
|
||||
for (var a : detail.freeDeliverHouseAreas()) {
|
||||
PddPublishCostTemplateDetailVO.DeliverHouseAreaItem item =
|
||||
new PddPublishCostTemplateDetailVO.DeliverHouseAreaItem();
|
||||
item.setProvince(a.province());
|
||||
item.setCity(a.city());
|
||||
item.setTown(a.town());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (StringUtils.hasText(a.province())) {
|
||||
sb.append(a.province());
|
||||
}
|
||||
if (StringUtils.hasText(a.city())) {
|
||||
sb.append(a.city());
|
||||
}
|
||||
if (StringUtils.hasText(a.town())) {
|
||||
sb.append(a.town());
|
||||
}
|
||||
item.setAreaText(sb.toString());
|
||||
houseAreas.add(item);
|
||||
}
|
||||
}
|
||||
vo.setFreeDeliverHouseAreas(houseAreas);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private static String fenToYuan(Long fen) {
|
||||
if (fen == null || fen < 0) {
|
||||
return null;
|
||||
}
|
||||
return String.format("%.2f", fen / 100.0);
|
||||
}
|
||||
|
||||
private static String buildFreeRuleText(PddGoodsPublishPopApiClient.PaidRegion r, boolean byWeight) {
|
||||
String unit = byWeight ? "kg" : "件";
|
||||
List<String> parts = new ArrayList<>();
|
||||
if (r.freeByCountEnabled() && r.freeMinCount() != null && r.freeMinCount() > 0) {
|
||||
parts.add("满" + r.freeMinCount() + unit + "包邮");
|
||||
}
|
||||
if (r.freeByAmountEnabled() && r.freeMinAmountFen() != null && r.freeMinAmountFen() > 0) {
|
||||
parts.add("满" + fenToYuan(r.freeMinAmountFen()) + "元包邮");
|
||||
}
|
||||
return parts.isEmpty() ? null : String.join(";", parts);
|
||||
}
|
||||
|
||||
private PddPublishCatTemplateVO mapCatTemplate(PddGoodsPublishPopApiClient.CatTemplate tpl) {
|
||||
PddPublishCatTemplateVO vo = new PddPublishCatTemplateVO();
|
||||
vo.setId(tpl.id());
|
||||
vo.setMaxSkuNum(tpl.maxSkuNum());
|
||||
vo.setInputMaxSpecNum(tpl.inputMaxSpecNum());
|
||||
vo.setSingleSpecValueNum(tpl.singleSpecValueNum());
|
||||
vo.setSingleItem(tpl.singleItem());
|
||||
List<PddPublishCatPropertyVO> props = new ArrayList<>();
|
||||
if (tpl.properties() != null) {
|
||||
for (var p : tpl.properties()) {
|
||||
PddPublishCatPropertyVO pv = new PddPublishCatPropertyVO();
|
||||
pv.setTemplatePid(p.templatePid());
|
||||
pv.setName(p.name());
|
||||
pv.setNameAlias(p.nameAlias());
|
||||
pv.setRefPid(p.refPid());
|
||||
pv.setSpecId(p.specId());
|
||||
pv.setParentId(p.parentId());
|
||||
pv.setRequired(p.required());
|
||||
pv.setSale(p.sale());
|
||||
pv.setControlType(p.controlType());
|
||||
pv.setFeature(p.feature());
|
||||
pv.setValueType(p.valueType());
|
||||
pv.setValueUnit(p.valueUnit());
|
||||
pv.setInputMaxNum(p.inputMaxNum());
|
||||
pv.setChooseMaxNum(p.chooseMaxNum());
|
||||
List<PddPublishCatPropertyValueVO> values = new ArrayList<>();
|
||||
if (p.values() != null) {
|
||||
for (var v : p.values()) {
|
||||
PddPublishCatPropertyValueVO vv = new PddPublishCatPropertyValueVO();
|
||||
vv.setVid(v.vid());
|
||||
vv.setValue(v.value());
|
||||
vv.setSpecId(v.specId());
|
||||
vv.setExtendInfo(v.extendInfo());
|
||||
vv.setParent(v.parent());
|
||||
vv.setParentVids(v.parentVids());
|
||||
values.add(vv);
|
||||
}
|
||||
}
|
||||
pv.setValues(values);
|
||||
props.add(pv);
|
||||
}
|
||||
}
|
||||
vo.setProperties(props);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private ShopAuth requireShopAuth(Long pddShopId) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
if (pddShopId == null) {
|
||||
throw new BusinessException("渠道店铺ID不能为空");
|
||||
}
|
||||
PddShopPO shop = pddShopMapper.selectById(pddShopId);
|
||||
if (shop == null || !Objects.equals(shop.getCompanyId(), companyId)) {
|
||||
throw new BusinessException("渠道店铺不存在");
|
||||
}
|
||||
if (shop.getPddAuthId() == null) {
|
||||
throw new PddAuthFailureException("渠道店铺未授权");
|
||||
}
|
||||
PddAuthPO auth = authTokenService.ensureUsableById(shop.getPddAuthId());
|
||||
if (auth == null || !StringUtils.hasText(auth.getAccessToken())) {
|
||||
throw new PddAuthFailureException("渠道店铺授权无效");
|
||||
}
|
||||
if (shop.getMallId() == null) {
|
||||
throw new BusinessException("渠道店铺缺少 mallId");
|
||||
}
|
||||
return new ShopAuth(shop, shop.getMallId(), auth.getAccessToken());
|
||||
}
|
||||
|
||||
private BusinessException wrapPop(String prefix, Exception e) {
|
||||
if (e instanceof BusinessException be) {
|
||||
return be;
|
||||
}
|
||||
log.error("{}: {}", prefix, e.getMessage(), e);
|
||||
String msg = e.getMessage();
|
||||
return new BusinessException(prefix + (StringUtils.hasText(msg) ? ": " + msg : ""));
|
||||
}
|
||||
|
||||
private record ShopAuth(PddShopPO shop, Long mallId, String accessToken) {
|
||||
}
|
||||
}
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.support;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.goods.PddGoodsPublishPopApiClient;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.model.vo.SysFileVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.service.OssService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.file.service.SysFileService;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Base64;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 本系统 fileId → 读字节 → Base64 → 拼多多商品图上传。
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PddGoodsImageTransfer {
|
||||
|
||||
private static final long MAX_BYTES = 1024 * 1024L;
|
||||
private static final Set<String> ALLOWED_EXT = Set.of("jpg", "jpeg", "png");
|
||||
|
||||
private final SysFileService sysFileService;
|
||||
private final OssService ossService;
|
||||
private final PddGoodsPublishPopApiClient publishPopApiClient;
|
||||
|
||||
public PddGoodsImageTransfer(SysFileService sysFileService,
|
||||
OssService ossService,
|
||||
PddGoodsPublishPopApiClient publishPopApiClient) {
|
||||
this.sysFileService = sysFileService;
|
||||
this.ossService = ossService;
|
||||
this.publishPopApiClient = publishPopApiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本公司文件转传为拼多多图片 URL。
|
||||
*/
|
||||
public String transfer(Long companyId, Long mallId, String accessToken, Long fileId) throws Exception {
|
||||
if (fileId == null) {
|
||||
throw new BusinessException("文件ID不能为空");
|
||||
}
|
||||
SysFileVO file = sysFileService.getFileById(fileId);
|
||||
if (file == null) {
|
||||
throw new BusinessException("文件不存在 fileId=" + fileId);
|
||||
}
|
||||
if (companyId != null && file.getCompanyId() != null
|
||||
&& !Objects.equals(companyId, file.getCompanyId())) {
|
||||
throw new BusinessException("无权使用该文件");
|
||||
}
|
||||
assertImageAllowed(file);
|
||||
|
||||
byte[] bytes = readAllBytes(file);
|
||||
if (bytes.length == 0) {
|
||||
throw new BusinessException("文件内容为空");
|
||||
}
|
||||
if (bytes.length > MAX_BYTES) {
|
||||
throw new BusinessException("图片超过1MB限制,无法上传到拼多多");
|
||||
}
|
||||
String base64 = Base64.getEncoder().encodeToString(bytes);
|
||||
return publishPopApiClient.uploadImageBase64(mallId, accessToken, base64);
|
||||
}
|
||||
|
||||
private void assertImageAllowed(SysFileVO file) {
|
||||
String fmt = normalizeExt(file.getFileFormat());
|
||||
if (!StringUtils.hasText(fmt) && StringUtils.hasText(file.getFilename())) {
|
||||
String name = file.getFilename();
|
||||
int dot = name.lastIndexOf('.');
|
||||
if (dot >= 0 && dot < name.length() - 1) {
|
||||
fmt = normalizeExt(name.substring(dot + 1));
|
||||
}
|
||||
}
|
||||
String mime = file.getMimeType() == null ? "" : file.getMimeType().toLowerCase(Locale.ROOT);
|
||||
boolean mimeOk = !StringUtils.hasText(mime)
|
||||
|| mime.contains("jpeg")
|
||||
|| mime.contains("jpg")
|
||||
|| mime.contains("png")
|
||||
|| mime.equals("application/octet-stream");
|
||||
if ((StringUtils.hasText(fmt) && !ALLOWED_EXT.contains(fmt)) || !mimeOk) {
|
||||
throw new BusinessException("仅支持 JPG/JPEG/PNG 图片上传到拼多多");
|
||||
}
|
||||
if (file.getFileSize() != null && file.getFileSize() > MAX_BYTES) {
|
||||
throw new BusinessException("图片超过1MB限制,无法上传到拼多多");
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizeExt(String ext) {
|
||||
if (!StringUtils.hasText(ext)) {
|
||||
return null;
|
||||
}
|
||||
String e = ext.trim().toLowerCase(Locale.ROOT);
|
||||
if (e.startsWith(".")) {
|
||||
e = e.substring(1);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
private byte[] readAllBytes(SysFileVO file) throws Exception {
|
||||
String storagePath = file.getStoragePath();
|
||||
String storageType = file.getStorageType();
|
||||
if (!StringUtils.hasText(storagePath)) {
|
||||
throw new BusinessException("文件存储路径为空");
|
||||
}
|
||||
if ("local".equalsIgnoreCase(storageType)) {
|
||||
File local = new File(storagePath);
|
||||
if (!local.exists() || !local.isFile()) {
|
||||
throw new BusinessException("本地文件不存在: " + storagePath);
|
||||
}
|
||||
try (InputStream in = new FileInputStream(local)) {
|
||||
return readFully(in);
|
||||
}
|
||||
}
|
||||
|
||||
try (InputStream stream = ossService.getFileAsStream(storagePath)) {
|
||||
if (stream != null) {
|
||||
return readFully(stream);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("OSS 流式读取失败,回退临时文件: {}", e.getMessage());
|
||||
}
|
||||
|
||||
File temp = File.createTempFile("pdd-img-", ".bin");
|
||||
try {
|
||||
if (!ossService.downloadFile(storagePath, temp)) {
|
||||
throw new BusinessException("从对象存储下载文件失败");
|
||||
}
|
||||
try (InputStream in = new FileInputStream(temp)) {
|
||||
return readFully(in);
|
||||
}
|
||||
} finally {
|
||||
if (!temp.delete()) {
|
||||
log.debug("临时文件删除失败: {}", temp.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] readFully(InputStream in) throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
byte[] buf = new byte[8192];
|
||||
int n;
|
||||
while ((n = in.read(buf)) >= 0) {
|
||||
out.write(buf, 0, n);
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
+8
@@ -16,6 +16,14 @@ public final class PddPopApiTypes {
|
||||
// ---------- 商品 ----------
|
||||
public static final String GOODS_INFORMATION_GET = "pdd.goods.information.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_IMAGE_UPLOAD = "pdd.goods.image.upload";
|
||||
public static final String GOODS_AUTHORIZATION_CATS = "pdd.goods.authorization.cats";
|
||||
public static final String GOODS_LOGISTICS_TEMPLATE_GET = "pdd.goods.logistics.template.get";
|
||||
public static final String GOODS_CAT_TEMPLATE_GET = "pdd.goods.cat.template.get";
|
||||
public static final String GOODS_SPEC_GET = "pdd.goods.spec.get";
|
||||
public static final String GOODS_SPEC_ID_GET = "pdd.goods.spec.id.get";
|
||||
public static final String ONE_EXPRESS_COST_TEMPLATE = "pdd.one.express.cost.template";
|
||||
|
||||
// ---------- 店铺 ----------
|
||||
public static final String MALL_INFO_GET = "pdd.mall.info.get";
|
||||
|
||||
+508
@@ -0,0 +1,508 @@
|
||||
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.PddGoodsAuthorizationCatsRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsCatTemplateGetRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsImageUploadRequest;
|
||||
import com.pdd.pop.sdk.http.api.pop.request.PddGoodsLogisticsTemplateGetRequest;
|
||||
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.PddGoodsAuthorizationCatsResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsCatTemplateGetResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsImageUploadResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsLogisticsTemplateGetResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsSpecGetResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddGoodsSpecIdGetResponse;
|
||||
import com.pdd.pop.sdk.http.api.pop.response.PddOneExpressCostTemplateResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.PddPopApiTypes;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.support.PddPopInvokeSupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品发布域 POP:类目/运费模板/属性模板/规格/传图/新增。
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PddGoodsPublishPopApiClient {
|
||||
|
||||
private final PddPopInvokeSupport invokeSupport;
|
||||
|
||||
public PddGoodsPublishPopApiClient(PddPopInvokeSupport invokeSupport) {
|
||||
this.invokeSupport = invokeSupport;
|
||||
}
|
||||
|
||||
/** 授权可发布类目(parentCatId 空或 0 为顶级)。 */
|
||||
public List<AuthCatItem> listAuthorizationCats(Long mallId, String accessToken, Long parentCatId)
|
||||
throws Exception {
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_AUTHORIZATION_CATS, mallId, client -> {
|
||||
PddGoodsAuthorizationCatsRequest request = new PddGoodsAuthorizationCatsRequest();
|
||||
request.setParentCatId(parentCatId == null ? 0L : parentCatId);
|
||||
PddGoodsAuthorizationCatsResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_AUTHORIZATION_CATS);
|
||||
return mapAuthCats(response);
|
||||
});
|
||||
}
|
||||
|
||||
/** 运费模板分页;goodsStatus:0 新发布 / 1 编辑。 */
|
||||
public LogisticsTemplatePage listLogisticsTemplates(Long mallId,
|
||||
String accessToken,
|
||||
int page,
|
||||
int pageSize,
|
||||
Integer goodsStatus) throws Exception {
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_LOGISTICS_TEMPLATE_GET, mallId, client -> {
|
||||
PddGoodsLogisticsTemplateGetRequest request = new PddGoodsLogisticsTemplateGetRequest();
|
||||
request.setPage(Math.max(page, 1));
|
||||
request.setPageSize(Math.min(Math.max(pageSize, 1), 100));
|
||||
if (goodsStatus != null) {
|
||||
request.setGoodsStatus(goodsStatus);
|
||||
}
|
||||
PddGoodsLogisticsTemplateGetResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_LOGISTICS_TEMPLATE_GET);
|
||||
return mapLogistics(response);
|
||||
});
|
||||
}
|
||||
|
||||
/** 按模板 ID 查询运费模板详情。 */
|
||||
public CostTemplateDetail fetchCostTemplateDetail(Long mallId, String accessToken, Long costTemplateId)
|
||||
throws Exception {
|
||||
if (costTemplateId == null) {
|
||||
throw new BusinessException("运费模板ID不能为空");
|
||||
}
|
||||
return invokeSupport.invoke(PddPopApiTypes.ONE_EXPRESS_COST_TEMPLATE, mallId, client -> {
|
||||
PddOneExpressCostTemplateRequest request = new PddOneExpressCostTemplateRequest();
|
||||
request.setCostTemplateId(costTemplateId);
|
||||
PddOneExpressCostTemplateResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.ONE_EXPRESS_COST_TEMPLATE);
|
||||
return mapCostTemplateDetail(response);
|
||||
});
|
||||
}
|
||||
|
||||
/** 叶子类目属性模板。 */
|
||||
public CatTemplate getCatTemplate(Long mallId, String accessToken, Long catId) throws Exception {
|
||||
if (catId == null) {
|
||||
throw new BusinessException("类目ID不能为空");
|
||||
}
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_CAT_TEMPLATE_GET, mallId, client -> {
|
||||
PddGoodsCatTemplateGetRequest request = new PddGoodsCatTemplateGetRequest();
|
||||
request.setCatId(catId);
|
||||
PddGoodsCatTemplateGetResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_CAT_TEMPLATE_GET);
|
||||
return mapCatTemplate(response);
|
||||
});
|
||||
}
|
||||
|
||||
/** 叶子类目父规格列表(需 level=3 的 cat_id)。 */
|
||||
public List<ParentSpecItem> listParentSpecs(Long mallId, String accessToken, Long catId) throws Exception {
|
||||
if (catId == null) {
|
||||
throw new BusinessException("类目ID不能为空");
|
||||
}
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_SPEC_GET, mallId, client -> {
|
||||
PddGoodsSpecGetRequest request = new PddGoodsSpecGetRequest();
|
||||
request.setCatId(catId);
|
||||
PddGoodsSpecGetResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_SPEC_GET);
|
||||
return mapParentSpecs(response);
|
||||
});
|
||||
}
|
||||
|
||||
/** 生成自定义规格值 ID。 */
|
||||
public SpecIdResult createSpecId(Long mallId, String accessToken, Long parentSpecId, String specName)
|
||||
throws Exception {
|
||||
if (parentSpecId == null || !StringUtils.hasText(specName)) {
|
||||
throw new BusinessException("父规格ID与规格值不能为空");
|
||||
}
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_SPEC_ID_GET, mallId, client -> {
|
||||
PddGoodsSpecIdGetRequest request = new PddGoodsSpecIdGetRequest();
|
||||
request.setParentSpecId(parentSpecId);
|
||||
request.setSpecName(specName.trim());
|
||||
PddGoodsSpecIdGetResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_SPEC_ID_GET);
|
||||
var body = response.getGoodsSpecIdGetResponse();
|
||||
if (body == null || body.getSpecId() == null) {
|
||||
throw new BusinessException("生成规格ID失败");
|
||||
}
|
||||
return new SpecIdResult(body.getParentSpecId(), body.getSpecName(), body.getSpecId());
|
||||
});
|
||||
}
|
||||
|
||||
/** 上传商品图(入参已是 base64)。 */
|
||||
public String uploadImageBase64(Long mallId, String accessToken, String imageBase64) throws Exception {
|
||||
if (!StringUtils.hasText(imageBase64)) {
|
||||
throw new BusinessException("图片内容不能为空");
|
||||
}
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_IMAGE_UPLOAD, mallId, client -> {
|
||||
PddGoodsImageUploadRequest request = new PddGoodsImageUploadRequest();
|
||||
request.setImage(imageBase64);
|
||||
PddGoodsImageUploadResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_IMAGE_UPLOAD);
|
||||
var body = response.getGoodsImageUploadResponse();
|
||||
if (body == null || !StringUtils.hasText(body.getImageUrl())) {
|
||||
throw new BusinessException("拼多多图片上传未返回URL");
|
||||
}
|
||||
return body.getImageUrl();
|
||||
});
|
||||
}
|
||||
|
||||
/** 商品新增。 */
|
||||
public GoodsAddResult addGoods(Long mallId, String accessToken, GoodsAddCommand command) throws Exception {
|
||||
if (command == null) {
|
||||
throw new BusinessException("发布参数不能为空");
|
||||
}
|
||||
return invokeSupport.invoke(PddPopApiTypes.GOODS_ADD, mallId, client -> {
|
||||
PddGoodsAddRequest request = toAddRequest(command);
|
||||
PddGoodsAddResponse response = client.syncInvoke(request, accessToken);
|
||||
invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_ADD);
|
||||
var body = response.getGoodsAddResponse();
|
||||
if (body == null || body.getGoodsId() == null) {
|
||||
throw new BusinessException("拼多多商品发布未返回goods_id");
|
||||
}
|
||||
return new GoodsAddResult(body.getGoodsId(), body.getGoodsCommitId(), body.getMatchedSpuId());
|
||||
});
|
||||
}
|
||||
|
||||
private PddGoodsAddRequest toAddRequest(GoodsAddCommand cmd) {
|
||||
PddGoodsAddRequest request = new PddGoodsAddRequest();
|
||||
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.goodsProperties() != null && !cmd.goodsProperties().isEmpty()) {
|
||||
List<PddGoodsAddRequest.GoodsPropertiesItem> props = new ArrayList<>();
|
||||
for (GoodsPropertyItem p : cmd.goodsProperties()) {
|
||||
PddGoodsAddRequest.GoodsPropertiesItem item = new PddGoodsAddRequest.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);
|
||||
}
|
||||
List<PddGoodsAddRequest.SkuListItem> skuList = new ArrayList<>();
|
||||
for (SkuAddItem sku : cmd.skuList()) {
|
||||
PddGoodsAddRequest.SkuListItem item = new PddGoodsAddRequest.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<PddGoodsAddRequest.SkuListItemSkuPropertiesItem> sps = new ArrayList<>();
|
||||
for (SkuPropertyItem sp : sku.skuProperties()) {
|
||||
PddGoodsAddRequest.SkuListItemSkuPropertiesItem spi =
|
||||
new PddGoodsAddRequest.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 List<AuthCatItem> mapAuthCats(PddGoodsAuthorizationCatsResponse response) {
|
||||
if (response == null || response.getGoodsAuthCatsGetResponse() == null
|
||||
|| response.getGoodsAuthCatsGetResponse().getGoodsCatsList() == null) {
|
||||
return List.of();
|
||||
}
|
||||
List<AuthCatItem> list = new ArrayList<>();
|
||||
for (var c : response.getGoodsAuthCatsGetResponse().getGoodsCatsList()) {
|
||||
if (c == null || c.getCatId() == null) {
|
||||
continue;
|
||||
}
|
||||
list.add(new AuthCatItem(c.getCatId(), c.getCatName(), Boolean.TRUE.equals(c.getLeaf())));
|
||||
}
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
private LogisticsTemplatePage mapLogistics(PddGoodsLogisticsTemplateGetResponse response) {
|
||||
if (response == null || response.getGoodsLogisticsTemplateGetResponse() == null) {
|
||||
return new LogisticsTemplatePage(0, List.of());
|
||||
}
|
||||
var body = response.getGoodsLogisticsTemplateGetResponse();
|
||||
int total = body.getTotalCount() != null ? body.getTotalCount() : 0;
|
||||
List<LogisticsTemplateItem> list = new ArrayList<>();
|
||||
if (body.getLogisticsTemplateList() != null) {
|
||||
for (var t : body.getLogisticsTemplateList()) {
|
||||
if (t == null || t.getTemplateId() == null) {
|
||||
continue;
|
||||
}
|
||||
list.add(new LogisticsTemplateItem(
|
||||
t.getTemplateId(), t.getTemplateName(), t.getCostType(), t.getLastUpdatedTime()));
|
||||
}
|
||||
}
|
||||
return new LogisticsTemplatePage(total, Collections.unmodifiableList(list));
|
||||
}
|
||||
|
||||
private CostTemplateDetail mapCostTemplateDetail(PddOneExpressCostTemplateResponse response) {
|
||||
if (response == null || response.getOneExpressCostTemplateResponse() == null) {
|
||||
throw new BusinessException("运费模板详情为空");
|
||||
}
|
||||
var body = response.getOneExpressCostTemplateResponse();
|
||||
List<FreeProvince> freeProvinces = new ArrayList<>();
|
||||
if (body.getFreeProvinceList() != null) {
|
||||
for (var p : body.getFreeProvinceList()) {
|
||||
if (p == null) {
|
||||
continue;
|
||||
}
|
||||
freeProvinces.add(new FreeProvince(p.getProvinceId(), p.getProvince()));
|
||||
}
|
||||
}
|
||||
List<PaidRegion> paidRegions = new ArrayList<>();
|
||||
if (body.getCostTemplateList() != null) {
|
||||
for (var item : body.getCostTemplateList()) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
List<FreeProvince> provinces = new ArrayList<>();
|
||||
if (item.getCostProvinceList() != null) {
|
||||
for (var p : item.getCostProvinceList()) {
|
||||
if (p == null) {
|
||||
continue;
|
||||
}
|
||||
provinces.add(new FreeProvince(
|
||||
p.getProvinceId() == null ? null : p.getProvinceId().longValue(),
|
||||
p.getProvince()));
|
||||
}
|
||||
}
|
||||
paidRegions.add(new PaidRegion(
|
||||
Collections.unmodifiableList(provinces),
|
||||
item.getFirstStandard(),
|
||||
item.getFirstCost(),
|
||||
item.getAddStandard(),
|
||||
item.getAddCost(),
|
||||
Boolean.TRUE.equals(item.getIsHaveFreeMinCount()),
|
||||
item.getHaveFreeMinCount(),
|
||||
Boolean.TRUE.equals(item.getIsHaveFreeMinAmount()),
|
||||
item.getHaveFreeMinAmount()));
|
||||
}
|
||||
}
|
||||
List<DeliverHouseArea> houseAreas = new ArrayList<>();
|
||||
if (body.getFreeDeliverHouseAreaList() != null) {
|
||||
for (var a : body.getFreeDeliverHouseAreaList()) {
|
||||
if (a == null) {
|
||||
continue;
|
||||
}
|
||||
houseAreas.add(new DeliverHouseArea(
|
||||
a.getProvinceId(), a.getCityId(), a.getTownId(),
|
||||
a.getProvince(), a.getCity(), a.getTown()));
|
||||
}
|
||||
}
|
||||
return new CostTemplateDetail(
|
||||
body.getTemplateId(),
|
||||
body.getTemplateName(),
|
||||
body.getCostType(),
|
||||
body.getProvinceId(),
|
||||
body.getCityId(),
|
||||
body.getDistrictId(),
|
||||
body.getAdditionalServiceType(),
|
||||
body.getSfFreeType(),
|
||||
Boolean.TRUE.equals(body.getFreeDeliverHouse()),
|
||||
Collections.unmodifiableList(freeProvinces),
|
||||
Collections.unmodifiableList(paidRegions),
|
||||
Collections.unmodifiableList(houseAreas));
|
||||
}
|
||||
|
||||
private CatTemplate mapCatTemplate(PddGoodsCatTemplateGetResponse response) {
|
||||
if (response == null || response.getOpenApiResponse() == null) {
|
||||
return new CatTemplate(null, null, null, null, null, List.of());
|
||||
}
|
||||
var body = response.getOpenApiResponse();
|
||||
List<CatProperty> props = new ArrayList<>();
|
||||
if (body.getProperties() != null) {
|
||||
for (var p : body.getProperties()) {
|
||||
if (p == null) {
|
||||
continue;
|
||||
}
|
||||
List<CatPropertyValue> values = new ArrayList<>();
|
||||
if (p.getValues() != null) {
|
||||
for (var v : p.getValues()) {
|
||||
if (v == null) {
|
||||
continue;
|
||||
}
|
||||
values.add(new CatPropertyValue(
|
||||
v.getVid(), v.getValue(), v.getSpecId(), v.getExtendInfo(),
|
||||
v.getIsParent(), v.getParentVids()));
|
||||
}
|
||||
}
|
||||
props.add(new CatProperty(
|
||||
p.getId(),
|
||||
p.getName(),
|
||||
p.getNameAlias(),
|
||||
p.getRefPid(),
|
||||
p.getSpecId(),
|
||||
p.getParentId(),
|
||||
Boolean.TRUE.equals(p.getRequired()),
|
||||
Boolean.TRUE.equals(p.getIsSale()),
|
||||
p.getControlType(),
|
||||
p.getFeature(),
|
||||
p.getValueType(),
|
||||
p.getValueUnit(),
|
||||
p.getInputMaxNum(),
|
||||
p.getChooseMaxNum(),
|
||||
Collections.unmodifiableList(values)));
|
||||
}
|
||||
}
|
||||
return new CatTemplate(
|
||||
body.getId(),
|
||||
body.getMaxSkuNum(),
|
||||
body.getInputMaxSpecNum(),
|
||||
body.getSingleSpecValueNum(),
|
||||
body.getIsSingleItem(),
|
||||
Collections.unmodifiableList(props));
|
||||
}
|
||||
|
||||
private List<ParentSpecItem> mapParentSpecs(PddGoodsSpecGetResponse response) {
|
||||
if (response == null || response.getGoodsSpecGetResponse() == null
|
||||
|| response.getGoodsSpecGetResponse().getGoodsSpecList() == null) {
|
||||
return List.of();
|
||||
}
|
||||
List<ParentSpecItem> list = new ArrayList<>();
|
||||
for (var s : response.getGoodsSpecGetResponse().getGoodsSpecList()) {
|
||||
if (s == null || s.getParentSpecId() == null) {
|
||||
continue;
|
||||
}
|
||||
list.add(new ParentSpecItem(s.getCatId(), s.getParentSpecId(), s.getParentSpecName()));
|
||||
}
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
public record AuthCatItem(Long catId, String catName, boolean leaf) {
|
||||
}
|
||||
|
||||
public record LogisticsTemplatePage(int totalCount, List<LogisticsTemplateItem> templates) {
|
||||
}
|
||||
|
||||
public record LogisticsTemplateItem(Long templateId, String templateName, Integer costType,
|
||||
Integer lastUpdatedTime) {
|
||||
}
|
||||
|
||||
/** 运费模板详情(pdd.one.express.cost.template)。 */
|
||||
public record CostTemplateDetail(
|
||||
Long templateId,
|
||||
String templateName,
|
||||
Integer costType,
|
||||
Integer shipProvinceId,
|
||||
Integer shipCityId,
|
||||
Integer shipDistrictId,
|
||||
Integer additionalServiceType,
|
||||
Integer sfFreeType,
|
||||
boolean freeDeliverHouse,
|
||||
List<FreeProvince> freeProvinces,
|
||||
List<PaidRegion> paidRegions,
|
||||
List<DeliverHouseArea> freeDeliverHouseAreas) {
|
||||
}
|
||||
|
||||
public record FreeProvince(Long provinceId, String province) {
|
||||
}
|
||||
|
||||
public record PaidRegion(
|
||||
List<FreeProvince> provinces,
|
||||
Long firstStandard,
|
||||
Long firstCostFen,
|
||||
Long addStandard,
|
||||
Long addCostFen,
|
||||
boolean freeByCountEnabled,
|
||||
Long freeMinCount,
|
||||
boolean freeByAmountEnabled,
|
||||
Long freeMinAmountFen) {
|
||||
}
|
||||
|
||||
public record DeliverHouseArea(
|
||||
Integer provinceId, Integer cityId, Integer townId,
|
||||
String province, String city, String town) {
|
||||
}
|
||||
|
||||
public record CatTemplate(Long id, Long maxSkuNum, Long inputMaxSpecNum, Long singleSpecValueNum,
|
||||
Boolean singleItem, List<CatProperty> properties) {
|
||||
}
|
||||
|
||||
public record CatProperty(Long templatePid, String name, String nameAlias, Long refPid, Long specId,
|
||||
Long parentId, boolean required, boolean sale, Integer controlType,
|
||||
Integer feature, Integer valueType, String valueUnit,
|
||||
Integer inputMaxNum, Integer chooseMaxNum, List<CatPropertyValue> values) {
|
||||
}
|
||||
|
||||
public record CatPropertyValue(Long vid, String value, Long specId, String extendInfo,
|
||||
Boolean parent, List<Long> parentVids) {
|
||||
}
|
||||
|
||||
public record ParentSpecItem(Long catId, Long parentSpecId, String parentSpecName) {
|
||||
}
|
||||
|
||||
public record SpecIdResult(Long parentSpecId, String specName, Long specId) {
|
||||
}
|
||||
|
||||
public record GoodsAddResult(Long goodsId, Long goodsCommitId, Long matchedSpuId) {
|
||||
}
|
||||
|
||||
public record GoodsPropertyItem(Long refPid, Long vid, String value, String valueUnit, Long templatePid,
|
||||
Long parentSpecId, Long specId, String imgUrl, String note,
|
||||
Integer groupId) {
|
||||
}
|
||||
|
||||
public record SkuPropertyItem(Long refPid, Long vid, String value, String punit) {
|
||||
}
|
||||
|
||||
public record SkuAddItem(Integer isOnsale, Long limitQuantity, Long multiPrice, Long price,
|
||||
Long quantity, Long weight, String thumbUrl, String outSkuSn,
|
||||
String specIdList, List<SkuPropertyItem> skuProperties) {
|
||||
}
|
||||
|
||||
public record GoodsAddCommand(
|
||||
String goodsName,
|
||||
String goodsDesc,
|
||||
Long catId,
|
||||
Long costTemplateId,
|
||||
Integer countryId,
|
||||
Integer goodsType,
|
||||
Long marketPrice,
|
||||
Long shipmentLimitSecond,
|
||||
Boolean isFolt,
|
||||
Boolean isPreSale,
|
||||
Boolean isRefundable,
|
||||
Boolean secondHand,
|
||||
List<String> carouselGallery,
|
||||
List<String> detailGallery,
|
||||
String outGoodsId,
|
||||
String imageUrl,
|
||||
List<GoodsPropertyItem> goodsProperties,
|
||||
List<SkuAddItem> skuList) {
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,51 @@ pdd:
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 800
|
||||
app-burst-window-seconds: 10
|
||||
pdd.goods.list.get:
|
||||
shop-limit: 5000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 800
|
||||
app-burst-window-seconds: 10
|
||||
pdd.goods.add:
|
||||
shop-limit: 2000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 400
|
||||
app-burst-window-seconds: 10
|
||||
pdd.goods.image.upload:
|
||||
shop-limit: 3000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 600
|
||||
app-burst-window-seconds: 10
|
||||
pdd.goods.authorization.cats:
|
||||
shop-limit: 6000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 800
|
||||
app-burst-window-seconds: 10
|
||||
pdd.goods.logistics.template.get:
|
||||
shop-limit: 6000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 800
|
||||
app-burst-window-seconds: 10
|
||||
pdd.goods.cat.template.get:
|
||||
shop-limit: 6000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 800
|
||||
app-burst-window-seconds: 10
|
||||
pdd.goods.spec.get:
|
||||
shop-limit: 6000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 800
|
||||
app-burst-window-seconds: 10
|
||||
pdd.goods.spec.id.get:
|
||||
shop-limit: 6000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 800
|
||||
app-burst-window-seconds: 10
|
||||
pdd.one.express.cost.template:
|
||||
shop-limit: 6000
|
||||
shop-window-seconds: 60
|
||||
app-burst-limit: 800
|
||||
app-burst-window-seconds: 10
|
||||
pdd.mall.info.get:
|
||||
shop-limit: 6000
|
||||
shop-window-seconds: 60
|
||||
|
||||
@@ -2,7 +2,12 @@ import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
import type { PddGoodsDTO, PddGoodsVO } from './types';
|
||||
import type {
|
||||
PddGoodsDTO,
|
||||
PddGoodsPublishDTO,
|
||||
PddGoodsPublishVO,
|
||||
PddGoodsVO,
|
||||
} from './types';
|
||||
|
||||
/** 分页查询拼多多渠道商品 */
|
||||
export async function getPddGoodsPageApi(
|
||||
@@ -30,3 +35,81 @@ export async function syncPddGoodsByShopApi(pddShopId: number) {
|
||||
`/channel/pdd/goods/sync/${pddShopId}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** 可发布类目 */
|
||||
export async function listPddPublishCatsApi(
|
||||
data: PddGoodsPublishDTO.ShopCatQuery,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.Cat[]>(
|
||||
'/channel/pdd/goods/publish/meta/cats',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 运费模板列表 */
|
||||
export async function listPddPublishLogisticsApi(
|
||||
data: PddGoodsPublishDTO.LogisticsQuery,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.LogisticsPage>(
|
||||
'/channel/pdd/goods/publish/meta/logistics-templates',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 运费模板详情 */
|
||||
export async function getPddPublishLogisticsTemplateDetailApi(
|
||||
data: PddGoodsPublishDTO.CostTemplateDetailQuery,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.CostTemplateDetail>(
|
||||
'/channel/pdd/goods/publish/meta/logistics-template-detail',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 类目属性模板 */
|
||||
export async function getPddPublishCatTemplateApi(
|
||||
data: PddGoodsPublishDTO.CatTemplateQuery,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.CatTemplate>(
|
||||
'/channel/pdd/goods/publish/meta/cat-template',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 父规格列表 */
|
||||
export async function listPddPublishParentSpecsApi(
|
||||
data: PddGoodsPublishDTO.SpecQuery,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.ParentSpec[]>(
|
||||
'/channel/pdd/goods/publish/meta/specs',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 生成规格 ID */
|
||||
export async function createPddPublishSpecIdApi(
|
||||
data: PddGoodsPublishDTO.SpecIdCreate,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.SpecId>(
|
||||
'/channel/pdd/goods/publish/meta/spec-id',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 本系统文件转传拼多多图 */
|
||||
export async function transferPddPublishImageApi(
|
||||
data: PddGoodsPublishDTO.TransferImage,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.TransferImageResult>(
|
||||
'/channel/pdd/goods/publish/transfer-image',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 发布商品并入库 */
|
||||
export async function publishPddGoodsApi(data: PddGoodsPublishDTO.Publish) {
|
||||
return requestClient.post<PddGoodsPublishVO.PublishResult>(
|
||||
'/channel/pdd/goods/publish',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export * from './publish';
|
||||
|
||||
export namespace PddGoodsDTO {
|
||||
export interface Filters {
|
||||
/** 渠道店铺ID(channel_pdd_shop.id) */
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
/** 拼多多商品发布相关类型 */
|
||||
export namespace PddGoodsPublishDTO {
|
||||
export interface Publish {
|
||||
pddShopId: number;
|
||||
primaryProductId: number;
|
||||
goodsName: string;
|
||||
goodsDesc?: string;
|
||||
catId: number;
|
||||
costTemplateId: number;
|
||||
marketPriceFen: number;
|
||||
shipmentLimitSecond: number;
|
||||
isFolt: boolean;
|
||||
isPreSale: boolean;
|
||||
isRefundable: boolean;
|
||||
secondHand: boolean;
|
||||
/** fileId 字符串或已转传的 URL */
|
||||
carouselImages: string[];
|
||||
detailImages: string[];
|
||||
imageUrl?: string;
|
||||
goodsProperties?: GoodsProperty[];
|
||||
skus: PublishSku[];
|
||||
}
|
||||
|
||||
export interface GoodsProperty {
|
||||
refPid?: number;
|
||||
vid?: number;
|
||||
value?: string;
|
||||
valueUnit?: string;
|
||||
templatePid?: number;
|
||||
parentSpecId?: number;
|
||||
specId?: number;
|
||||
imgUrl?: string;
|
||||
note?: string;
|
||||
groupId?: number;
|
||||
}
|
||||
|
||||
export interface PublishSku {
|
||||
/** 可选:选内部 SKU;手填时可不传 */
|
||||
internalSkuId?: number;
|
||||
/** 商家编码;未选内部 SKU 时必填 */
|
||||
outSkuSn?: string;
|
||||
priceFen: number;
|
||||
multiPriceFen: number;
|
||||
quantity: number;
|
||||
weight: number;
|
||||
thumbImage: string;
|
||||
specIdList: string;
|
||||
isOnsale?: number;
|
||||
skuProperties?: SkuProperty[];
|
||||
}
|
||||
|
||||
export interface SkuProperty {
|
||||
refPid: number;
|
||||
vid: number;
|
||||
value?: string;
|
||||
punit?: string;
|
||||
}
|
||||
|
||||
export interface ShopCatQuery {
|
||||
pddShopId: number;
|
||||
parentCatId?: number;
|
||||
}
|
||||
|
||||
export interface LogisticsQuery {
|
||||
pddShopId: number;
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
goodsStatus?: number;
|
||||
}
|
||||
|
||||
export interface CostTemplateDetailQuery {
|
||||
pddShopId: number;
|
||||
costTemplateId: number;
|
||||
}
|
||||
|
||||
export interface CatTemplateQuery {
|
||||
pddShopId: number;
|
||||
catId: number;
|
||||
}
|
||||
|
||||
export interface SpecQuery {
|
||||
pddShopId: number;
|
||||
catId: number;
|
||||
}
|
||||
|
||||
export interface SpecIdCreate {
|
||||
pddShopId: number;
|
||||
parentSpecId: number;
|
||||
specName: string;
|
||||
}
|
||||
|
||||
export interface TransferImage {
|
||||
pddShopId: number;
|
||||
fileId: number;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace PddGoodsPublishVO {
|
||||
export interface Cat {
|
||||
catId: number;
|
||||
catName?: string;
|
||||
leaf?: boolean;
|
||||
}
|
||||
|
||||
export interface LogisticsPage {
|
||||
totalCount?: number;
|
||||
templates?: LogisticsTemplate[];
|
||||
}
|
||||
|
||||
export interface LogisticsTemplate {
|
||||
templateId: number;
|
||||
templateName?: string;
|
||||
costType?: number;
|
||||
lastUpdatedTime?: number;
|
||||
}
|
||||
|
||||
export interface CostTemplateDetail {
|
||||
templateId?: number;
|
||||
templateName?: string;
|
||||
costType?: number;
|
||||
costTypeLabel?: string;
|
||||
additionalServiceType?: number;
|
||||
additionalServiceLabel?: string;
|
||||
sfFreeType?: number;
|
||||
sfFree?: boolean;
|
||||
freeDeliverHouse?: boolean;
|
||||
freeProvinces?: CostProvince[];
|
||||
paidRegions?: CostPaidRegion[];
|
||||
freeDeliverHouseAreas?: CostDeliverHouseArea[];
|
||||
}
|
||||
|
||||
export interface CostProvince {
|
||||
provinceId?: number;
|
||||
province?: string;
|
||||
}
|
||||
|
||||
export interface CostPaidRegion {
|
||||
provinces?: CostProvince[];
|
||||
provincesText?: string;
|
||||
firstStandard?: number;
|
||||
firstCostFen?: number;
|
||||
firstCostYuan?: string;
|
||||
addStandard?: number;
|
||||
addCostFen?: number;
|
||||
addCostYuan?: string;
|
||||
freeByCountEnabled?: boolean;
|
||||
freeMinCount?: number;
|
||||
freeByAmountEnabled?: boolean;
|
||||
freeMinAmountFen?: number;
|
||||
freeMinAmountYuan?: string;
|
||||
freeRuleText?: string;
|
||||
}
|
||||
|
||||
export interface CostDeliverHouseArea {
|
||||
province?: string;
|
||||
city?: string;
|
||||
town?: string;
|
||||
areaText?: string;
|
||||
}
|
||||
|
||||
export interface CatTemplate {
|
||||
id?: number;
|
||||
maxSkuNum?: number;
|
||||
inputMaxSpecNum?: number;
|
||||
singleSpecValueNum?: number;
|
||||
singleItem?: boolean;
|
||||
properties?: CatProperty[];
|
||||
}
|
||||
|
||||
export interface CatProperty {
|
||||
templatePid?: number;
|
||||
name?: string;
|
||||
nameAlias?: string;
|
||||
refPid?: number;
|
||||
specId?: number;
|
||||
parentId?: number;
|
||||
required?: boolean;
|
||||
sale?: boolean;
|
||||
controlType?: number;
|
||||
feature?: number;
|
||||
valueType?: number;
|
||||
valueUnit?: string;
|
||||
inputMaxNum?: number;
|
||||
chooseMaxNum?: number;
|
||||
values?: CatPropertyValue[];
|
||||
}
|
||||
|
||||
export interface CatPropertyValue {
|
||||
vid?: number;
|
||||
value?: string;
|
||||
specId?: number;
|
||||
extendInfo?: string;
|
||||
parent?: boolean;
|
||||
parentVids?: number[];
|
||||
}
|
||||
|
||||
export interface ParentSpec {
|
||||
catId?: number;
|
||||
parentSpecId: number;
|
||||
parentSpecName?: string;
|
||||
}
|
||||
|
||||
export interface SpecId {
|
||||
parentSpecId?: number;
|
||||
specName?: string;
|
||||
specId: number;
|
||||
}
|
||||
|
||||
export interface TransferImageResult {
|
||||
imageUrl: string;
|
||||
}
|
||||
|
||||
export interface PublishResult {
|
||||
goodsId: number;
|
||||
goodsCommitId?: number;
|
||||
matchedSpuId?: number;
|
||||
goods?: {
|
||||
id: number;
|
||||
productId?: number;
|
||||
goodsId?: string;
|
||||
goodsName?: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
+1310
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@ import PddShopDetailModal from '#/views/channel/pdd/shop/components/PddShopDetai
|
||||
import ProductDetailDrawer from '#/views/ec/product/list/components/ProductDetailDrawer.vue';
|
||||
|
||||
import PddGoodsDetailDrawer from './components/PddGoodsDetailDrawer.vue';
|
||||
import PddGoodsPublishModal from './components/PddGoodsPublishModal.vue';
|
||||
|
||||
defineOptions({ name: 'PddGoodsManagement' });
|
||||
|
||||
@@ -27,6 +28,7 @@ const loading = ref(false);
|
||||
const detailDrawerRef = ref<InstanceType<typeof PddGoodsDetailDrawer>>();
|
||||
const shopDetailModalRef = ref<InstanceType<typeof PddShopDetailModal>>();
|
||||
const productDetailDrawerRef = ref<InstanceType<typeof ProductDetailDrawer>>();
|
||||
const publishOpen = ref(false);
|
||||
/** 左侧选中的拼多多渠道店铺 ID */
|
||||
const selectedShopId = ref<number | undefined>(undefined);
|
||||
const shopNameById = ref<Record<number, string>>({});
|
||||
@@ -329,7 +331,14 @@ onMounted(async () => {
|
||||
}"
|
||||
>
|
||||
<template #title>
|
||||
<span class="text-base font-semibold">拼多多商品</span>
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="text-base font-semibold">拼多多商品</span>
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button type="primary" size="small" @click="publishOpen = true">
|
||||
发布商品
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div
|
||||
@@ -416,6 +425,11 @@ onMounted(async () => {
|
||||
/>
|
||||
<PddShopDetailModal ref="shopDetailModalRef" />
|
||||
<ProductDetailDrawer ref="productDetailDrawerRef" />
|
||||
<PddGoodsPublishModal
|
||||
v-model:open="publishOpen"
|
||||
:preset-pdd-shop-id="selectedShopId"
|
||||
@success="() => gridApi.reload()"
|
||||
/>
|
||||
</PddShopColPage>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user