feat:共富商城订单适配

This commit is contained in:
dzc committed 2025-10-22 16:55:13 +08:00
1 parent 0a0bccdc54
commit ee6783ab4f
2 files changed
+93 -2

No files matched your search

@@ -28,12 +28,14 @@ import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.mapper.order.HardParentCarMapper;
import com.bsd.pjcloud.hard.service.HardCarService;
import com.bsd.pjcloud.hard.service.HardSpuService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteMallProductService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteShopSkuService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteShopSpuService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketUnitSkuService;
import com.bsd.pjcloud.supermarket.entity.ShopSkuEntity;
import com.bsd.pjcloud.supermarket.vo.app.ShopSpuDetailAppVo;
import com.bsd.pjcloud.supermarket.vo.erp.SmErpUnitWithSpuVo;
import com.bsd.pjcloud.supermarket.vo.mall.MallProductDetailAppVo;
import com.bsd.pjcloud.thirdparty.dto.pay.PayDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -68,6 +70,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
private final RemoteSupermarketUnitSkuService supermarketUnitSkuService;
private final RemoteShopSkuService remoteShopSkuService;
private final RemoteShopSpuService remoteShopSpuService;
private final RemoteMallProductService remoteMallProductService;
@Override
public Page<HardCarVo> pageJoin(Page page, HardCarDto dto) {
@@ -416,6 +419,38 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
baseMapper.insert(carObjectList);
return;
}
// 共富商城
if (ObjectUtil.equals(sysType, HardTypeEnum.FARMER)) {
List<HardCarEntity> carObjectList = new ArrayList<>();
List<MallProductDetailAppVo> spuList = remoteMallProductService.getDetailByIds(productIds).getData();
for (HardCreateCarDto v : productList) {
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build();
spuList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
Integer price = getSupermarket(spu);
int totalPrice = 0;
if (ObjectUtil.isNotEmpty(v.getProductCount()) && !ObjectUtil.equals(v.getProductCount(), 0)) {
// 按数量
totalPrice = v.getProductCount() * price;
} else if (ObjectUtil.isNotEmpty(v.getProductWeight()) && v.getProductWeight().compareTo(BigDecimal.valueOf(0)) != 0) {
// 按重量
totalPrice = v.getProductWeight().multiply(BigDecimal.valueOf(price)).setScale(0, RoundingMode.CEILING).intValue();
}
item.setProductId(spu.getId());
item.setProductName(spu.getTitle());
item.setProductPrice(price);
item.setProductPic(spu.getCoverImage());
item.setTotalPrice((long) totalPrice);
if (ObjectUtil.isNotEmpty(v.getProductNature())) {
item.setProductNature(v.getProductNature().getType());
}
item.setProductCount(v.getProductCount());
item.setProductWeight(v.getProductWeight());
carObjectList.add(item);
});
}
baseMapper.insert(carObjectList);
return;
}
}
@Override
@@ -463,10 +498,16 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
}
// 共富商城
if (ObjectUtil.equals(sysType, HardTypeEnum.FARMER)) {
List<HardSpuEntity> supList = hardSpuService.getByIds(productIds);
List<MallProductDetailAppVo> supList = remoteMallProductService.getDetailByIds(productIds).getData();
for (HardCreateCarDto v : list) {
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> {
str.append(spu.getName()).append("x").append(v.getProductCount()).append(";");
str.append(spu.getTitle()).append("x");
if (ObjectUtil.equals(spu.getProductNature(), HardProductNatureEnum.DEFAULT.getType())) {
str.append(v.getProductCount());
} else if (ObjectUtil.equals(spu.getProductNature(), HardProductNatureEnum.WEIGHT.getType())) {
str.append(v.getProductWeight()).append("/kg");
}
str.append(";");
});
}
}
@@ -65,9 +65,11 @@ import com.bsd.pjcloud.hard.api.vo.wechat.WechatMicropayVo;
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.service.*;
import com.bsd.pjcloud.supermarket.api.feign.RemoteMallProductService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteShopSkuService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteShopSpuService;
import com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketSpuService;
import com.bsd.pjcloud.supermarket.dto.MallProductStockChangeDTO;
import com.bsd.pjcloud.supermarket.dto.SkuStockChangeDTO;
import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockReqDTO;
import com.bsd.pjcloud.supermarket.entity.ShopSkuEntity;
@@ -150,6 +152,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
private final RemoteSupermarketSpuService supermarketSpuService;
private final RemoteShopSkuService remoteShopSkuService;
private final RemoteActCancelService remoteActCancelService;
private final RemoteMallProductService remoteMallProductService;
private final HardManagerMapper hardManagerMapper;
@@ -1304,6 +1307,53 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
log.info("扣减智能柜库存成功|{}|{},成功,order:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(list));
return;
}
// 共富商城
if (ObjectUtil.equals(HardOrderTypeEnum.FARMER, orderTypeEnum)) {
// 查询购物车
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
// 扣件库存
MallProductStockChangeDTO dto = new MallProductStockChangeDTO();
dto.setDeviceType(0);
List<MallProductStockChangeDTO.Item> itemList = carList.stream().map(v -> {
MallProductStockChangeDTO.Item item = new MallProductStockChangeDTO.Item();
item.setId(v.getProductId());
item.setProductType(1);
if (ObjectUtil.isNotEmpty(v.getProductCount()) && !ObjectUtil.equals(v.getProductCount(), 0)) {
// 按数量
int prouctCount = v.getProductCount();
// 如果退款购物车数组里有,就用退款购物车的数量
if (ObjectUtil.isNotEmpty(refundCarList)) {
HardCarEntity refundCarTarget = refundCarList.stream().filter(i -> ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) {
prouctCount = refundCarTarget.getProductCount();
}
}
double count = BigDecimal.valueOf(prouctCount).multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue();
item.setIncrCount(count);
} else if (ObjectUtil.isNotEmpty(v.getProductWeight()) && v.getProductWeight().compareTo(BigDecimal.valueOf(0)) != 0) {
// 按重量
BigDecimal productWeight = v.getProductWeight();
// 如果退款购物车数组里有,就用退款购物车的数量
if (ObjectUtil.isNotEmpty(refundCarList)) {
HardCarEntity refundCarTarget = refundCarList.stream().filter(i -> ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null);
if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) {
productWeight = refundCarTarget.getProductWeight();
}
}
double weight = productWeight.multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue();
item.setIncrCount(weight);
}
return item;
}).toList();
dto.setItems(itemList);
R<Boolean> updateSkuStockRes = remoteMallProductService.deductStock(dto);
if (updateSkuStockRes.getCode() != 0 || !updateSkuStockRes.getData()) {
log.info("|{}|{},失败,order:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(dto));
throw new RuntimeException(CarErrorMsg + "错误");
}
log.info("|{}|{},成功,order:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(dto));
return;
}
}
// 发送mq消息