feat:超市线上商城对接

This commit is contained in:
dzc committed 2025-08-29 17:05:28 +08:00
1 parent 4932778cdd
commit 2b4ecf485e
4 files changed
+119 -61

No files matched your search

@@ -28,7 +28,11 @@ import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.mapper.order.HardParentCarMapper; import com.bsd.pjcloud.hard.mapper.order.HardParentCarMapper;
import com.bsd.pjcloud.hard.service.HardCarService; import com.bsd.pjcloud.hard.service.HardCarService;
import com.bsd.pjcloud.hard.service.HardSpuService; import com.bsd.pjcloud.hard.service.HardSpuService;
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.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.erp.SmErpUnitWithSpuVo;
import com.bsd.pjcloud.thirdparty.dto.pay.PayDto; import com.bsd.pjcloud.thirdparty.dto.pay.PayDto;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -62,6 +66,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
private final RemoteOnlineCanteenSpuService onlineCanteenSpuService; private final RemoteOnlineCanteenSpuService onlineCanteenSpuService;
private final RemoteCanteenSpuService canteenSpuService; private final RemoteCanteenSpuService canteenSpuService;
private final RemoteSupermarketUnitSkuService supermarketUnitSkuService; private final RemoteSupermarketUnitSkuService supermarketUnitSkuService;
private final RemoteShopSkuService remoteShopSkuService;
private final RemoteShopSpuService remoteShopSpuService;
@Override @Override
public Page<HardCarVo> pageJoin(Page page, HardCarDto dto) { public Page<HardCarVo> pageJoin(Page page, HardCarDto dto) {
@@ -295,32 +301,60 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
// 超市 // 超市
if (ObjectUtil.equals(sysType, HardTypeEnum.SUPERMARKET)) { if (ObjectUtil.equals(sysType, HardTypeEnum.SUPERMARKET)) {
List<HardCarEntity> carObjectList = new ArrayList<>(); List<HardCarEntity> carObjectList = new ArrayList<>();
List<SmErpUnitWithSpuVo> supList = supermarketUnitSkuService.getSupermarketUnits(productIds).getData(); // 线上
for (HardCreateCarDto v : productList) { if (ObjectUtil.equals(HardOrderTypeEnum.RESERVE, orderType)) {
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build(); List<ShopSkuEntity> skuList = remoteShopSkuService.getSelectListAll(productIds).getData();
supList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(spu -> { List<ShopSpuDetailAppVo> spuList = remoteShopSpuService.getShopSpuDetailByIds(skuList.stream().map(ShopSkuEntity::getSpuId).toList()).getData();
Integer price = getSupermarket(spu); for (HardCreateCarDto v : productList) {
int totalPrice = 0; HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build();
// 按重量 skuList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(sku -> {
if (ObjectUtil.isNotEmpty(v.getProductCount()) && !ObjectUtil.equals(v.getProductCount(), 0)) { Integer price = getSupermarket(sku);
// 按数量 int totalPrice = 0;
totalPrice = v.getProductCount() * price; totalPrice = v.getProductCount() * price;
} else if (ObjectUtil.isNotEmpty(v.getProductWeight()) && v.getProductWeight().compareTo(BigDecimal.valueOf(0)) != 0) { // 找到spu
// 按重量 ShopSpuDetailAppVo spu = spuList.stream().filter(i -> ObjectUtil.equals(i.getId(), sku.getSpuId())).findFirst().orElse(null);
totalPrice = v.getProductWeight().multiply(BigDecimal.valueOf(price)).setScale(0, RoundingMode.CEILING).intValue(); item.setProductId(sku.getId());
} item.setProductPrice(price);
item.setProductId(spu.getId()); item.setTotalPrice((long) totalPrice);
item.setProductName(spu.getProductName()); item.setProductNature(HardProductNatureEnum.DEFAULT.getType());
item.setProductPrice(price); item.setProductCount(v.getProductCount());
item.setProductPic(spu.getPicUrl()); item.setProductWeight(BigDecimal.ZERO);
item.setTotalPrice((long) totalPrice); if (ObjectUtil.isNotEmpty(spu)) {
if (ObjectUtil.isNotEmpty(v.getProductNature())) { item.setProductName(spu.getProductName());
item.setProductNature(v.getProductNature().getType()); item.setProductPic(spu.getPicUrl());
} }
item.setProductCount(v.getProductCount()); carObjectList.add(item);
item.setProductWeight(v.getProductWeight()); });
carObjectList.add(item); }
}); }
// 线下
if (ObjectUtil.equals(HardOrderTypeEnum.BELOW, orderType)) {
List<SmErpUnitWithSpuVo> spuList = supermarketUnitSkuService.getSupermarketUnits(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.getProductName());
item.setProductPrice(price);
item.setProductPic(spu.getPicUrl());
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); baseMapper.insert(carObjectList);
return; return;
@@ -416,7 +450,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
); );
} }
// 获取超市商品价格 // 获取线下超市商品价格
private Integer getSupermarket(SmErpUnitWithSpuVo vo) { private Integer getSupermarket(SmErpUnitWithSpuVo vo) {
if (ObjectUtil.isEmpty(vo)) return 0; if (ObjectUtil.isEmpty(vo)) return 0;
if (ObjectUtil.isNotEmpty(vo.getPromotionPrice()) && !ObjectUtil.equals(vo.getPromotionPrice(), 0)) { if (ObjectUtil.isNotEmpty(vo.getPromotionPrice()) && !ObjectUtil.equals(vo.getPromotionPrice(), 0)) {
@@ -428,6 +462,18 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
return 0; return 0;
} }
// 获取线上超市商品价格
private Integer getSupermarket(ShopSkuEntity vo) {
if (ObjectUtil.isEmpty(vo)) return 0;
if (ObjectUtil.isNotEmpty(vo.getPromotionPrice()) && !ObjectUtil.equals(vo.getPromotionPrice(), 0)) {
return vo.getPromotionPrice();
}
if (ObjectUtil.isNotEmpty(vo.getRetailPrice())) {
return vo.getRetailPrice();
}
return 0;
}
private HardCarServiceImpl getSelf() { private HardCarServiceImpl getSelf() {
return SpringUtil.getBean(getClass()); return SpringUtil.getBean(getClass());
} }
@@ -55,8 +55,12 @@ import com.bsd.pjcloud.hard.api.vo.wechat.WechatMicropayVo;
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper; import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper; import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
import com.bsd.pjcloud.hard.service.*; import com.bsd.pjcloud.hard.service.*;
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.api.feign.RemoteSupermarketSpuService;
import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockReqDTO; import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockReqDTO;
import com.bsd.pjcloud.supermarket.entity.ShopSkuEntity;
import com.bsd.pjcloud.supermarket.vo.app.ShopSpuDetailAppVo;
import com.bsd.pjcloud.thirdparty.dto.ks.KsRecognitionCallbackDto; import com.bsd.pjcloud.thirdparty.dto.ks.KsRecognitionCallbackDto;
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum; import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
import com.bsd.pjcloud.wallet.api.constant.WalletCodeBizEnum; import com.bsd.pjcloud.wallet.api.constant.WalletCodeBizEnum;
@@ -131,6 +135,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
private final RemoteOnlineCanteenSpuService onlineCanteenSpuService; private final RemoteOnlineCanteenSpuService onlineCanteenSpuService;
private final RemoteSupermarketSpuService supermarketSpuService; private final RemoteSupermarketSpuService supermarketSpuService;
private final RemoteShopSkuService remoteShopSkuService;
private final HardManagerMapper hardManagerMapper; private final HardManagerMapper hardManagerMapper;
@@ -902,45 +907,51 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
// 查询购物车 // 查询购物车
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId()); List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在"); if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在");
SupermarketSpuUpdateStockReqDTO dto = new SupermarketSpuUpdateStockReqDTO(); // 线下
List<SupermarketSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> { if (ObjectUtil.equals(HardOrderTypeEnum.BELOW, orderTypeEnum)) {
SupermarketSpuUpdateStockReqDTO.Item item = new SupermarketSpuUpdateStockReqDTO.Item(); SupermarketSpuUpdateStockReqDTO dto = new SupermarketSpuUpdateStockReqDTO();
item.setId(v.getProductId()); List<SupermarketSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
if (ObjectUtil.isNotEmpty(v.getProductCount()) && !ObjectUtil.equals(v.getProductCount(), 0)) { SupermarketSpuUpdateStockReqDTO.Item item = new SupermarketSpuUpdateStockReqDTO.Item();
// 按数量 item.setId(v.getProductId());
int prouctCount = v.getProductCount(); if (ObjectUtil.isNotEmpty(v.getProductCount()) && !ObjectUtil.equals(v.getProductCount(), 0)) {
// 如果退款购物车数组里有,就用退款购物车的数量 // 按数量
if (ObjectUtil.isNotEmpty(refundCarList)) { int prouctCount = v.getProductCount();
HardCarEntity refundCarTarget = refundCarList.stream().filter(i -> ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null); // 如果退款购物车数组里有,就用退款购物车的数量
if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) { if (ObjectUtil.isNotEmpty(refundCarList)) {
prouctCount = refundCarTarget.getProductCount(); 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();
double count = BigDecimal.valueOf(prouctCount).multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue(); item.setIncrCount(count);
item.setIncrCount(count); } else if (ObjectUtil.isNotEmpty(v.getProductWeight()) && v.getProductWeight().compareTo(BigDecimal.valueOf(0)) != 0) {
} else if (ObjectUtil.isNotEmpty(v.getProductWeight()) && v.getProductWeight().compareTo(BigDecimal.valueOf(0)) != 0) { // 按重量
// 按重量 BigDecimal productWeight = v.getProductWeight();
BigDecimal productWeight = v.getProductWeight(); // 如果退款购物车数组里有,就用退款购物车的数量
// 如果退款购物车数组里有,就用退款购物车的数量 if (ObjectUtil.isNotEmpty(refundCarList)) {
if (ObjectUtil.isNotEmpty(refundCarList)) { HardCarEntity refundCarTarget = refundCarList.stream().filter(i -> ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null);
HardCarEntity refundCarTarget = refundCarList.stream().filter(i -> ObjectUtil.equals(i.getProductId(), v.getProductId())).findFirst().orElse(null); if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) {
if (ObjectUtil.isNotEmpty(refundCarTarget) && ObjectUtil.isNotEmpty(refundCarTarget.getProductCount())) { productWeight = refundCarTarget.getProductWeight();
productWeight = refundCarTarget.getProductWeight(); }
} }
double weight = productWeight.multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue();
item.setIncrCount(weight);
} }
double weight = productWeight.multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue(); return item;
item.setIncrCount(weight); }).filter(v -> ObjectUtil.isNotEmpty(v.getIncrCount()) && v.getIncrCount() > 0).toList();
dto.setItems(list);
R updateSkuStockRes = supermarketSpuService.updateSpuStock(dto);
if (updateSkuStockRes.getCode() != 0) {
log.info("|{}|{},失败,order:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(dto));
throw new RuntimeException(CarErrorMsg + "错误");
} }
return item; log.info("|{}|{},成功,order:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(dto));
}).filter(v -> ObjectUtil.isNotEmpty(v.getIncrCount()) && v.getIncrCount() > 0).toList(); return;
dto.setItems(list); }
R updateSkuStockRes = supermarketSpuService.updateSpuStock(dto); if (ObjectUtil.equals(HardOrderTypeEnum.RESERVE, orderTypeEnum)) {
if (updateSkuStockRes.getCode() != 0) { return;
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;
} }
// 智能柜扣减库存 // 智能柜扣减库存
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.DOOR)) { if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.DOOR)) {
@@ -62,7 +62,7 @@ public interface RemoteShopSkuService {
* 查询所有sku列表信息,根据条件skuIds * 查询所有sku列表信息,根据条件skuIds
* @return R * @return R
*/ */
@PostMapping("/shopSku/selectListAll") @GetMapping("/shopSku/selectListAll")
R<List<ShopSkuEntity>> getSelectListAll(@RequestParam List<Long> ids); R<List<ShopSkuEntity>> getSelectListAll(@RequestParam List<Long> ids);
@@ -3,3 +3,4 @@ com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketSpuService
com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketUnitSkuService com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketUnitSkuService
com.bsd.pjcloud.supermarket.api.feign.RemoteShopCategoryService com.bsd.pjcloud.supermarket.api.feign.RemoteShopCategoryService
com.bsd.pjcloud.supermarket.api.feign.RemoteShopSpuService com.bsd.pjcloud.supermarket.api.feign.RemoteShopSpuService
com.bsd.pjcloud.supermarket.api.feign.RemoteShopSkuService