From d2e887e61a56004eb50bec8923381d850666c2bf Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Fri, 11 Sep 2026 22:24:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=91=E5=B8=83=E5=95=86=E5=93=81?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E7=B1=BB=E7=9B=AE=E5=90=8E=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=BA=97=E9=93=BA=E5=8F=91=E5=B8=83=E6=9D=83=E5=B9=B6=E6=8F=90?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PddGoodsPublishController.java | 8 ++ .../publish/PddPublishCatAuthQueryDTO.java | 21 ++++ .../model/vo/publish/PddPublishCatAuthVO.java | 18 ++++ .../goods/service/PddGoodsPublishService.java | 5 + .../impl/PddGoodsPublishServiceImpl.java | 39 ++++++++ .../src/api/channel/pdd/goods/apis.ts | 10 ++ .../api/channel/pdd/goods/types/publish.ts | 12 +++ .../goods/components/PddGoodsPublishModal.vue | 95 ++++++++++++++++++- 8 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddPublishCatAuthQueryDTO.java create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/publish/PddPublishCatAuthVO.java diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/controller/PddGoodsPublishController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/controller/PddGoodsPublishController.java index c9fb3213..c077fcfa 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/controller/PddGoodsPublishController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/controller/PddGoodsPublishController.java @@ -8,6 +8,7 @@ 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.PddPublishCatAuthQueryDTO; 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; @@ -16,6 +17,7 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.Pdd 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.PddPublishCatAuthVO; 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; @@ -46,6 +48,12 @@ public class PddGoodsPublishController { return ApiResponse.success("获取成功", publishService.listAuthCats(query)); } + @PostMapping("/meta/check-cat-auth") + @RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true) + public ApiResponse checkCatAuth(@Valid @RequestBody PddPublishCatAuthQueryDTO query) { + return ApiResponse.success("校验成功", publishService.checkCatAuth(query)); + } + @PostMapping("/meta/logistics-templates") @RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true) public ApiResponse listLogistics( diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddPublishCatAuthQueryDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddPublishCatAuthQueryDTO.java new file mode 100644 index 00000000..e3e003f0 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/dto/publish/PddPublishCatAuthQueryDTO.java @@ -0,0 +1,21 @@ +package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish; + +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +import java.util.List; + +/** + * 校验类目路径是否在当前店铺可发布授权树内。 + */ +@Data +public class PddPublishCatAuthQueryDTO { + + @NotNull(message = "渠道店铺ID不能为空") + private Long pddShopId; + + /** 根 → 叶的 catId 路径 */ + @NotEmpty(message = "类目路径不能为空") + private List catPath; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/publish/PddPublishCatAuthVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/publish/PddPublishCatAuthVO.java new file mode 100644 index 00000000..4f75ec7b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/model/vo/publish/PddPublishCatAuthVO.java @@ -0,0 +1,18 @@ +package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.publish; + +import lombok.Data; + +/** + * 类目发布授权校验结果。 + */ +@Data +public class PddPublishCatAuthVO { + + /** 整条路径是否均在授权树中 */ + private boolean authorized; + + /** 未授权时失败的那一级 catId */ + private Long failedCatId; + + private String message; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsPublishService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsPublishService.java index 81d9b0d5..db88b70a 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsPublishService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/PddGoodsPublishService.java @@ -2,6 +2,7 @@ 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.PddPublishCatAuthQueryDTO; 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; @@ -9,6 +10,7 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.Pdd 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.PddPublishCatAuthVO; 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; @@ -25,6 +27,9 @@ public interface PddGoodsPublishService { List listAuthCats(PddPublishShopCatQueryDTO query); + /** 按路径校验当前店铺是否有权发布该类目 */ + PddPublishCatAuthVO checkCatAuth(PddPublishCatAuthQueryDTO query); + PddPublishLogisticsPageVO listLogisticsTemplates(PddPublishLogisticsQueryDTO query); PddPublishCostTemplateDetailVO getCostTemplateDetail(PddPublishCostTemplateDetailQueryDTO query); diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java index 2b0c4473..76af10c2 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/channel/pdd/goods/service/impl/PddGoodsPublishServiceImpl.java @@ -13,6 +13,7 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.Pdd 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.PddPublishCatAuthQueryDTO; 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; @@ -23,6 +24,7 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.publish.Pdd 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.PddPublishCatAuthVO; 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; @@ -117,6 +119,43 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService { } } + @Override + public PddPublishCatAuthVO checkCatAuth(PddPublishCatAuthQueryDTO query) { + ShopAuth ctx = requireShopAuth(query.getPddShopId()); + PddPublishCatAuthVO vo = new PddPublishCatAuthVO(); + List path = query.getCatPath().stream() + .filter(Objects::nonNull) + .filter(id -> id > 0) + .collect(Collectors.toList()); + if (path.isEmpty()) { + vo.setAuthorized(false); + vo.setMessage("类目路径无效"); + return vo; + } + try { + long parent = 0L; + for (Long catId : path) { + List children = + publishPopApiClient.listAuthorizationCats(ctx.mallId(), ctx.accessToken(), parent); + boolean hit = children.stream().anyMatch(c -> Objects.equals(c.catId(), catId)); + if (!hit) { + vo.setAuthorized(false); + vo.setFailedCatId(catId); + vo.setMessage("当前店铺无权发布该类目(授权类目树中不存在)"); + return vo; + } + parent = catId; + } + vo.setAuthorized(true); + vo.setMessage("当前店铺有权发布该类目"); + return vo; + } catch (BusinessException e) { + throw e; + } catch (Exception e) { + throw wrapPop("校验类目发布权限失败", e); + } + } + @Override public PddPublishLogisticsPageVO listLogisticsTemplates(PddPublishLogisticsQueryDTO query) { ShopAuth ctx = requireShopAuth(query.getPddShopId()); diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts index 8d4afa0d..e74f2f0e 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/apis.ts @@ -41,6 +41,16 @@ export async function listPddPublishCatsApi( ); } +/** 校验类目路径是否有发布权 */ +export async function checkPddPublishCatAuthApi( + data: PddGoodsPublishDTO.CatAuthQuery, +) { + return requestClient.post( + '/channel/pdd/goods/publish/meta/check-cat-auth', + data, + ); +} + /** 运费模板列表 */ export async function listPddPublishLogisticsApi( data: PddGoodsPublishDTO.LogisticsQuery, diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish.ts b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish.ts index be33acaf..2386ce3a 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/channel/pdd/goods/types/publish.ts @@ -63,6 +63,12 @@ export namespace PddGoodsPublishDTO { parentCatId?: number; } + export interface CatAuthQuery { + pddShopId: number; + /** 根 → 叶 */ + catPath: number[]; + } + export interface LogisticsQuery { pddShopId: number; page?: number; @@ -104,6 +110,12 @@ export namespace PddGoodsPublishVO { leaf?: boolean; } + export interface CatAuth { + authorized: boolean; + failedCatId?: number; + message?: string; + } + export interface LogisticsPage { totalCount?: number; templates?: LogisticsTemplate[]; diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue index 0833a844..1783dddb 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/channel/pdd/goods/components/PddGoodsPublishModal.vue @@ -35,6 +35,7 @@ import { } from 'ant-design-vue'; import { + checkPddPublishCatAuthApi, createPddPublishSpecIdApi, getPddPublishCatTemplateApi, getPddPublishLogisticsTemplateDetailApi, @@ -388,6 +389,11 @@ const catDegradeHint = computed(() => { return '本地类目未就绪:已降级为拼多多授权类目逐级加载;搜索仅匹配已展开节点。同步成功后可跨层搜索'; }); +/** 当前选中叶子是否有发布权;null=未校验/不适用 */ +const catAuthAuthorized = ref(null); +const catAuthMessage = ref(''); +const catAuthChecking = ref(false); + const skuSelectOptions = computed(() => skuOptions.value.map((s) => ({ label: `${s.productName} / ${s.name}${s.skuCode ? ` (${s.skuCode})` : ''}`, @@ -411,7 +417,7 @@ function mapLocalCatNode(c: { leaf?: boolean; }): CatCascaderNode { return { - label: c.catName, + label: c.catName || `类目${c.catId}`, value: c.catId, isLeaf: !!c.leaf, }; @@ -440,6 +446,38 @@ async function fetchCatChildren(parentCatId: number): Promise return list.map(mapPopCatNode); } +/** 选中叶子后再校验发布权(不在选择器展开时实时标权) */ +async function refreshCatAuth(fullPath: number[]) { + catAuthAuthorized.value = null; + catAuthMessage.value = ''; + if (!form.pddShopId || !fullPath.length) { + return; + } + // 降级已是授权树,展开选中默认有权 + if (!localCatReady.value) { + catAuthAuthorized.value = true; + return; + } + catAuthChecking.value = true; + try { + const res = await checkPddPublishCatAuthApi({ + pddShopId: form.pddShopId, + catPath: fullPath, + }); + catAuthAuthorized.value = !!res?.authorized; + catAuthMessage.value = + res?.message || + (res?.authorized + ? '当前店铺有权发布该类目' + : '当前店铺无权发布该类目'); + } catch (e: any) { + catAuthAuthorized.value = null; + catAuthMessage.value = e?.message || '类目权限校验失败'; + } finally { + catAuthChecking.value = false; + } +} + /** 展开时按需加载子类目(本地库或拼多多接口) */ const catLoadData: CascaderProps['loadData'] = async (selectedOptions) => { // 跨层搜索结果为扁平叶子,不走懒加载 @@ -577,7 +615,11 @@ async function applyCatSelection(catId: number, pathIds?: string, pathLabel?: st specAxes.value = []; specCatalog.value = []; specValueDraftByRow.value = {}; + await refreshCatAuth(path); if (!form.pddShopId || !form.catId) return; + if (catAuthAuthorized.value === false) { + return; + } try { const [tpl, specs] = await Promise.all([ getPddPublishCatTemplateApi({ @@ -678,6 +720,8 @@ watch( form.catPath = []; form.catId = undefined; selectedCatPathLabel.value = ''; + catAuthAuthorized.value = null; + catAuthMessage.value = ''; form.costTemplateId = undefined; costTemplateDetail.value = null; catTemplate.value = null; @@ -1059,6 +1103,8 @@ async function onCatChange(path: number[]) { form.catId = undefined; selectedCatPathLabel.value = ''; pinnedSelectedCat.value = null; + catAuthAuthorized.value = null; + catAuthMessage.value = ''; catTemplate.value = null; parentSpecs.value = []; form.goodsPropValues = {}; @@ -1079,6 +1125,8 @@ async function onCatChange(path: number[]) { form.catId = undefined; selectedCatPathLabel.value = ''; pinnedSelectedCat.value = null; + catAuthAuthorized.value = null; + catAuthMessage.value = ''; catTemplate.value = null; parentSpecs.value = []; clearSkuRows(); @@ -1311,6 +1359,14 @@ function validateForm(): boolean { message.warning('请选择叶子类目'); return false; } + if (catAuthAuthorized.value === false) { + message.warning(catAuthMessage.value || '当前店铺无权发布该类目'); + return false; + } + if (catAuthChecking.value) { + message.warning('正在校验类目发布权限,请稍候'); + return false; + } if (!form.costTemplateId) { message.warning('请选择运费模板'); return false; @@ -1553,6 +1609,8 @@ function resetAll() { form.catPath = []; form.catId = undefined; selectedCatPathLabel.value = ''; + catAuthAuthorized.value = null; + catAuthMessage.value = ''; form.costTemplateId = undefined; costTemplateDetail.value = null; form.marketPriceYuan = undefined; @@ -1681,6 +1739,34 @@ onBeforeUnmount(() => { > 已选:{{ selectedCatPathLabel }}

+ + + +