|
@@ -42,6 +42,7 @@ import zs.payment.service.flymall.b2cshop.B2cShopService;
|
|
|
|
|
|
|
|
import zs.payment.mapper.flymall.B2cGoodsAttrMapper;
|
|
import zs.payment.mapper.flymall.B2cGoodsAttrMapper;
|
|
|
import zs.payment.mapper.flymall.B2cGoodsSpuInOnlineMapper;
|
|
import zs.payment.mapper.flymall.B2cGoodsSpuInOnlineMapper;
|
|
|
|
|
+import zs.payment.mapper.flymall.B2cGoodsStatusMapper;
|
|
|
import zs.payment.messages.KafkaProducer;
|
|
import zs.payment.messages.KafkaProducer;
|
|
|
import zs.payment.utils.RedisUtils;
|
|
import zs.payment.utils.RedisUtils;
|
|
|
|
|
|
|
@@ -95,6 +96,8 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
|
|
|
private B2cGoodsSpuInOnlineMapper b2cGoodsSpuInOnlineMapper;
|
|
private B2cGoodsSpuInOnlineMapper b2cGoodsSpuInOnlineMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private B2cGoodsAttrMapper b2cGoodsAttrMapper;
|
|
private B2cGoodsAttrMapper b2cGoodsAttrMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private B2cGoodsStatusMapper b2cGoodsStatusMapper;
|
|
|
|
|
|
|
|
private static final BigDecimal HUNDRED = new BigDecimal("100");
|
|
private static final BigDecimal HUNDRED = new BigDecimal("100");
|
|
|
private static final BigDecimal COMMISSION_DEFAULT_RATE = new BigDecimal("0.01");
|
|
private static final BigDecimal COMMISSION_DEFAULT_RATE = new BigDecimal("0.01");
|
|
@@ -1196,33 +1199,49 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 停止供货:通知云商城停止供货
|
|
|
|
|
- * 对应PHP supply()中issupply==0的逻辑(1015-1034行)
|
|
|
|
|
|
|
+ * 停止供货:直连BD完成云商城下架+删除操作(替换原 PHP changeStatus 接口)
|
|
|
|
|
+ * 对应PHP changeStatus() 完整流程:
|
|
|
|
|
+ * 1. goodsHandleByQiyue type=1 → is_on_sale=2
|
|
|
|
|
+ * 2. goodsHandleByQiyue type=2 → is_del=1
|
|
|
|
|
+ * 3. updateshelfnumbygdid + delGoodsByShelvesId → 更新货架计数 + 软删除货架商品
|
|
|
|
|
+ * 4. delSkuByGdId → 删除SKU
|
|
|
|
|
+ * 5. 清除Redis缓存
|
|
|
|
|
+ * 6. editYdDistributionGoodsStatus → 下架悦店分销商品
|
|
|
|
|
+ * 7. batchOffTheShelfJfGoods → 下架积分商品
|
|
|
*/
|
|
*/
|
|
|
private void stopSupplyFromMall(ImsEweiShopGoods item, Integer storeid) {
|
|
private void stopSupplyFromMall(ImsEweiShopGoods item, Integer storeid) {
|
|
|
if (item.getGdId() == null || item.getGdId() == 0) {
|
|
if (item.getGdId() == null || item.getGdId() == 0) {
|
|
|
throw new ApiException("该商品未在云商城供货,无法停止供货");
|
|
throw new ApiException("该商品未在云商城供货,无法停止供货");
|
|
|
}
|
|
}
|
|
|
|
|
+ Integer gdId = item.getGdId();
|
|
|
|
|
|
|
|
- // 调用云商城接口通知停止供货
|
|
|
|
|
- String changeStatusUrl = mallHost + "/changeStatus?shop_id=" + storeid
|
|
|
|
|
- + "&gd_id=" + item.getGdId() + "&status=2";
|
|
|
|
|
- try {
|
|
|
|
|
- String resp = HttpUtil.restTemplateGet(changeStatusUrl, null);
|
|
|
|
|
- log.info("云商城停止供货 goodsId={}, gd_id={}, url={}, resp={}", item.getId(), item.getGdId(), changeStatusUrl, resp);
|
|
|
|
|
- JSONObject result = JSON.parseObject(resp);
|
|
|
|
|
- if (result == null || result.getIntValue("head") != 200) {
|
|
|
|
|
- throw new ApiException("停止供货失败!");
|
|
|
|
|
- }
|
|
|
|
|
- } catch (ApiException e) {
|
|
|
|
|
- throw e;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("云商城停止供货接口异常 goodsId={}", item.getId(), e);
|
|
|
|
|
- throw new ApiException("停止供货接口调用失败!");
|
|
|
|
|
|
|
+ // Step 1: 下架商品(is_on_sale=2)
|
|
|
|
|
+ int affected = b2cGoodsStatusMapper.updateOnSaleStatus(gdId, 2);
|
|
|
|
|
+ if (affected <= 0) {
|
|
|
|
|
+ throw new ApiException("停止供货失败!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //取消供货
|
|
|
|
|
- yunMallGoodsService.saveGoods(item.getGdId().toString(),0);
|
|
|
|
|
|
|
+ // Step 2: 软删除商品(is_del=1)
|
|
|
|
|
+ b2cGoodsStatusMapper.softDeleteSpu(gdId);
|
|
|
|
|
+
|
|
|
|
|
+ // Step 3: 更新货架商品数量 + 软删除货架商品
|
|
|
|
|
+ updateShelfCountAndDelete(storeid, gdId);
|
|
|
|
|
+
|
|
|
|
|
+ // Step 4: 删除SKU + 清除Redis缓存
|
|
|
|
|
+ deleteSkusAndClearCache(gdId);
|
|
|
|
|
+
|
|
|
|
|
+ // Step 5: 下架悦店分销商品
|
|
|
|
|
+ b2cGoodsStatusMapper.offShelfYdDistributionGoods(gdId);
|
|
|
|
|
+
|
|
|
|
|
+ // Step 6: 下架积分商品(SPU + SKU + 商城)
|
|
|
|
|
+ b2cGoodsStatusMapper.offShelfJfGoodsSpu(gdId);
|
|
|
|
|
+ b2cGoodsStatusMapper.offShelfJfGoodsSku(gdId);
|
|
|
|
|
+ b2cGoodsStatusMapper.offShelfJfMallGoods(gdId);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("云商城停止供货成功 goodsId={}, gdId={}, storeid={}", item.getId(), gdId, storeid);
|
|
|
|
|
+
|
|
|
|
|
+ // 取消供货
|
|
|
|
|
+ yunMallGoodsService.saveGoods(gdId.toString(), 2);
|
|
|
// 停止供货时取消推荐状态
|
|
// 停止供货时取消推荐状态
|
|
|
ImsEweiShopGoods update = new ImsEweiShopGoods();
|
|
ImsEweiShopGoods update = new ImsEweiShopGoods();
|
|
|
update.setId(item.getId());
|
|
update.setId(item.getId());
|
|
@@ -1230,6 +1249,78 @@ public class CommodityProcureServiceImpl implements CommodityProcureService {
|
|
|
goodsService.updateById(update);
|
|
goodsService.updateById(update);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 更新货架商品数量并软删除货架商品(对应PHP updateshelfnumbygdid + delGoodsByShelvesId)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateShelfCountAndDelete(Integer shopId, Integer gdId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 查询关联的货架ID
|
|
|
|
|
+ List<Integer> shelfIds = b2cGoodsStatusMapper.findShelfIdsByShopAndGd(shopId, gdId);
|
|
|
|
|
+ if (shelfIds != null && !shelfIds.isEmpty()) {
|
|
|
|
|
+ for (Integer shelfId : shelfIds) {
|
|
|
|
|
+ updateShelfNum(shelfId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 软删除货架商品
|
|
|
|
|
+ b2cGoodsStatusMapper.softDeleteShelfGoods(shopId, gdId);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("更新货架商品数量失败 shopId={}, gdId={}", shopId, gdId, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 重新计算货架及其父货架的商品数量(对应PHP updateshelfnum)
|
|
|
|
|
+ * 逻辑:计算当前货架商品数,同时更新父货架商品总数
|
|
|
|
|
+ */
|
|
|
|
|
+ private void updateShelfNum(Integer shelfId) {
|
|
|
|
|
+ Map<String, Object> shelfInfo = b2cGoodsStatusMapper.findShelfById(shelfId);
|
|
|
|
|
+ if (shelfInfo == null) return;
|
|
|
|
|
+
|
|
|
|
|
+ Object parentIdObj = shelfInfo.get("parent_id");
|
|
|
|
|
+ Integer parentId = parentIdObj != null ? ((Number) parentIdObj).intValue() : 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 重新计算当前货架商品数(减1,因为待删除的商品还未标记is_del)
|
|
|
|
|
+ int currentCount = b2cGoodsStatusMapper.countShelfGoods(shelfId);
|
|
|
|
|
+ int newCount = Math.max(currentCount - 1, 0);
|
|
|
|
|
+ b2cGoodsStatusMapper.updateShelfGoodsCount(shelfId, newCount);
|
|
|
|
|
+
|
|
|
|
|
+ // 更新父货架商品数
|
|
|
|
|
+ if (parentId > 0) {
|
|
|
|
|
+ Map<String, Object> parentInfo = b2cGoodsStatusMapper.findShelfById(parentId);
|
|
|
|
|
+ if (parentInfo != null) {
|
|
|
|
|
+ List<Integer> childShelfIds = b2cGoodsStatusMapper.findChildShelfIds(parentId);
|
|
|
|
|
+ int parentCount = 0;
|
|
|
|
|
+ if (childShelfIds != null && !childShelfIds.isEmpty()) {
|
|
|
|
|
+ parentCount = b2cGoodsStatusMapper.countShelfGoodsByIds(childShelfIds);
|
|
|
|
|
+ parentCount = Math.max(parentCount - 1, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ b2cGoodsStatusMapper.updateShelfGoodsCount(parentId, parentCount);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除SKU并清除Redis缓存(对应PHP delSkuByGdId + Redis删除)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void deleteSkusAndClearCache(Integer gdId) {
|
|
|
|
|
+ // 先查询sku_id用于清除缓存
|
|
|
|
|
+ List<Integer> skuIds = b2cGoodsStatusMapper.findSkuIdsByGdId(gdId);
|
|
|
|
|
+
|
|
|
|
|
+ // 删除SKU记录
|
|
|
|
|
+ b2cGoodsStatusMapper.deleteSkusByGdId(gdId);
|
|
|
|
|
+
|
|
|
|
|
+ // 清除Redis缓存
|
|
|
|
|
+ if (skuIds != null && !skuIds.isEmpty()) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (Integer skuId : skuIds) {
|
|
|
|
|
+ redisUtils.del(String.valueOf(skuId));
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("Redis缓存清除失败 gdId={}", gdId, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Result processSupplyItem(Long goodsId, Integer issupply, Integer cate, Integer uniacid, Integer storeid) {
|
|
public Result processSupplyItem(Long goodsId, Integer issupply, Integer cate, Integer uniacid, Integer storeid) {
|