refactor: 发品去掉主内部商品绑定,改由订单同步兜底建品

This commit is contained in:
2026-10-09 14:15:12 +08:00
parent 7fa0729722
commit 59b3ada695
6 changed files with 4 additions and 123 deletions
@@ -24,10 +24,6 @@ public class PddGoodsPublishDTO {
*/
private Long systemDraftId;
/** 渠道商品绑定的主内部商品 */
@NotNull(message = "主内部商品不能为空")
private Long primaryProductId;
@NotBlank(message = "商品标题不能为空")
private String goodsName;
@@ -41,14 +41,11 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.po.
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;
@@ -73,11 +70,9 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
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;
private final PddGoodsPublishDraftMapper publishDraftMapper;
public PddGoodsPublishServiceImpl(CurrentUserContext currentUserContext,
@@ -86,11 +81,9 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
PddGoodsPublishPopApiClient publishPopApiClient,
PddGoodsPopApiClient goodsPopApiClient,
PddGoodsImageTransfer imageTransfer,
ProductMapper productMapper,
ProductSkuService productSkuService,
PddGoodsService pddGoodsService,
PddGoodsMapper pddGoodsMapper,
PddProductAutoCreateService productAutoCreateService,
PddGoodsPublishDraftMapper publishDraftMapper) {
this.currentUserContext = currentUserContext;
this.pddShopMapper = pddShopMapper;
@@ -98,11 +91,9 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
this.publishPopApiClient = publishPopApiClient;
this.goodsPopApiClient = goodsPopApiClient;
this.imageTransfer = imageTransfer;
this.productMapper = productMapper;
this.productSkuService = productSkuService;
this.pddGoodsService = pddGoodsService;
this.pddGoodsMapper = pddGoodsMapper;
this.productAutoCreateService = productAutoCreateService;
this.publishDraftMapper = publishDraftMapper;
}
@@ -290,13 +281,7 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
throw new BusinessException("发布成功但拉取商品详情为空 goodsId=" + addResult.goodsId());
}
ProductPO primary = productMapper.selectById(dto.getPrimaryProductId());
if (primary == null || !Objects.equals(primary.getCompanyId(), companyId)) {
throw new BusinessException("主内部商品不存在或不属于当前公司");
}
// 主商品下补缺失 SKU(外商品已有 sku_code 会跳过,不挪绑)
productAutoCreateService.ensureMissingSkus(companyId, primary.getId(), detailInfo);
// 不定主内部商品;缺 SKU 由订单同步等路径兜底建品
pddGoodsService.upsertFromGoodsDetail(
companyId, ctx.shop().getId(), ctx.mallId(), detailInfo);
@@ -317,8 +302,8 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
result.setGoods(goodsVo);
bindSystemDraftAfterPublish(companyId, dto.getSystemDraftId(),
addResult.goodsCommitId(), addResult.goodsId());
log.info("拼多多商品发布成功 companyId={} shopId={} goodsId={} primaryProductId={}",
companyId, ctx.shop().getId(), addResult.goodsId(), primary.getId());
log.info("拼多多商品发布成功 companyId={} shopId={} goodsId={}",
companyId, ctx.shop().getId(), addResult.goodsId());
return result;
} catch (BusinessException e) {
throw e;
@@ -365,22 +350,6 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
*/
private PddGoodsPublishPopApiClient.GoodsAddCommand assembleAddCommand(
PddGoodsPublishDTO dto, Long companyId, ShopAuth ctx, boolean strict) throws Exception {
String outGoodsId = null;
if (dto.getPrimaryProductId() != null) {
ProductPO primary = productMapper.selectById(dto.getPrimaryProductId());
if (primary == null || !Objects.equals(primary.getCompanyId(), companyId)) {
if (strict) {
throw new BusinessException("主内部商品不存在或不属于当前公司");
}
} else if (StringUtils.hasText(primary.getProductCode())) {
outGoodsId = primary.getProductCode().trim();
} else if (strict) {
throw new BusinessException("主内部商品缺少商品编码,无法写入 out_goods_id");
}
} else if (strict) {
throw new BusinessException("主内部商品不能为空");
}
List<PddGoodsPublishSkuDTO> skuDtos = dto.getSkus() == null ? List.of() : dto.getSkus();
if (strict && skuDtos.isEmpty()) {
throw new BusinessException("SKU列表不能为空");
@@ -486,7 +455,7 @@ public class PddGoodsPublishServiceImpl implements PddGoodsPublishService {
dto.getTwoPiecesDiscount() == null ? 95 : dto.getTwoPiecesDiscount(),
carousel,
detail,
outGoodsId,
null,
mainImage,
goodsProps,
skuAdds);
@@ -4,7 +4,6 @@ export namespace PddGoodsPublishDTO {
pddShopId: number;
/** 关联系统草稿:发布成功后回写 goods_commit_id */
systemDraftId?: number;
primaryProductId: number;
goodsName: string;
goodsDesc?: string;
catId: number;
@@ -2,8 +2,6 @@
/**
* 拼多多发布编辑器壳:编排 form + composables + 卡片,不含业务算法细节。
*/
import type { ProductVO } from '#/api/ec/product/types';
import {
onBeforeUnmount,
onMounted,
@@ -39,11 +37,8 @@ import {
Tag,
Tooltip,
Upload,
message,
} from 'ant-design-vue';
import { getProductPageApi } from '#/api/ec/product';
import CatPropertyField from './components/CatPropertyField.vue';
import SpecAxesCard from './components/SpecAxesCard.vue';
import SkuTableCard from './components/SkuTableCard.vue';
@@ -83,9 +78,6 @@ const hydratingDraft = ref(false);
const skuRows = ref<SkuRow[]>([]);
const specAxes = ref<SpecAxis[]>([]);
const specCatalog = ref<SpecCatalogItem[]>([]);
const productOptions = ref<{ label: string; value: number; name: string }[]>(
[],
);
/** 环依赖:specs ↔ sku,用可变实现在装配后回填 */
let syncSkuRowsFromSpecsImpl: (opts?: {
@@ -139,23 +131,6 @@ rebuildPreservingImpl = specs.rebuildSpecCatalogPreservingUserData;
buildSpecCatalogImpl = specs.buildSpecCatalog;
clearSkuRowsImpl = sku.clearSkuRows;
async function loadProducts(keyword = '') {
try {
const data = await getProductPageApi({
page: 1,
pageSize: 50,
filters: keyword ? { keywords: keyword } : {},
});
productOptions.value = (data.records ?? []).map((p: ProductVO.Info) => ({
label: `${p.name}${p.productCode ? ` (${p.productCode})` : ''}`,
value: p.id,
name: p.name,
}));
} catch {
message.error('加载内部商品失败');
}
}
function handleClose() {
resetAll();
emit('close');
@@ -178,8 +153,6 @@ const draft = usePublishDraft({
selectedCatPathLabel: category.selectedCatPathLabel,
allNonSaleProps: category.allNonSaleProps,
nonSaleProps: category.nonSaleProps,
productOptions,
loadProducts,
specAxes,
specCatalog,
normalizeSpecValueSlots: specs.normalizeSpecValueSlots,
@@ -216,17 +189,6 @@ const agent = usePublishAgent({
revokeUploadFiles: images.revokeUploadFiles,
});
watch(
() => form.primaryProductId,
(id) => {
if (!id) return;
const p = productOptions.value.find((x) => x.value === id);
if (p && !form.goodsName) {
form.goodsName = p.name;
}
},
);
watch(
() => props.open ?? true,
(v) => {
@@ -235,7 +197,6 @@ watch(
form.pddShopId = props.presetPddShopId ?? undefined;
}
void category.loadShops();
void loadProducts();
void sku.loadSkuCandidates();
if (props.draftId) {
void draft.hydrateFromDraft(props.draftId);
@@ -250,7 +211,6 @@ onMounted(() => {
form.pddShopId = props.presetPddShopId ?? undefined;
}
void category.loadShops();
void loadProducts();
void sku.loadSkuCandidates();
if (props.draftId) {
void draft.hydrateFromDraft(props.draftId);
@@ -492,19 +452,6 @@ function onSkuTableWrapRef(el: HTMLElement | null) {
<div
class="min-h-0 flex-1 space-y-4 overflow-y-auto overscroll-y-contain px-4 py-3"
>
<Form.Item label="主内部商品" required>
<Select
v-model:value="form.primaryProductId"
show-search
allow-clear
class="w-full"
placeholder="搜索并选择主商品(标题默认带出)"
:filter-option="false"
:options="productOptions"
@search="(kw: string) => loadProducts(kw)"
/>
</Form.Item>
<div
data-agent-field="goodsName"
:class="{ 'agent-typing-field': agentTypingField === 'goodsName' }"
@@ -65,9 +65,6 @@ export function usePublishDraft(options: {
selectedCatPathLabel: Ref<string>;
allNonSaleProps: ComputedRef<PddGoodsPublishVO.CatProperty[]>;
nonSaleProps: ComputedRef<PddGoodsPublishVO.CatProperty[]>;
// products
productOptions: Ref<{ label: string; value: number; name: string }[]>;
loadProducts: (keyword?: string) => Promise<void>;
// specs
specAxes: Ref<SpecAxis[]>;
specCatalog: Ref<SpecCatalogItem[]>;
@@ -110,8 +107,6 @@ export function usePublishDraft(options: {
selectedCatPathLabel,
allNonSaleProps,
nonSaleProps,
productOptions,
loadProducts,
specAxes,
specCatalog,
normalizeSpecValueSlots,
@@ -164,10 +159,6 @@ export function usePublishDraft(options: {
message.warning('请选择渠道店铺');
return false;
}
if (!form.primaryProductId) {
message.warning('请选择主内部商品');
return false;
}
if (!form.goodsName.trim()) {
message.warning('请填写商品标题');
return false;
@@ -361,7 +352,6 @@ export function usePublishDraft(options: {
return {
pddShopId: form.pddShopId!,
primaryProductId: form.primaryProductId!,
goodsName: form.goodsName.trim(),
goodsDesc: form.goodsDesc || undefined,
catId: form.catId!,
@@ -408,7 +398,6 @@ export function usePublishDraft(options: {
loadShops(),
shopId ? loadRootCats() : Promise.resolve(),
shopId ? loadLogistics() : Promise.resolve(),
loadProducts(),
loadSkuCandidates(),
]);
@@ -417,22 +406,6 @@ export function usePublishDraft(options: {
draft.title ||
'';
if (typeof es.goodsDesc === 'string') form.goodsDesc = es.goodsDesc;
if (typeof es.primaryProductId === 'number') {
form.primaryProductId = es.primaryProductId;
if (
form.primaryProductId &&
!productOptions.value.some((p) => p.value === form.primaryProductId)
) {
productOptions.value = [
{
label: `商品#${form.primaryProductId}`,
value: form.primaryProductId,
name: form.goodsName || `商品#${form.primaryProductId}`,
},
...productOptions.value,
];
}
}
const catId =
draft.catId ??
@@ -681,7 +654,6 @@ export function usePublishDraft(options: {
const payloadJson = JSON.stringify({
editorState: {
pddShopId: form.pddShopId,
primaryProductId: form.primaryProductId,
goodsName: form.goodsName,
goodsDesc: form.goodsDesc,
catId: form.catId,
@@ -87,7 +87,6 @@ export type DefaultOptionType = {
/** 发布表单字段(店铺/类目/标题等) */
export type PublishFormFields = {
pddShopId: number | undefined;
primaryProductId: number | undefined;
goodsName: string;
goodsDesc: string;
catPath: number[];
@@ -123,7 +122,6 @@ export function twoPiecesDiscountFromStored(raw: number): number {
export function createEmptyPublishForm(): PublishFormFields {
return {
pddShopId: undefined,
primaryProductId: undefined,
goodsName: '',
goodsDesc: '',
catPath: [],