diff --git a/ecom-dmb-backend/sql/design/channel/channel_pdd_good_design.sql b/ecom-dmb-backend/sql/design/channel/channel_pdd_good_design.sql index 31759f70..c1174d57 100644 --- a/ecom-dmb-backend/sql/design/channel/channel_pdd_good_design.sql +++ b/ecom-dmb-backend/sql/design/channel/channel_pdd_good_design.sql @@ -15,8 +15,8 @@ DROP TABLE IF EXISTS `channel_pdd_goods`; CREATE TABLE `channel_pdd_goods` ( `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID', `company_id` bigint UNSIGNED NOT NULL COMMENT '公司ID', - `shop_id` bigint UNSIGNED NOT NULL COMMENT '店铺ID(ec_shop.id)', - `pdd_auth_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '拼多多授权ID(open_pdd_auth.id)', + `shop_id` bigint UNSIGNED NOT NULL COMMENT '渠道店铺ID(channel_pdd_shop.id)', + `mall_id` bigint UNSIGNED NOT NULL COMMENT '拼多多店铺ID(mall_id)', `goods_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '拼多多商品ID(goods_id)', `goods_name` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品名称(goods_name)', `goods_quantity` int NOT NULL DEFAULT 0 COMMENT '商品总库存(goods_quantity)', @@ -31,14 +31,13 @@ CREATE TABLE `channel_pdd_goods` ( `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入库时间', `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', PRIMARY KEY (`id`) USING BTREE, - UNIQUE INDEX `uk_channel_pdd_goods_company_goods`(`company_id` ASC, `goods_id` ASC) USING BTREE, - INDEX `idx_channel_pdd_goods_shop`(`shop_id` ASC) USING BTREE, + UNIQUE INDEX `uk_channel_pdd_goods_shop_goods`(`shop_id` ASC, `goods_id` ASC) USING BTREE, + INDEX `idx_channel_pdd_goods_company_mall`(`company_id` ASC, `mall_id` ASC) USING BTREE, + INDEX `idx_channel_pdd_goods_mall_goods`(`mall_id` ASC, `goods_id` ASC) USING BTREE, INDEX `idx_channel_pdd_goods_onsale`(`is_onsale` ASC) USING BTREE, - INDEX `idx_channel_pdd_goods_auth`(`pdd_auth_id` ASC) USING BTREE, INDEX `idx_channel_pdd_goods_sync`(`last_sync_time` ASC) USING BTREE, CONSTRAINT `fk_channel_pdd_goods_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_channel_pdd_goods_shop` FOREIGN KEY (`shop_id`) REFERENCES `ec_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_channel_pdd_goods_auth` FOREIGN KEY (`pdd_auth_id`) REFERENCES `open_pdd_auth` (`id`) ON DELETE SET NULL ON UPDATE CASCADE + CONSTRAINT `fk_channel_pdd_goods_shop` FOREIGN KEY (`shop_id`) REFERENCES `channel_pdd_shop` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '拼多多-商品主表(SPU)' ROW_FORMAT = Dynamic; -- ======================================== diff --git a/ecom-dmb-backend/sql/migration/V20260822__channel_pdd_goods_and_shop_menu.sql b/ecom-dmb-backend/sql/migration/V20260822__channel_pdd_goods_and_shop_menu.sql new file mode 100644 index 00000000..7df6ef71 --- /dev/null +++ b/ecom-dmb-backend/sql/migration/V20260822__channel_pdd_goods_and_shop_menu.sql @@ -0,0 +1,52 @@ +-- 拼多多商品权限 + 渠道店铺菜单(商品表已手工建库,此处不建表) +-- sys_permission.id / sys_menu.id 均为 AUTO_INCREMENT,插入不写死主键,避免与存量 id 冲突 + +-- 权限(唯一约束:uk_code_parent(code, parent_id)) +INSERT INTO `sys_permission` (`parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT p.id, 'biz:pdd:goods:read', '拼多多商品查看', 'api', 1, '', 364 +FROM `sys_permission` p +WHERE p.`code` = 'biz:pdd' + AND NOT EXISTS (SELECT 1 FROM `sys_permission` x WHERE x.`code` = 'biz:pdd:goods:read') +LIMIT 1; + +INSERT INTO `sys_permission` (`parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT p.id, 'biz:pdd:goods:manage', '拼多多商品管理', 'api', 1, '同步/维护拼多多商品', 365 +FROM `sys_permission` p +WHERE p.`code` = 'biz:pdd' + AND NOT EXISTS (SELECT 1 FROM `sys_permission` x WHERE x.`code` = 'biz:pdd:goods:manage') +LIMIT 1; + +-- 菜单:拼多多店铺(渠道店列表 + 同步商品) +INSERT INTO `sys_menu` (`parent_id`, `super`, `name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) +SELECT m.id, 0, '拼多多店铺', '店铺', '/pdd/shop', '/channel/pdd/shop/index', '', 'lucide:store', 'menu', 1, 1, 0, 0 +FROM `sys_menu` m +WHERE m.`name` = '拼多多' + AND NOT EXISTS (SELECT 1 FROM `sys_menu` x WHERE x.`name` = '拼多多店铺') +LIMIT 1; + +-- 修正拼多多订单组件路径(views 已迁到 channel/pdd) +UPDATE `sys_menu` +SET `component` = '/channel/pdd/order/index', + `path` = '/pdd/order' +WHERE `name` = '拼多多订单' + AND (`component` LIKE '%ecommerce/pdd%' OR `component` = '/ecommerce/pdd/order/index'); + +INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`) +SELECT m.id, p.id +FROM `sys_menu` m +JOIN `sys_permission` p ON p.code IN ('biz:pdd:shop:read', 'biz:pdd:shop:manage', 'biz:pdd:goods:read', 'biz:pdd:goods:manage') +WHERE m.name = '拼多多店铺'; + +-- 菜单:拼多多商品 +INSERT INTO `sys_menu` (`parent_id`, `super`, `name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) +SELECT m.id, 0, '拼多多商品', '商品', '/pdd/goods', '/channel/pdd/goods/index', '', 'lucide:package', 'menu', 1, 1, 0, 2 +FROM `sys_menu` m +WHERE m.`name` = '拼多多' + AND NOT EXISTS (SELECT 1 FROM `sys_menu` x WHERE x.`name` = '拼多多商品') +LIMIT 1; + +INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`) +SELECT m.id, p.id +FROM `sys_menu` m +JOIN `sys_permission` p ON p.code IN ('biz:pdd:goods:read', 'biz:pdd:goods:manage') +WHERE m.name = '拼多多商品'; diff --git a/ecom-dmb-backend/sql/migration/V20260823__channel_pdd_goods_menu.sql b/ecom-dmb-backend/sql/migration/V20260823__channel_pdd_goods_menu.sql new file mode 100644 index 00000000..e1a8d25b --- /dev/null +++ b/ecom-dmb-backend/sql/migration/V20260823__channel_pdd_goods_menu.sql @@ -0,0 +1,13 @@ +-- 拼多多商品菜单(幂等) +INSERT INTO `sys_menu` (`parent_id`, `super`, `name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) +SELECT m.id, 0, '拼多多商品', '商品', '/pdd/goods', '/channel/pdd/goods/index', '', 'lucide:package', 'menu', 1, 1, 0, 2 +FROM `sys_menu` m +WHERE m.`name` = '拼多多' + AND NOT EXISTS (SELECT 1 FROM `sys_menu` x WHERE x.`name` = '拼多多商品') +LIMIT 1; + +INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`) +SELECT m.id, p.id +FROM `sys_menu` m +JOIN `sys_permission` p ON p.code IN ('biz:pdd:goods:read', 'biz:pdd:goods:manage') +WHERE m.name = '拼多多商品'; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/controller/PddGoodsController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/controller/PddGoodsController.java index d63ae410..b1d27d6b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/controller/PddGoodsController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/controller/PddGoodsController.java @@ -12,6 +12,7 @@ import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.CreatePddGoodsDTO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.PddGoodsFilterDTO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.UpdatePddGoodsDTO; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsSyncResultVO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsVO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsService; @@ -67,4 +68,13 @@ public class PddGoodsController { PddGoodsVO vo = pddGoodsService.getPddGoodsDetail(id); return ApiResponse.success("获取成功", vo); } + + @Operation(summary = "同步商品", description = "按渠道店铺调用 pdd.goods.list.get,同步上架+下架商品及SKU到本地") + @PostMapping("/sync/{pddShopId}") + @RequirePermission(value = "biz:pdd:goods:manage", description = "同步拼多多商品", allowSuper = true) + public ApiResponse syncGoodsByPddShop( + @Parameter(description = "渠道店铺ID(channel_pdd_shop.id)") @PathVariable Long pddShopId) { + PddGoodsSyncResultVO result = pddGoodsService.syncGoodsByPddShop(pddShopId); + return ApiResponse.success("同步完成", result); + } } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/CreatePddGoodsDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/CreatePddGoodsDTO.java index d4f56ad3..417c920b 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/CreatePddGoodsDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/CreatePddGoodsDTO.java @@ -12,12 +12,13 @@ import java.util.List; @Schema(description = "创建拼多多商品DTO") public class CreatePddGoodsDTO { - @Schema(description = "店铺ID(ec_shop.id)", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "店铺ID不能为空") + @Schema(description = "渠道店铺ID(channel_pdd_shop.id)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "渠道店铺ID不能为空") private Long shopId; - @Schema(description = "拼多多授权ID") - private Long pddAuthId; + @Schema(description = "拼多多店铺ID(mall_id)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "mall_id不能为空") + private Long mallId; @Schema(description = "拼多多商品ID", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "商品ID不能为空") diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/PddGoodsFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/PddGoodsFilterDTO.java index c4faace7..caf79019 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/PddGoodsFilterDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/PddGoodsFilterDTO.java @@ -7,9 +7,12 @@ import lombok.Data; @Schema(description = "拼多多商品过滤DTO") public class PddGoodsFilterDTO { - @Schema(description = "店铺ID") + @Schema(description = "渠道店铺ID(channel_pdd_shop.id)") private Long shopId; + @Schema(description = "拼多多店铺ID(mall_id)") + private Long mallId; + @Schema(description = "商品名称") private String goodsName; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/UpdatePddGoodsDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/UpdatePddGoodsDTO.java index 614efd3f..b4402dd2 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/UpdatePddGoodsDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/UpdatePddGoodsDTO.java @@ -12,12 +12,13 @@ import java.util.List; @Schema(description = "更新拼多多商品DTO") public class UpdatePddGoodsDTO { - @Schema(description = "店铺ID(ec_shop.id)", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "店铺ID不能为空") + @Schema(description = "渠道店铺ID(channel_pdd_shop.id)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "渠道店铺ID不能为空") private Long shopId; - @Schema(description = "拼多多授权ID") - private Long pddAuthId; + @Schema(description = "拼多多店铺ID(mall_id)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "mall_id不能为空") + private Long mallId; @Schema(description = "拼多多商品ID", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "商品ID不能为空") diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/po/PddGoodsPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/po/PddGoodsPO.java index 522c04bb..bf22cd8a 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/po/PddGoodsPO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/po/PddGoodsPO.java @@ -15,11 +15,13 @@ public class PddGoodsPO { @TableField("company_id") private Long companyId; + /** 渠道店铺ID(channel_pdd_shop.id) */ @TableField("shop_id") private Long shopId; - @TableField("pdd_auth_id") - private Long pddAuthId; + /** 拼多多店铺 mall_id */ + @TableField("mall_id") + private Long mallId; @TableField("goods_id") private String goodsId; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/PddGoodsSyncResultVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/PddGoodsSyncResultVO.java new file mode 100644 index 00000000..c7992b2a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/PddGoodsSyncResultVO.java @@ -0,0 +1,36 @@ +package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(description = "拼多多商品同步结果") +public class PddGoodsSyncResultVO { + + @Schema(description = "渠道店铺ID") + private Long pddShopId; + + @Schema(description = "拼多多 mall_id") + private Long mallId; + + @Schema(description = "本次拉取并落库的商品数(去重后)") + private Integer syncedCount; + + @Schema(description = "新增数") + private Integer createdCount; + + @Schema(description = "更新数") + private Integer updatedCount; + + @Schema(description = "SKU 落库条数") + private Integer skuCount; + + @Schema(description = "调用列表接口页次数") + private Integer pageCount; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/PddGoodsVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/PddGoodsVO.java index ed49bec3..3f6ab787 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/PddGoodsVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/PddGoodsVO.java @@ -16,11 +16,11 @@ public class PddGoodsVO { @Schema(description = "公司ID") private Long companyId; - @Schema(description = "店铺ID") + @Schema(description = "渠道店铺ID(channel_pdd_shop.id)") private Long shopId; - @Schema(description = "拼多多授权ID") - private Long pddAuthId; + @Schema(description = "拼多多店铺ID(mall_id)") + private Long mallId; @Schema(description = "拼多多商品ID") private String goodsId; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsService.java index 2d76f3c5..9b1a8351 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsService.java @@ -7,6 +7,7 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.CreatePddGo import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.PddGoodsFilterDTO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.UpdatePddGoodsDTO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.po.PddGoodsPO; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsSyncResultVO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsVO; public interface PddGoodsService extends IService { @@ -20,4 +21,11 @@ public interface PddGoodsService extends IService { PageResultVO getPddGoodsPage(PageQueryDTO pageQueryDTO); PddGoodsVO getPddGoodsDetail(Long id); + + /** + * 按渠道店铺调用 pdd.goods.list.get 全量同步(上架+下架)到 channel_pdd_goods / sku。 + * + * @param pddShopId channel_pdd_shop.id + */ + PddGoodsSyncResultVO syncGoodsByPddShop(Long pddShopId); } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsServiceImpl.java index c9bc4b0a..92c0ad64 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsServiceImpl.java @@ -4,12 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +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.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.common.utils.BeanCopyUtils; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.mapper.PddAuthMapper; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.model.po.PddAuthPO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.mapper.PddGoodsMapper; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.mapper.PddGoodsSkuMapper; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.CreatePddGoodsDTO; @@ -19,22 +23,45 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.UpdatePddGo import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.po.PddGoodsPO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.po.PddGoodsSkuPO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsSkuVO; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsSyncResultVO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsVO; import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service.PddGoodsService; +import top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.goods.PddGoodsPopApiClient; +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.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; +@Slf4j @Service public class PddGoodsServiceImpl extends ServiceImpl implements PddGoodsService { + private static final int LIST_PAGE_SIZE = 100; + private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai"); + private final PddGoodsSkuMapper pddGoodsSkuMapper; + private final PddShopMapper pddShopMapper; + private final PddAuthMapper pddAuthMapper; + private final PddGoodsPopApiClient goodsPopApiClient; private final CurrentUserContext currentUserContext; - public PddGoodsServiceImpl(PddGoodsSkuMapper pddGoodsSkuMapper, CurrentUserContext currentUserContext) { + public PddGoodsServiceImpl(PddGoodsSkuMapper pddGoodsSkuMapper, + PddShopMapper pddShopMapper, + PddAuthMapper pddAuthMapper, + PddGoodsPopApiClient goodsPopApiClient, + CurrentUserContext currentUserContext) { this.pddGoodsSkuMapper = pddGoodsSkuMapper; + this.pddShopMapper = pddShopMapper; + this.pddAuthMapper = pddAuthMapper; + this.goodsPopApiClient = goodsPopApiClient; this.currentUserContext = currentUserContext; } @@ -44,7 +71,7 @@ public class PddGoodsServiceImpl extends ServiceImpl Long companyId = currentUserContext.getCurrentCompanyId(); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(PddGoodsPO::getCompanyId, companyId) + wrapper.eq(PddGoodsPO::getShopId, createPddGoodsDTO.getShopId()) .eq(PddGoodsPO::getGoodsId, createPddGoodsDTO.getGoodsId()); if (this.count(wrapper) > 0) { throw new BusinessException("该商品已存在"); @@ -71,12 +98,12 @@ public class PddGoodsServiceImpl extends ServiceImpl Long companyId = currentUserContext.getCurrentCompanyId(); PddGoodsPO existing = this.getById(id); - if (existing == null) { + if (existing == null || !companyId.equals(existing.getCompanyId())) { throw new BusinessException("商品不存在"); } LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(PddGoodsPO::getCompanyId, companyId) + wrapper.eq(PddGoodsPO::getShopId, updatePddGoodsDTO.getShopId()) .eq(PddGoodsPO::getGoodsId, updatePddGoodsDTO.getGoodsId()) .ne(PddGoodsPO::getId, id); if (this.count(wrapper) > 0) { @@ -100,14 +127,15 @@ public class PddGoodsServiceImpl extends ServiceImpl skus.forEach(pddGoodsSkuMapper::insert); } - return convertToVO(goods); + return convertToVO(this.getById(id)); } @Override @Transactional public void deletePddGoods(Long id) { + Long companyId = currentUserContext.getCurrentCompanyId(); PddGoodsPO existing = this.getById(id); - if (existing == null) { + if (existing == null || !companyId.equals(existing.getCompanyId())) { throw new BusinessException("商品不存在"); } @@ -130,6 +158,9 @@ public class PddGoodsServiceImpl extends ServiceImpl if (filter.getShopId() != null) { wrapper.eq(PddGoodsPO::getShopId, filter.getShopId()); } + if (filter.getMallId() != null) { + wrapper.eq(PddGoodsPO::getMallId, filter.getMallId()); + } if (filter.getGoodsName() != null && !filter.getGoodsName().isEmpty()) { wrapper.like(PddGoodsPO::getGoodsName, filter.getGoodsName()); } @@ -143,13 +174,14 @@ public class PddGoodsServiceImpl extends ServiceImpl wrapper.eq(PddGoodsPO::getIsMoreSku, filter.getIsMoreSku()); } - wrapper.orderByDesc(PddGoodsPO::getCreateTime); + wrapper.orderByDesc(PddGoodsPO::getIsOnsale) + .orderByDesc(PddGoodsPO::getPddCreatedAt); IPage page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); IPage result = this.page(page, wrapper); List voList = result.getRecords().stream() - .map(this::convertToVO) + .map(this::convertToBriefVO) .collect(Collectors.toList()); return PageResultVO.create(voList, result.getTotal(), @@ -158,13 +190,193 @@ public class PddGoodsServiceImpl extends ServiceImpl @Override public PddGoodsVO getPddGoodsDetail(Long id) { + Long companyId = currentUserContext.getCurrentCompanyId(); PddGoodsPO goods = this.getById(id); - if (goods == null) { + if (goods == null || !companyId.equals(goods.getCompanyId())) { throw new BusinessException("商品不存在"); } return convertToVO(goods); } + @Override + public PddGoodsSyncResultVO syncGoodsByPddShop(Long pddShopId) { + Long companyId = currentUserContext.getCurrentCompanyId(); + if (pddShopId == null) { + throw new BusinessException("渠道店铺ID不能为空"); + } + + PddShopPO pddShop = pddShopMapper.selectById(pddShopId); + if (pddShop == null || !companyId.equals(pddShop.getCompanyId())) { + throw new BusinessException("拼多多渠道店铺不存在"); + } + if (pddShop.getPddAuthId() == null) { + throw new BusinessException("该渠道店铺尚未绑定授权,请先完成授权"); + } + PddAuthPO auth = pddAuthMapper.selectById(pddShop.getPddAuthId()); + if (auth == null || auth.getStatus() == null || auth.getStatus() != 1 + || !StringUtils.hasText(auth.getAccessToken())) { + throw new BusinessException("拼多多授权无效或已失效,请重新授权"); + } + + Long mallId = pddShop.getMallId(); + String accessToken = auth.getAccessToken(); + LocalDateTime syncTime = LocalDateTime.now(); + + int pageCount = 0; + int created = 0; + int updated = 0; + int skuCount = 0; + Set seenGoodsIds = new HashSet<>(); + + // 列表接口 is_onsale / outer_id / goods_name 三选一,需分别拉上架与下架 + for (int isOnsale : List.of(1, 0)) { + int page = 1; + Integer total = null; + while (true) { + PddGoodsPopApiClient.GoodsListPage listPage; + try { + listPage = goodsPopApiClient.fetchGoodsList( + mallId, accessToken, page, LIST_PAGE_SIZE, isOnsale); + } catch (BusinessException e) { + throw e; + } catch (Exception e) { + log.error("同步拼多多商品失败 pddShopId={} mallId={} isOnsale={} page={}", + pddShopId, mallId, isOnsale, page, e); + throw new BusinessException("同步拼多多商品失败: " + e.getMessage()); + } + pageCount++; + if (total == null) { + total = listPage.totalCount(); + } + List items = listPage.goodsList(); + if (items == null || items.isEmpty()) { + break; + } + for (PddGoodsPopApiClient.GoodsListItem item : items) { + if (item.goodsId() == null) { + continue; + } + String goodsId = String.valueOf(item.goodsId()); + if (!seenGoodsIds.add(goodsId)) { + continue; + } + UpsertResult ur = upsertGoodsItem(companyId, pddShopId, mallId, item, syncTime); + if (ur.created()) { + created++; + } else { + updated++; + } + skuCount += ur.skuCount(); + } + if (items.size() < LIST_PAGE_SIZE) { + break; + } + if (total != null && page * LIST_PAGE_SIZE >= total) { + break; + } + page++; + } + } + + return PddGoodsSyncResultVO.builder() + .pddShopId(pddShopId) + .mallId(mallId) + .syncedCount(seenGoodsIds.size()) + .createdCount(created) + .updatedCount(updated) + .skuCount(skuCount) + .pageCount(pageCount) + .build(); + } + + private UpsertResult upsertGoodsItem(Long companyId, + Long pddShopId, + Long mallId, + PddGoodsPopApiClient.GoodsListItem item, + LocalDateTime syncTime) { + String goodsId = String.valueOf(item.goodsId()); + PddGoodsPO existing = this.getOne(new LambdaQueryWrapper() + .eq(PddGoodsPO::getShopId, pddShopId) + .eq(PddGoodsPO::getGoodsId, goodsId) + .last("LIMIT 1")); + + boolean created = existing == null; + PddGoodsPO goods = existing != null ? existing : new PddGoodsPO(); + goods.setCompanyId(companyId); + goods.setShopId(pddShopId); + goods.setMallId(mallId); + goods.setGoodsId(goodsId); + goods.setGoodsName(StringUtils.hasText(item.goodsName()) ? item.goodsName() : goodsId); + goods.setGoodsQuantity(toInt(item.goodsQuantity())); + goods.setGoodsReserveQuantity(toInt(item.goodsReserveQuantity())); + goods.setImageUrl(blankToNull(item.imageUrl())); + goods.setThumbUrl(blankToNull(item.thumbUrl())); + goods.setIsMoreSku(item.isMoreSku() != null ? item.isMoreSku() : 0); + goods.setIsOnsale(item.isOnsale() != null ? item.isOnsale() : 0); + goods.setPddCreatedAt(epochSecToLocalDateTime(item.createdAtEpochSec())); + goods.setRawResponse(item.rawJson()); + goods.setLastSyncTime(syncTime); + + if (created) { + this.save(goods); + } else { + this.updateById(goods); + pddGoodsSkuMapper.delete(new LambdaQueryWrapper() + .eq(PddGoodsSkuPO::getGoodsRowId, goods.getId())); + } + + int skuInserted = 0; + if (item.skuList() != null) { + for (PddGoodsPopApiClient.GoodsListSku sku : item.skuList()) { + if (sku == null || sku.skuId() == null) { + continue; + } + PddGoodsSkuPO po = new PddGoodsSkuPO(); + po.setGoodsRowId(goods.getId()); + po.setCompanyId(companyId); + po.setGoodsId(goodsId); + po.setSkuId(String.valueOf(sku.skuId())); + po.setSpec(blankToNull(sku.spec())); + po.setSpecDetails(blankToNull(sku.specDetailsJson())); + po.setSkuQuantity(toInt(sku.skuQuantity())); + po.setReserveQuantity(toInt(sku.reserveQuantity())); + po.setIsSkuOnsale(sku.isSkuOnsale() != null ? sku.isSkuOnsale() : 0); + po.setOuterGoodsId(blankToNull(sku.outerGoodsId())); + po.setOuterId(blankToNull(sku.outerId())); + pddGoodsSkuMapper.insert(po); + skuInserted++; + } + } + return new UpsertResult(created, skuInserted); + } + + private record UpsertResult(boolean created, int skuCount) { + } + + private static Integer toInt(Long v) { + if (v == null) { + return 0; + } + if (v > Integer.MAX_VALUE) { + return Integer.MAX_VALUE; + } + if (v < Integer.MIN_VALUE) { + return Integer.MIN_VALUE; + } + return v.intValue(); + } + + private static String blankToNull(String s) { + return StringUtils.hasText(s) ? s.trim() : null; + } + + private static LocalDateTime epochSecToLocalDateTime(Long epochSec) { + if (epochSec == null || epochSec <= 0) { + return null; + } + return LocalDateTime.ofInstant(Instant.ofEpochSecond(epochSec), ZONE); + } + private PddGoodsSkuPO convertToSkuPO(CreatePddGoodsSkuDTO dto, Long goodsRowId, Long companyId) { PddGoodsSkuPO sku = new PddGoodsSkuPO(); BeanCopyUtils.copyProperties(dto, sku); @@ -173,6 +385,13 @@ public class PddGoodsServiceImpl extends ServiceImpl return sku; } + private PddGoodsVO convertToBriefVO(PddGoodsPO goods) { + PddGoodsVO vo = new PddGoodsVO(); + BeanCopyUtils.copyProperties(goods, vo); + vo.setSkus(null); + return vo; + } + private PddGoodsVO convertToVO(PddGoodsPO goods) { PddGoodsVO vo = new PddGoodsVO(); BeanCopyUtils.copyProperties(goods, vo); 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 68faf2f7..df89f419 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 @@ -15,6 +15,7 @@ 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 MALL_INFO_GET = "pdd.mall.info.get"; diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/goods/PddGoodsPopApiClient.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/goods/PddGoodsPopApiClient.java index 356856bc..945cf873 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/goods/PddGoodsPopApiClient.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/pop/goods/PddGoodsPopApiClient.java @@ -1,8 +1,10 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.goods; +import com.fasterxml.jackson.databind.ObjectMapper; import com.pdd.pop.sdk.http.api.pop.request.PddGoodsInformationGetRequest; +import com.pdd.pop.sdk.http.api.pop.request.PddGoodsListGetRequest; import com.pdd.pop.sdk.http.api.pop.response.PddGoodsInformationGetResponse; -import lombok.RequiredArgsConstructor; +import com.pdd.pop.sdk.http.api.pop.response.PddGoodsListGetResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; @@ -14,14 +16,19 @@ import java.util.Collections; import java.util.List; /** - * 商品域 POP:{@value PddPopApiTypes#GOODS_INFORMATION_GET}。 + * 商品域 POP:{@value PddPopApiTypes#GOODS_INFORMATION_GET}、{@value PddPopApiTypes#GOODS_LIST_GET}。 */ @Slf4j @Component -@RequiredArgsConstructor public class PddGoodsPopApiClient { private final PddPopInvokeSupport invokeSupport; + private final ObjectMapper objectMapper; + + public PddGoodsPopApiClient(PddPopInvokeSupport invokeSupport, ObjectMapper objectMapper) { + this.invokeSupport = invokeSupport; + this.objectMapper = objectMapper; + } public GoodsDetail fetchGoodsInformation(Long mallId, String accessToken, Long goodsId) throws Exception { if (goodsId == null) { @@ -32,11 +39,78 @@ public class PddGoodsPopApiClient { request.setGoodsId(goodsId); PddGoodsInformationGetResponse response = client.syncInvoke(request, accessToken); invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_INFORMATION_GET); - return map(response); + return mapInformation(response); }); } - private static GoodsDetail map(PddGoodsInformationGetResponse response) { + /** + * 商品列表分页。isOnsale:0 下架 / 1 上架;与 outer_id、goods_name 三选一,优先级 is_onsale 最高。 + */ + public GoodsListPage fetchGoodsList(Long mallId, + String accessToken, + int page, + int pageSize, + Integer isOnsale) throws Exception { + return invokeSupport.invoke(PddPopApiTypes.GOODS_LIST_GET, mallId, client -> { + PddGoodsListGetRequest request = new PddGoodsListGetRequest(); + request.setPage(Math.max(page, 1)); + request.setPageSize(Math.min(Math.max(pageSize, 1), 100)); + if (isOnsale != null) { + request.setIsOnsale(isOnsale); + } + PddGoodsListGetResponse response = client.syncInvoke(request, accessToken); + invokeSupport.assertNoError(response, PddPopApiTypes.GOODS_LIST_GET); + return mapList(response); + }); + } + + private GoodsListPage mapList(PddGoodsListGetResponse response) { + if (response == null || response.getGoodsListGetResponse() == null) { + return new GoodsListPage(0, List.of()); + } + var body = response.getGoodsListGetResponse(); + int total = body.getTotalCount() != null ? body.getTotalCount() : 0; + List items = new ArrayList<>(); + if (body.getGoodsList() != null) { + for (var g : body.getGoodsList()) { + if (g == null || g.getGoodsId() == null) { + continue; + } + List skus = new ArrayList<>(); + if (g.getSkuList() != null) { + for (var s : g.getSkuList()) { + if (s == null || s.getSkuId() == null) { + continue; + } + skus.add(new GoodsListSku( + s.getSkuId(), + s.getSpec(), + s.getSkuQuantity(), + s.getReserveQuantity(), + s.getIsSkuOnsale(), + s.getOuterGoodsId(), + s.getOuterId(), + toJsonQuietly(s.getSpecDetails()))); + } + } + items.add(new GoodsListItem( + g.getGoodsId(), + g.getGoodsName(), + g.getGoodsQuantity(), + g.getGoodsReserveQuantity(), + g.getImageUrl(), + g.getThumbUrl(), + g.getIsMoreSku(), + g.getIsOnsale(), + g.getCreatedAt(), + Collections.unmodifiableList(skus), + toJsonQuietly(g))); + } + } + return new GoodsListPage(total, Collections.unmodifiableList(items)); + } + + private GoodsDetail mapInformation(PddGoodsInformationGetResponse response) { if (response == null || response.getGoodsInfoGetResponse() == null || response.getGoodsInfoGetResponse().getGoodsInfo() == null) { return null; @@ -65,6 +139,46 @@ public class PddGoodsPopApiClient { Collections.unmodifiableList(skus)); } + private String toJsonQuietly(Object value) { + if (value == null) { + return null; + } + try { + return objectMapper.writeValueAsString(value); + } catch (Exception e) { + log.warn("序列化拼多多商品字段失败: {}", e.getMessage()); + return null; + } + } + + public record GoodsListPage(int totalCount, List goodsList) { + } + + public record GoodsListItem( + Long goodsId, + String goodsName, + Long goodsQuantity, + Long goodsReserveQuantity, + String imageUrl, + String thumbUrl, + Integer isMoreSku, + Integer isOnsale, + Long createdAtEpochSec, + List skuList, + String rawJson) { + } + + public record GoodsListSku( + Long skuId, + String spec, + Long skuQuantity, + Long reserveQuantity, + Integer isSkuOnsale, + String outerGoodsId, + String outerId, + String specDetailsJson) { + } + public record GoodsDetail( Long goodsId, String goodsName, diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/impl/PddShopServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/impl/PddShopServiceImpl.java index f3928eda..daa0f050 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/impl/PddShopServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/shop/service/impl/PddShopServiceImpl.java @@ -143,7 +143,7 @@ public class PddShopServiceImpl extends ServiceImpl im IPage page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); IPage result = this.page(page, wrapper); - List voList = toBriefVoList(result.getRecords()); + List voList = toVoList(result.getRecords(), true); return PageResultVO.create(voList, result.getTotal(), (int) pageQueryDTO.getPage(), (int) pageQueryDTO.getPageSize()); diff --git a/ecom-dmb-backend/src/main/resources/sql/init/sys_seed.sql b/ecom-dmb-backend/src/main/resources/sql/init/sys_seed.sql index d2f0fef3..6d93cbda 100644 --- a/ecom-dmb-backend/src/main/resources/sql/init/sys_seed.sql +++ b/ecom-dmb-backend/src/main/resources/sql/init/sys_seed.sql @@ -121,6 +121,14 @@ INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status SELECT 3603, (SELECT id FROM `sys_permission` WHERE `code` = 'biz:pdd' LIMIT 1), 'biz:pdd:shop:manage', '拼多多店铺管理', 'api', 1, '', 363 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `code` = 'biz:pdd:shop:manage'); +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3610, (SELECT id FROM `sys_permission` WHERE `code` = 'biz:pdd' LIMIT 1), 'biz:pdd:goods:read', '拼多多商品查看', 'api', 1, '', 364 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `code` = 'biz:pdd:goods:read'); + +INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) +SELECT 3611, (SELECT id FROM `sys_permission` WHERE `code` = 'biz:pdd' LIMIT 1), 'biz:pdd:goods:manage', '拼多多商品管理', 'api', 1, '同步/维护拼多多商品', 365 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `code` = 'biz:pdd:goods:manage'); + INSERT INTO `sys_permission` (`id`, `parent_id`, `code`, `name`, `type`, `status`, `remark`, `sort_order`) SELECT 4100, (SELECT id FROM `sys_permission` WHERE `code` = 'MODULE:data' LIMIT 1), 'data:import-group', '数据导入', 'module', 1, '', 400 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_permission` WHERE `code` = 'data:import-group'); @@ -374,9 +382,17 @@ SELECT 12030, NULL, 0, '拼多多', '拼多多', '/pdd', '', '', 'arcticons:pind FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `name` = '拼多多'); INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) -SELECT 12032, (SELECT id FROM `sys_menu` WHERE `name` = '拼多多' LIMIT 1), 0, '拼多多订单', '订单', '/pdd/order', '/ecommerce/pdd/order/index', '', 'lucide:shopping-bag', 'menu', 1, 1, 0, 1 +SELECT 12032, (SELECT id FROM `sys_menu` WHERE `name` = '拼多多' LIMIT 1), 0, '拼多多订单', '订单', '/pdd/order', '/channel/pdd/order/index', '', 'lucide:shopping-bag', 'menu', 1, 1, 0, 1 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `name` = '拼多多订单'); +INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) +SELECT 12033, (SELECT id FROM `sys_menu` WHERE `name` = '拼多多' LIMIT 1), 0, '拼多多店铺', '店铺', '/pdd/shop', '/channel/pdd/shop/index', '', 'lucide:store', 'menu', 1, 1, 0, 0 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `name` = '拼多多店铺'); + +INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) +SELECT 12034, (SELECT id FROM `sys_menu` WHERE `name` = '拼多多' LIMIT 1), 0, '拼多多商品', '商品', '/pdd/goods', '/channel/pdd/goods/index', '', 'lucide:package', 'menu', 1, 1, 0, 2 +FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `name` = '拼多多商品'); + INSERT INTO `sys_menu` (`id`, `parent_id`, `super`, `name`, `title`, `path`, `component`, `redirect`, `icon`, `type`, `visible`, `status`, `keep_alive`, `order`) SELECT 12031, NULL, 0, '淘宝', '淘宝', '', '', '', 'ri:taobao-fill', 'menu', 1, 1, 0, 0 FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `name` = '淘宝'); @@ -516,6 +532,12 @@ SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'ecom INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`) SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code IN ('biz:pdd:order:read', 'biz:pdd:order:manage', 'biz:pdd:order:sync') WHERE m.name = '拼多多订单'; +INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`) +SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code IN ('biz:pdd:shop:read', 'biz:pdd:shop:manage', 'biz:pdd:goods:read', 'biz:pdd:goods:manage') WHERE m.name = '拼多多店铺'; + +INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`) +SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code IN ('biz:pdd:goods:read', 'biz:pdd:goods:manage') WHERE m.name = '拼多多商品'; + INSERT IGNORE INTO `sys_menu_permission` (`menu_id`, `permission_id`) SELECT m.id, p.id FROM `sys_menu` m JOIN `sys_permission` p ON p.code LIKE 'ecom:product:%' WHERE m.name = '商品管理'; 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 new file mode 100644 index 00000000..3d708e9b --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts @@ -0,0 +1,32 @@ +import type { PageQueryDTO, PageResultVO } from '#/types/common'; + +import { requestClient } from '#/api/request'; + +import type { PddGoodsDTO, PddGoodsVO } from './types'; + +/** 分页查询拼多多渠道商品 */ +export async function getPddGoodsPageApi( + params: PageQueryDTO, +) { + return requestClient.post>( + '/channel/pdd/goods/list', + params, + ); +} + +/** 拼多多商品详情(含 SKU) */ +export async function getPddGoodsDetailApi(id: number) { + return requestClient.get(`/channel/pdd/goods/detail/${id}`); +} + +/** 删除拼多多商品及 SKU */ +export async function deletePddGoodsApi(id: number) { + return requestClient.delete(`/channel/pdd/goods/delete/${id}`); +} + +/** 按渠道店铺同步商品 */ +export async function syncPddGoodsByShopApi(pddShopId: number) { + return requestClient.post( + `/channel/pdd/goods/sync/${pddShopId}`, + ); +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/index.ts new file mode 100644 index 00000000..daf76d51 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/index.ts @@ -0,0 +1,2 @@ +export * from './apis'; +export * from './types'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/index.ts new file mode 100644 index 00000000..a582b3ae --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/index.ts @@ -0,0 +1,59 @@ +export namespace PddGoodsDTO { + export interface Filters { + /** 渠道店铺ID(channel_pdd_shop.id) */ + shopId?: number; + mallId?: number; + goodsName?: string; + goodsId?: string; + /** 0否 1是 */ + isOnsale?: number; + /** 0否 1是 */ + isMoreSku?: number; + } +} + +export namespace PddGoodsVO { + export interface Sku { + id?: number; + goodsRowId?: number; + goodsId?: string; + skuId?: string; + spec?: string; + specDetails?: string; + skuQuantity?: number; + reserveQuantity?: number; + isSkuOnsale?: number; + outerGoodsId?: string; + outerId?: string; + } + + export interface Info { + id: number; + companyId?: number; + shopId?: number; + mallId?: number; + goodsId?: string; + goodsName?: string; + goodsQuantity?: number; + goodsReserveQuantity?: number; + imageUrl?: string; + thumbUrl?: string; + isMoreSku?: number; + isOnsale?: number; + pddCreatedAt?: string; + lastSyncTime?: string; + createTime?: string; + updateTime?: string; + skus?: Sku[]; + } + + export interface SyncResult { + pddShopId: number; + mallId?: number; + syncedCount?: number; + createdCount?: number; + updatedCount?: number; + skuCount?: number; + pageCount?: number; + } +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/apis.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/apis.ts index 80561849..359c378b 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/apis.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/apis.ts @@ -1,10 +1,20 @@ -import type { PddShopInfo } from '#/api/ec/shop/types'; +import type { PageQueryDTO, PageResultVO } from '#/types/common'; import { requestClient } from '#/api/request'; -/** - * 拼多多渠道店铺详情(含授权信息,不含 token) - */ +import type { PddShopDTO, PddShopVO } from './types'; + +/** 分页查询拼多多渠道店铺 */ +export async function getPddShopPageApi( + params: PageQueryDTO, +) { + return requestClient.post>( + '/channel/pdd/shop/list', + params, + ); +} + +/** 拼多多渠道店铺详情(含授权信息,不含 token) */ export async function getPddShopDetailApi(id: number) { - return requestClient.get(`/channel/pdd/shop/detail/${id}`); + return requestClient.get(`/channel/pdd/shop/detail/${id}`); } diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/index.ts index 3cefd991..daf76d51 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/index.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/index.ts @@ -1 +1,2 @@ export * from './apis'; +export * from './types'; diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/types/index.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/types/index.ts new file mode 100644 index 00000000..3806b445 --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/shop/types/index.ts @@ -0,0 +1,39 @@ +export namespace PddShopDTO { + export interface Filters { + mallName?: string; + merchantType?: number; + mallCharacter?: number; + pddAuthId?: number; + } +} + +export namespace PddShopVO { + export interface AuthInfo { + id: number; + companyId?: number; + ownerId?: string; + expiresAt?: string; + refreshTokenExpiresAt?: string; + scope?: string; + /** 0失效 1正常 2已撤销 */ + status?: number; + createTime?: string; + updateTime?: string; + } + + export interface Info { + id: number; + companyId?: number; + pddAuthId?: null | number; + auth?: AuthInfo | null; + mallId?: number; + mallName?: string; + logo?: string; + mallDesc?: string; + merchantType?: number; + mallCharacter?: number; + lastSyncTime?: string; + createTime?: string; + updateTime?: string; + } +} diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsDetailDrawer.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsDetailDrawer.vue new file mode 100644 index 00000000..421d6c1e --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsDetailDrawer.vue @@ -0,0 +1,150 @@ + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/index.vue new file mode 100644 index 00000000..64510fbc --- /dev/null +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/index.vue @@ -0,0 +1,387 @@ + + + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/list/components/PddShopDetailModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/shop/components/PddShopDetailModal.vue similarity index 91% rename from ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/list/components/PddShopDetailModal.vue rename to ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/shop/components/PddShopDetailModal.vue index b5e7a06e..8f7a9cb3 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ec/shop/list/components/PddShopDetailModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/shop/components/PddShopDetailModal.vue @@ -1,5 +1,5 @@