mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 发布商品选中类目后校验店铺发布权并提示
This commit is contained in:
+8
@@ -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<PddPublishCatAuthVO> 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<PddPublishLogisticsPageVO> listLogistics(
|
||||
|
||||
+21
@@ -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<Long> catPath;
|
||||
}
|
||||
+18
@@ -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;
|
||||
}
|
||||
+5
@@ -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<PddPublishCatVO> listAuthCats(PddPublishShopCatQueryDTO query);
|
||||
|
||||
/** 按路径校验当前店铺是否有权发布该类目 */
|
||||
PddPublishCatAuthVO checkCatAuth(PddPublishCatAuthQueryDTO query);
|
||||
|
||||
PddPublishLogisticsPageVO listLogisticsTemplates(PddPublishLogisticsQueryDTO query);
|
||||
|
||||
PddPublishCostTemplateDetailVO getCostTemplateDetail(PddPublishCostTemplateDetailQueryDTO query);
|
||||
|
||||
+39
@@ -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<Long> 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<PddGoodsPublishPopApiClient.AuthCatItem> 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());
|
||||
|
||||
@@ -41,6 +41,16 @@ export async function listPddPublishCatsApi(
|
||||
);
|
||||
}
|
||||
|
||||
/** 校验类目路径是否有发布权 */
|
||||
export async function checkPddPublishCatAuthApi(
|
||||
data: PddGoodsPublishDTO.CatAuthQuery,
|
||||
) {
|
||||
return requestClient.post<PddGoodsPublishVO.CatAuth>(
|
||||
'/channel/pdd/goods/publish/meta/check-cat-auth',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 运费模板列表 */
|
||||
export async function listPddPublishLogisticsApi(
|
||||
data: PddGoodsPublishDTO.LogisticsQuery,
|
||||
|
||||
@@ -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[];
|
||||
|
||||
+93
-2
@@ -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<boolean | null>(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<CatCascaderNode[]>
|
||||
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 }}
|
||||
</p>
|
||||
<Alert
|
||||
v-if="catAuthChecking"
|
||||
class="mt-2"
|
||||
type="info"
|
||||
show-icon
|
||||
message="正在校验该类目是否有发布权…"
|
||||
/>
|
||||
<Alert
|
||||
v-else-if="form.catId && catAuthAuthorized === true"
|
||||
class="mt-2"
|
||||
type="success"
|
||||
show-icon
|
||||
message="当前店铺有权发布该类目"
|
||||
/>
|
||||
<Alert
|
||||
v-else-if="form.catId && catAuthAuthorized === false"
|
||||
class="mt-2"
|
||||
type="error"
|
||||
show-icon
|
||||
:message="catAuthMessage || '当前店铺无权发布该类目'"
|
||||
/>
|
||||
<Alert
|
||||
v-else-if="form.catId && catAuthMessage && catAuthAuthorized === null"
|
||||
class="mt-2"
|
||||
type="warning"
|
||||
show-icon
|
||||
:message="catAuthMessage"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="运费模板" required>
|
||||
<Select
|
||||
@@ -2114,7 +2200,12 @@ onBeforeUnmount(() => {
|
||||
>
|
||||
<Space>
|
||||
<Button @click="handleClose">取消</Button>
|
||||
<Button type="primary" :loading="submitting" @click="handleSubmit">
|
||||
<Button
|
||||
type="primary"
|
||||
:loading="submitting"
|
||||
:disabled="catAuthAuthorized === false || catAuthChecking"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
发布到拼多多
|
||||
</Button>
|
||||
</Space>
|
||||
|
||||
Reference in New Issue
Block a user