diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java index f16ffac49..4d42cf77c 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardCarServiceImpl.java @@ -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 pageJoin(Page page, HardCarDto dto) { @@ -416,6 +419,38 @@ public class HardCarServiceImpl extends ServiceImpl carObjectList = new ArrayList<>(); + List 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 supList = hardSpuService.getByIds(productIds); + List 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(";"); }); } } diff --git a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderServiceImpl.java b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderServiceImpl.java index a9f2cc62f..bf2d91be7 100644 --- a/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderServiceImpl.java +++ b/pjcloud-hardware/pjcloud-hardware-biz/src/main/java/com/bsd/pjcloud/hard/service/impl/order/HardOrderServiceImpl.java @@ -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 carList = hardCarService.getByParentCarId(order.getParentCarId()); + // 扣件库存 + MallProductStockChangeDTO dto = new MallProductStockChangeDTO(); + dto.setDeviceType(0); + List 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 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消息