mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
refactor: 去掉拼多多商品手工增删改接口与删除入口
This commit is contained in:
+4
-25
@@ -6,13 +6,14 @@ import top.xyquan.ecomdmbbackend.common.annotation.RequirePermission;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 拼多多渠道商品:列表/详情/同步(入库靠同步与发布,不提供手工增删改)。
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/channel/pdd/goods")
|
||||
public class PddGoodsController {
|
||||
@@ -23,28 +24,6 @@ public class PddGoodsController {
|
||||
this.pddGoodsService = pddGoodsService;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@RequirePermission(value = "channel:pdd:goods:create", description = "创建拼多多商品", allowSuper = true)
|
||||
public ApiResponse<PddGoodsVO> createPddGoods(@Valid @RequestBody CreatePddGoodsDTO createPddGoodsDTO) {
|
||||
PddGoodsVO vo = pddGoodsService.createPddGoods(createPddGoodsDTO);
|
||||
return ApiResponse.success("创建成功", vo);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "channel:pdd:goods:update", description = "更新拼多多商品", allowSuper = true)
|
||||
public ApiResponse<PddGoodsVO> updatePddGoods(@Valid @RequestBody UpdatePddGoodsDTO updatePddGoodsDTO,
|
||||
@PathVariable Long id) {
|
||||
PddGoodsVO vo = pddGoodsService.updatePddGoods(updatePddGoodsDTO, id);
|
||||
return ApiResponse.success("更新成功", vo);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@RequirePermission(value = "channel:pdd:goods:delete", description = "删除拼多多商品", allowSuper = true)
|
||||
public ApiResponse<Void> deletePddGoods(@PathVariable Long id) {
|
||||
pddGoodsService.deletePddGoods(id);
|
||||
return ApiResponse.success("删除成功");
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "channel:pdd:goods:read", description = "查询拼多多商品列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<PddGoodsVO>> getPddGoodsPage(
|
||||
@@ -63,7 +42,7 @@ public class PddGoodsController {
|
||||
@PostMapping("/sync/{pddShopId}")
|
||||
@RequirePermission(value = "channel:pdd:goods:sync", description = "同步拼多多商品", allowSuper = true)
|
||||
public ApiResponse<PddGoodsSyncResultVO> syncGoodsByPddShop(
|
||||
@PathVariable Long pddShopId) {
|
||||
@PathVariable Long pddShopId) {
|
||||
PddGoodsSyncResultVO result = pddGoodsService.syncGoodsByPddShop(pddShopId);
|
||||
return ApiResponse.success("同步完成", result);
|
||||
}
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class CreatePddGoodsDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
@NotNull(message = "mall_id不能为空")
|
||||
private Long mallId;
|
||||
|
||||
@NotBlank(message = "商品ID不能为空")
|
||||
private String goodsId;
|
||||
|
||||
@NotBlank(message = "商品名称不能为空")
|
||||
private String goodsName;
|
||||
|
||||
private Integer goodsQuantity;
|
||||
|
||||
private Integer goodsReserveQuantity;
|
||||
|
||||
private String imageUrl;
|
||||
|
||||
private String thumbUrl;
|
||||
|
||||
private Integer isMoreSku;
|
||||
|
||||
private Integer isOnsale;
|
||||
|
||||
private LocalDateTime pddCreatedAt;
|
||||
|
||||
private String rawResponse;
|
||||
|
||||
@NotNull(message = "同步时间不能为空")
|
||||
private LocalDateTime lastSyncTime;
|
||||
|
||||
private List<CreatePddGoodsSkuDTO> skus;
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreatePddGoodsSkuDTO {
|
||||
|
||||
@NotBlank(message = "商品ID不能为空")
|
||||
private String goodsId;
|
||||
|
||||
@NotBlank(message = "SKU ID不能为空")
|
||||
private String skuId;
|
||||
|
||||
private String spec;
|
||||
|
||||
private String specDetails;
|
||||
|
||||
private Integer skuQuantity;
|
||||
|
||||
private Integer reserveQuantity;
|
||||
|
||||
private Integer isSkuOnsale;
|
||||
|
||||
private String outerGoodsId;
|
||||
|
||||
private String outerId;
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class UpdatePddGoodsDTO {
|
||||
|
||||
@NotNull(message = "渠道店铺ID不能为空")
|
||||
private Long shopId;
|
||||
|
||||
@NotNull(message = "mall_id不能为空")
|
||||
private Long mallId;
|
||||
|
||||
@NotBlank(message = "商品ID不能为空")
|
||||
private String goodsId;
|
||||
|
||||
@NotBlank(message = "商品名称不能为空")
|
||||
private String goodsName;
|
||||
|
||||
private Integer goodsQuantity;
|
||||
|
||||
private Integer goodsReserveQuantity;
|
||||
|
||||
private String imageUrl;
|
||||
|
||||
private String thumbUrl;
|
||||
|
||||
private Integer isMoreSku;
|
||||
|
||||
private Integer isOnsale;
|
||||
|
||||
private LocalDateTime pddCreatedAt;
|
||||
|
||||
private String rawResponse;
|
||||
|
||||
@NotNull(message = "同步时间不能为空")
|
||||
private LocalDateTime lastSyncTime;
|
||||
|
||||
private List<CreatePddGoodsSkuDTO> skus;
|
||||
}
|
||||
-8
@@ -3,9 +3,7 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
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.po.PddGoodsPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsSyncResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsVO;
|
||||
@@ -13,12 +11,6 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.pop.goods.PddGoodsPopApiCli
|
||||
|
||||
public interface PddGoodsService extends IService<PddGoodsPO> {
|
||||
|
||||
PddGoodsVO createPddGoods(CreatePddGoodsDTO createPddGoodsDTO);
|
||||
|
||||
PddGoodsVO updatePddGoods(UpdatePddGoodsDTO updatePddGoodsDTO, Long id);
|
||||
|
||||
void deletePddGoods(Long id);
|
||||
|
||||
PageResultVO<PddGoodsVO> getPddGoodsPage(PageQueryDTO<PddGoodsFilterDTO> pageQueryDTO);
|
||||
|
||||
PddGoodsVO getPddGoodsDetail(Long id);
|
||||
|
||||
+1
-93
@@ -18,10 +18,7 @@ import top.xyquan.ecomdmbbackend.modules.channel.pdd.auth.service.PddAuthTokenSe
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.ensure.PddGoodsEnsureService;
|
||||
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;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.dto.CreatePddGoodsSkuDTO;
|
||||
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.po.PddGoodsSkuPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.model.vo.PddGoodsSkuVO;
|
||||
@@ -45,7 +42,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 拼多多渠道商品 CRUD 与列表同步;主表不定内部商品。
|
||||
* 拼多多渠道商品查询与同步;主表不定内部商品。手工增删改已下线。
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -78,87 +75,6 @@ public class PddGoodsServiceImpl extends ServiceImpl<PddGoodsMapper, PddGoodsPO>
|
||||
this.currentUserContext = currentUserContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PddGoodsVO createPddGoods(CreatePddGoodsDTO createPddGoodsDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
LambdaQueryWrapper<PddGoodsPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PddGoodsPO::getShopId, createPddGoodsDTO.getShopId())
|
||||
.eq(PddGoodsPO::getGoodsId, createPddGoodsDTO.getGoodsId());
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("该商品已存在");
|
||||
}
|
||||
|
||||
PddGoodsPO goods = new PddGoodsPO();
|
||||
BeanCopyUtils.copyProperties(createPddGoodsDTO, goods);
|
||||
goods.setCompanyId(companyId);
|
||||
this.save(goods);
|
||||
|
||||
if (createPddGoodsDTO.getSkus() != null && !createPddGoodsDTO.getSkus().isEmpty()) {
|
||||
List<PddGoodsSkuPO> skus = createPddGoodsDTO.getSkus().stream()
|
||||
.map(skuDTO -> convertToSkuPO(skuDTO, goods.getId(), companyId))
|
||||
.collect(Collectors.toList());
|
||||
skus.forEach(pddGoodsSkuMapper::insert);
|
||||
}
|
||||
|
||||
return convertToVO(goods);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public PddGoodsVO updatePddGoods(UpdatePddGoodsDTO updatePddGoodsDTO, Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
PddGoodsPO existing = this.getById(id);
|
||||
if (existing == null || !companyId.equals(existing.getCompanyId())) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<PddGoodsPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PddGoodsPO::getShopId, updatePddGoodsDTO.getShopId())
|
||||
.eq(PddGoodsPO::getGoodsId, updatePddGoodsDTO.getGoodsId())
|
||||
.ne(PddGoodsPO::getId, id);
|
||||
if (this.count(wrapper) > 0) {
|
||||
throw new BusinessException("该商品已存在");
|
||||
}
|
||||
|
||||
PddGoodsPO goods = new PddGoodsPO();
|
||||
BeanCopyUtils.copyProperties(updatePddGoodsDTO, goods);
|
||||
goods.setId(id);
|
||||
goods.setCompanyId(companyId);
|
||||
this.updateById(goods);
|
||||
|
||||
LambdaQueryWrapper<PddGoodsSkuPO> deleteWrapper = new LambdaQueryWrapper<>();
|
||||
deleteWrapper.eq(PddGoodsSkuPO::getGoodsRowId, id);
|
||||
pddGoodsSkuMapper.delete(deleteWrapper);
|
||||
|
||||
if (updatePddGoodsDTO.getSkus() != null && !updatePddGoodsDTO.getSkus().isEmpty()) {
|
||||
List<PddGoodsSkuPO> skus = updatePddGoodsDTO.getSkus().stream()
|
||||
.map(skuDTO -> convertToSkuPO(skuDTO, id, companyId))
|
||||
.collect(Collectors.toList());
|
||||
skus.forEach(pddGoodsSkuMapper::insert);
|
||||
}
|
||||
|
||||
return convertToVO(this.getById(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deletePddGoods(Long id) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
PddGoodsPO existing = this.getById(id);
|
||||
if (existing == null || !companyId.equals(existing.getCompanyId())) {
|
||||
throw new BusinessException("商品不存在");
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<PddGoodsSkuPO> deleteWrapper = new LambdaQueryWrapper<>();
|
||||
deleteWrapper.eq(PddGoodsSkuPO::getGoodsRowId, id);
|
||||
pddGoodsSkuMapper.delete(deleteWrapper);
|
||||
|
||||
this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<PddGoodsVO> getPddGoodsPage(PageQueryDTO<PddGoodsFilterDTO> pageQueryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
@@ -503,14 +419,6 @@ public class PddGoodsServiceImpl extends ServiceImpl<PddGoodsMapper, PddGoodsPO>
|
||||
return LocalDateTime.ofInstant(Instant.ofEpochSecond(epochSec), ZONE);
|
||||
}
|
||||
|
||||
private PddGoodsSkuPO convertToSkuPO(CreatePddGoodsSkuDTO dto, Long goodsRowId, Long companyId) {
|
||||
PddGoodsSkuPO sku = new PddGoodsSkuPO();
|
||||
BeanCopyUtils.copyProperties(dto, sku);
|
||||
sku.setGoodsRowId(goodsRowId);
|
||||
sku.setCompanyId(companyId);
|
||||
return sku;
|
||||
}
|
||||
|
||||
private PddGoodsVO convertToBriefVO(PddGoodsPO goods) {
|
||||
PddGoodsVO vo = new PddGoodsVO();
|
||||
BeanCopyUtils.copyProperties(goods, vo);
|
||||
|
||||
+8
@@ -92,6 +92,14 @@ public class ProductSkuController {
|
||||
return ApiResponse.success("查询SKU成功", vo);
|
||||
}
|
||||
|
||||
/** 按公司内 SKU 编码反查,返回所属内部商品信息 */
|
||||
@GetMapping("/find-by-sku-code")
|
||||
@RequirePermission(value = "ec:product:read", description = "根据SKU编码反查内部商品", allowSuper = true)
|
||||
public ApiResponse<ProductSkuVO> getProductSkuBySkuCode(@RequestParam("skuCode") String skuCode) {
|
||||
ProductSkuVO vo = productSkuService.getProductSkuBySkuCode(skuCode);
|
||||
return ApiResponse.success("查询SKU成功", vo);
|
||||
}
|
||||
|
||||
@PostMapping("/find-by-product-and-skus")
|
||||
@RequirePermission(value = "ec:product:read", description = "批量根据商品名称和SKU编码查询", allowSuper = true)
|
||||
public ApiResponse<List<ProductVO>> getProductSkusByProductAndSkus(@RequestBody List<ProductSkuQueryDTO> queries) {
|
||||
|
||||
+5
@@ -33,6 +33,11 @@ public interface ProductSkuService extends IService<ProductSkuPO> {
|
||||
|
||||
ProductSkuVO getProductSkuByProductAndSku(String productName, String skuCode);
|
||||
|
||||
/**
|
||||
* 当前公司内按 SKU 编码反查(含所属商品 id/名称)。
|
||||
*/
|
||||
ProductSkuVO getProductSkuBySkuCode(String skuCode);
|
||||
|
||||
List<ProductVO> getProductSkusByProductAndSkus(List<ProductSkuQueryDTO> queries);
|
||||
|
||||
ProductSkuPO getByCompanyIdAndSkuCode(Long companyId, String skuCode);
|
||||
|
||||
+20
@@ -288,6 +288,26 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
return sku == null ? null : toVo(sku);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductSkuVO getProductSkuBySkuCode(String skuCode) {
|
||||
if (skuCode == null || skuCode.isBlank()) {
|
||||
throw new BusinessException("SKU编码不能为空");
|
||||
}
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ProductSkuPO sku = getByCompanyIdAndSkuCode(companyId, skuCode.trim());
|
||||
if (sku == null) {
|
||||
throw new BusinessException("未找到对应的内部SKU: " + skuCode.trim());
|
||||
}
|
||||
ProductSkuVO vo = toVo(sku);
|
||||
if (sku.getProductId() != null) {
|
||||
ProductPO product = productService.getById(sku.getProductId());
|
||||
if (product != null) {
|
||||
vo.setProductName(product.getName());
|
||||
}
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductSkuPO getByCompanyIdAndSkuCode(Long companyId, String skuCode) {
|
||||
if (companyId == null || skuCode == null || skuCode.isBlank()) {
|
||||
|
||||
@@ -24,11 +24,6 @@ export async function getPddGoodsDetailApi(id: number) {
|
||||
return requestClient.get<PddGoodsVO.Info>(`/channel/pdd/goods/detail/${id}`);
|
||||
}
|
||||
|
||||
/** 删除拼多多商品及 SKU */
|
||||
export async function deletePddGoodsApi(id: number) {
|
||||
return requestClient.delete<void>(`/channel/pdd/goods/delete/${id}`);
|
||||
}
|
||||
|
||||
/** 按渠道店铺同步商品 */
|
||||
export async function syncPddGoodsByShopApi(pddShopId: number) {
|
||||
return requestClient.post<PddGoodsVO.SyncResult>(
|
||||
|
||||
@@ -68,6 +68,16 @@ export async function getProductSkuByProductAndSkuApi(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 SKU 编码反查内部 SKU(含所属商品 id/名称)
|
||||
*/
|
||||
export async function getProductSkuBySkuCodeApi(skuCode: string) {
|
||||
return requestClient.get<ProductSkuVO.Info>(
|
||||
'/ec/product/sku/find-by-sku-code',
|
||||
{ params: { skuCode } },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量根据商品名称和 SKU 编码查询商品 SKU
|
||||
*/
|
||||
|
||||
+59
-8
@@ -4,6 +4,7 @@ import type { PddGoodsVO } from '#/api/channel/pdd/goods';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Descriptions,
|
||||
DescriptionsItem,
|
||||
Drawer,
|
||||
@@ -15,6 +16,8 @@ import {
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getPddGoodsDetailApi } from '#/api/channel/pdd/goods';
|
||||
import { getProductSkuBySkuCodeApi } from '#/api/ec/product/sku';
|
||||
import ProductDetailModal from '#/views/ec/product/list/components/ProductDetailModal.vue';
|
||||
|
||||
defineOptions({ name: 'PddGoodsDetailDrawer' });
|
||||
|
||||
@@ -22,8 +25,18 @@ const openFlag = ref(false);
|
||||
const loading = ref(false);
|
||||
const shopName = ref('');
|
||||
const detail = ref<null | PddGoodsVO.Info>(null);
|
||||
const productDetailModalRef = ref<InstanceType<typeof ProductDetailModal>>();
|
||||
const resolvingOuterId = ref<null | string>(null);
|
||||
|
||||
const skuColumns = [
|
||||
{
|
||||
// POP outer_goods_id:商家外部商品编码(非内部商品)
|
||||
title: '外部商品编码',
|
||||
dataIndex: 'outerGoodsId',
|
||||
key: 'outerGoodsId',
|
||||
ellipsis: true,
|
||||
width: 140,
|
||||
},
|
||||
{
|
||||
title: '外部SKU',
|
||||
dataIndex: 'outerId',
|
||||
@@ -40,13 +53,6 @@ const skuColumns = [
|
||||
width: 80,
|
||||
},
|
||||
{ title: '在架', key: 'isSkuOnsale', width: 80 },
|
||||
{
|
||||
title: '外部商品',
|
||||
dataIndex: 'outerGoodsId',
|
||||
key: 'outerGoodsId',
|
||||
ellipsis: true,
|
||||
width: 120,
|
||||
},
|
||||
];
|
||||
|
||||
async function open(id: number, shopLabel?: string) {
|
||||
@@ -69,6 +75,31 @@ function close() {
|
||||
openFlag.value = false;
|
||||
}
|
||||
|
||||
/** 点击外部 SKU:按 sku_code 反查并打开内部商品详情 */
|
||||
async function openInternalProductByOuterId(outerId?: string) {
|
||||
const code = outerId?.trim();
|
||||
if (!code) {
|
||||
message.warning('该规格无外部SKU编码');
|
||||
return;
|
||||
}
|
||||
if (resolvingOuterId.value) {
|
||||
return;
|
||||
}
|
||||
resolvingOuterId.value = code;
|
||||
try {
|
||||
const sku = await getProductSkuBySkuCodeApi(code);
|
||||
if (!sku?.productId) {
|
||||
message.warning(`未匹配到内部商品:${code}`);
|
||||
return;
|
||||
}
|
||||
await productDetailModalRef.value?.openById(sku.productId, sku.productName);
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || `未找到内部SKU:${code}`);
|
||||
} finally {
|
||||
resolvingOuterId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
defineExpose({ open, close });
|
||||
</script>
|
||||
|
||||
@@ -137,7 +168,25 @@ defineExpose({ open, close });
|
||||
:scroll="{ x: 700 }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'isSkuOnsale'">
|
||||
<template v-if="column.key === 'outerGoodsId'">
|
||||
<span :class="record.outerGoodsId ? '' : 'text-slate-400'">
|
||||
{{ record.outerGoodsId || '-' }}
|
||||
</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'outerId'">
|
||||
<Button
|
||||
v-if="record.outerId"
|
||||
type="link"
|
||||
size="small"
|
||||
class="!px-0"
|
||||
:loading="resolvingOuterId === record.outerId"
|
||||
@click="openInternalProductByOuterId(record.outerId)"
|
||||
>
|
||||
{{ record.outerId }}
|
||||
</Button>
|
||||
<span v-else class="text-slate-400">-</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'isSkuOnsale'">
|
||||
<Tag :color="record.isSkuOnsale === 1 ? 'success' : 'default'">
|
||||
{{ record.isSkuOnsale === 1 ? '在架' : '下架' }}
|
||||
</Tag>
|
||||
@@ -146,5 +195,7 @@ defineExpose({ open, close });
|
||||
</Table>
|
||||
</template>
|
||||
</Spin>
|
||||
|
||||
<ProductDetailModal ref="productDetailModalRef" :show-actions="false" />
|
||||
</Drawer>
|
||||
</template>
|
||||
|
||||
@@ -6,13 +6,10 @@ import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { Button, Card, Image, Popconfirm, Space, Tag, message } from 'ant-design-vue';
|
||||
import { Button, Card, Image, Tag, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePddGoodsApi,
|
||||
getPddGoodsPageApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
import { getPddGoodsPageApi } from '#/api/channel/pdd/goods';
|
||||
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
|
||||
import { PermissionGate } from '#/components/permission';
|
||||
import PddShopColPage from '#/views/channel/pdd/components/PddShopColPage.vue';
|
||||
@@ -123,7 +120,7 @@ const gridOptions: VxeGridProps<PddGoodsVO.Info> = {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 140,
|
||||
width: 88,
|
||||
fixed: 'right' as const,
|
||||
showOverflow: false,
|
||||
slots: { default: 'action' },
|
||||
@@ -288,16 +285,6 @@ function openShopDetail(row: PddGoodsVO.Info) {
|
||||
shopDetailModalRef.value?.open(row.shopId);
|
||||
}
|
||||
|
||||
async function handleDelete(row: PddGoodsVO.Info) {
|
||||
try {
|
||||
await deletePddGoodsApi(row.id);
|
||||
message.success('已删除');
|
||||
gridApi.reload();
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadShopNames();
|
||||
});
|
||||
@@ -373,19 +360,9 @@ onMounted(async () => {
|
||||
</template>
|
||||
|
||||
<template #action="{ row }: { row: PddGoodsVO.Info }">
|
||||
<Space size="small" :wrap="false">
|
||||
<Button type="link" size="small" @click="openDetail(row)">
|
||||
详情
|
||||
</Button>
|
||||
<PermissionGate code="channel:pdd:goods:delete">
|
||||
<Popconfirm
|
||||
title="确定删除该商品及全部 SKU 吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</PermissionGate>
|
||||
</Space>
|
||||
<Button type="link" size="small" @click="openDetail(row)">
|
||||
详情
|
||||
</Button>
|
||||
</template>
|
||||
</Grid>
|
||||
</div>
|
||||
|
||||
+133
-69
@@ -8,15 +8,26 @@ import { useRouter } from 'vue-router';
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Image, Space, Table, Tooltip } from 'ant-design-vue';
|
||||
import { Button, Image, Space, Spin, Table, Tooltip, message } from 'ant-design-vue';
|
||||
|
||||
import { getProductSkuPageApi } from '#/api/ec/product/sku';
|
||||
|
||||
defineOptions({ name: 'ProductDetailModal' });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 是否展示编辑/成本等操作按钮,渠道侧只读可关 */
|
||||
showActions?: boolean;
|
||||
}>(),
|
||||
{ showActions: true },
|
||||
);
|
||||
|
||||
const ChartIcon = createIconifyIcon('lucide:line-chart');
|
||||
const EditIcon = createIconifyIcon('lucide:square-pen');
|
||||
const ImageIcon = createIconifyIcon('lucide:image');
|
||||
|
||||
const product = ref<ProductVO.Info | null>(null);
|
||||
const loading = ref(false);
|
||||
const router = useRouter();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -131,15 +142,60 @@ const [Modal, modalApi] = useVbenModal({
|
||||
footer: false,
|
||||
});
|
||||
|
||||
/** 打开详情模态框 */
|
||||
/** 打开详情模态框(已有完整商品对象) */
|
||||
function open(record: ProductVO.Info) {
|
||||
product.value = record;
|
||||
loading.value = false;
|
||||
modalApi.setState({
|
||||
title: `商品详情 - ${record.name}`,
|
||||
});
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
/**
|
||||
* 按内部商品 ID 加载后打开。
|
||||
* @param productId 内部商品 ID
|
||||
* @param fallbackName 列表侧已知名称(可选)
|
||||
*/
|
||||
async function openById(productId: number, fallbackName?: string) {
|
||||
if (!productId) {
|
||||
message.warning('未关联内部商品');
|
||||
return;
|
||||
}
|
||||
product.value = null;
|
||||
loading.value = true;
|
||||
modalApi.setState({
|
||||
title: fallbackName ? `商品详情 - ${fallbackName}` : '商品详情',
|
||||
});
|
||||
modalApi.open();
|
||||
try {
|
||||
const data = await getProductSkuPageApi({
|
||||
page: 1,
|
||||
pageSize: 500,
|
||||
filters: { productId },
|
||||
});
|
||||
const skus = (data.records ?? []) as ProductVO.SkuInfo[];
|
||||
const first = skus[0];
|
||||
const name = fallbackName || first?.productName || `商品#${productId}`;
|
||||
product.value = {
|
||||
id: productId,
|
||||
companyId: first?.companyId ?? 0,
|
||||
name,
|
||||
mainImage: first?.imageUrl,
|
||||
createTime: first?.createTime ?? '',
|
||||
updateTime: first?.updateTime ?? '',
|
||||
skus,
|
||||
};
|
||||
modalApi.setState({ title: `商品详情 - ${name}` });
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
message.error(error?.message || '加载内部商品详情失败');
|
||||
modalApi.close();
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 跳转经营统计 */
|
||||
function goOverview() {
|
||||
if (!product.value) return;
|
||||
@@ -164,88 +220,96 @@ function handleManageCost() {
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
openById,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<div v-if="product" class="space-y-5">
|
||||
<!-- 商品基础信息 -->
|
||||
<div
|
||||
class="flex flex-col gap-4 rounded-xl border border-slate-200 bg-slate-50/80 p-4 sm:flex-row sm:items-start dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_14%)]"
|
||||
>
|
||||
<Spin :spinning="loading">
|
||||
<div v-if="product" class="space-y-5">
|
||||
<!-- 商品基础信息 -->
|
||||
<div
|
||||
class="flex h-[120px] w-[120px] shrink-0 items-center justify-center overflow-hidden rounded-lg border border-slate-200 bg-white dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
class="flex flex-col gap-4 rounded-xl border border-slate-200 bg-slate-50/80 p-4 sm:flex-row sm:items-start dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_14%)]"
|
||||
>
|
||||
<Image
|
||||
v-if="product.mainImage"
|
||||
:src="product.mainImage"
|
||||
:width="120"
|
||||
:height="120"
|
||||
class="object-cover"
|
||||
:preview="true"
|
||||
/>
|
||||
<ImageIcon
|
||||
v-else
|
||||
class="h-10 w-10 text-slate-300 dark:text-[hsl(240deg_5%_45%)]"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="min-w-0 flex-1 space-y-2 text-sm">
|
||||
<div class="text-lg font-semibold text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ product.name }}
|
||||
<div
|
||||
class="flex h-[120px] w-[120px] shrink-0 items-center justify-center overflow-hidden rounded-lg border border-slate-200 bg-white dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
>
|
||||
<Image
|
||||
v-if="product.mainImage"
|
||||
:src="product.mainImage"
|
||||
:width="120"
|
||||
:height="120"
|
||||
class="object-cover"
|
||||
:preview="true"
|
||||
/>
|
||||
<ImageIcon
|
||||
v-else
|
||||
class="h-10 w-10 text-slate-300 dark:text-[hsl(240deg_5%_45%)]"
|
||||
/>
|
||||
</div>
|
||||
<div class="grid gap-2 sm:grid-cols-2">
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">商品编码:</span>
|
||||
<span>{{ product.productCode || '-' }}</span>
|
||||
|
||||
<div class="min-w-0 flex-1 space-y-2 text-sm">
|
||||
<div class="text-lg font-semibold text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
{{ product.name }}
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">商品类目:</span>
|
||||
<span>{{ product.categoryName || '-' }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">SKU 数量:</span>
|
||||
<span>{{ product.skus?.length ?? 0 }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">创建时间:</span>
|
||||
<span>{{ product.createTime || '-' }}</span>
|
||||
<div class="grid gap-2 sm:grid-cols-2">
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">商品编码:</span>
|
||||
<span>{{ product.productCode || '-' }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">商品类目:</span>
|
||||
<span>{{ product.categoryName || '-' }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">SKU 数量:</span>
|
||||
<span>{{ product.skus?.length ?? 0 }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">创建时间:</span>
|
||||
<span>{{ product.createTime || '-' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SKU 明细表 -->
|
||||
<div>
|
||||
<div class="mb-3 text-base font-medium text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
SKU 明细
|
||||
<!-- SKU 明细表 -->
|
||||
<div>
|
||||
<div class="mb-3 text-base font-medium text-slate-900 dark:text-[hsl(0deg_0%_95%)]">
|
||||
SKU 明细
|
||||
</div>
|
||||
<Table
|
||||
:columns="skuColumns"
|
||||
:data-source="skuDataSource"
|
||||
:pagination="false"
|
||||
row-key="id"
|
||||
size="small"
|
||||
bordered
|
||||
:scroll="{ x: 920 }"
|
||||
/>
|
||||
</div>
|
||||
<Table
|
||||
:columns="skuColumns"
|
||||
:data-source="skuDataSource"
|
||||
:pagination="false"
|
||||
row-key="id"
|
||||
size="small"
|
||||
bordered
|
||||
:scroll="{ x: 920 }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end border-t border-slate-200 pt-4 dark:border-[hsl(240deg_3.7%_22%)]">
|
||||
<Space>
|
||||
<Button @click="modalApi.close()">关闭</Button>
|
||||
<Button @click="goOverview">
|
||||
<ChartIcon class="mr-1 h-4 w-4" />
|
||||
经营统计
|
||||
</Button>
|
||||
<Button @click="handleManageCost">管理成本</Button>
|
||||
<Button type="primary" @click="handleEdit">
|
||||
<EditIcon class="mr-1 h-4 w-4" />
|
||||
编辑商品
|
||||
</Button>
|
||||
</Space>
|
||||
<div class="flex justify-end border-t border-slate-200 pt-4 dark:border-[hsl(240deg_3.7%_22%)]">
|
||||
<Space>
|
||||
<Button @click="modalApi.close()">关闭</Button>
|
||||
<template v-if="props.showActions">
|
||||
<Button @click="goOverview">
|
||||
<ChartIcon class="mr-1 h-4 w-4" />
|
||||
经营统计
|
||||
</Button>
|
||||
<Button @click="handleManageCost">管理成本</Button>
|
||||
<Button type="primary" @click="handleEdit">
|
||||
<EditIcon class="mr-1 h-4 w-4" />
|
||||
编辑商品
|
||||
</Button>
|
||||
</template>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="!loading" class="py-10 text-center text-slate-400">
|
||||
暂无商品数据
|
||||
</div>
|
||||
</Spin>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user