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.service.HardCarService;
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.entity.ShopSkuEntity;
import com.bsd.pjcloud.supermarket.vo.app.ShopSpuDetailAppVo;
import com.bsd.pjcloud.supermarket.vo.erp.SmErpUnitWithSpuVo;
import com.bsd.pjcloud.thirdparty.dto.pay.PayDto;
import lombok.RequiredArgsConstructor;
@@ -62,6 +66,8 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
private final RemoteOnlineCanteenSpuService onlineCanteenSpuService;
private final RemoteCanteenSpuService canteenSpuService;
private final RemoteSupermarketUnitSkuService supermarketUnitSkuService;
private final RemoteShopSkuService remoteShopSkuService;
private final RemoteShopSpuService remoteShopSpuService;
@Override
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)) {
List<HardCarEntity> carObjectList = new ArrayList<>();
List<SmErpUnitWithSpuVo> supList = supermarketUnitSkuService.getSupermarketUnits(productIds).getData();
for (HardCreateCarDto v : productList) {
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build();
supList.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)) {
// 按数量
// 线上
if (ObjectUtil.equals(HardOrderTypeEnum.RESERVE, orderType)) {
List<ShopSkuEntity> skuList = remoteShopSkuService.getSelectListAll(productIds).getData();
List<ShopSpuDetailAppVo> spuList = remoteShopSpuService.getShopSpuDetailByIds(skuList.stream().map(ShopSkuEntity::getSpuId).toList()).getData();
for (HardCreateCarDto v : productList) {
HardCarEntity item = HardCarEntity.builder().parentCarId(parentCarId).build();
skuList.stream().filter(i -> ObjectUtil.equals(i.getId(), v.getProductId())).findFirst().ifPresent(sku -> {
Integer price = getSupermarket(sku);
int totalPrice = 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);
});
// 找到spu
ShopSpuDetailAppVo spu = spuList.stream().filter(i -> ObjectUtil.equals(i.getId(), sku.getSpuId())).findFirst().orElse(null);
item.setProductId(sku.getId());
item.setProductPrice(price);
item.setTotalPrice((long) totalPrice);
item.setProductNature(HardProductNatureEnum.DEFAULT.getType());
item.setProductCount(v.getProductCount());
item.setProductWeight(BigDecimal.ZERO);
if (ObjectUtil.isNotEmpty(spu)) {
item.setProductName(spu.getProductName());
item.setProductPic(spu.getPicUrl());
}
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);
return;
@@ -416,7 +450,7 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
);
}
// 获取超市商品价格
// 获取线下超市商品价格
private Integer getSupermarket(SmErpUnitWithSpuVo vo) {
if (ObjectUtil.isEmpty(vo)) return 0;
if (ObjectUtil.isNotEmpty(vo.getPromotionPrice()) && !ObjectUtil.equals(vo.getPromotionPrice(), 0)) {
@@ -428,6 +462,18 @@ public class HardCarServiceImpl extends ServiceImpl<HardCarMapper, HardCarEntity
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() {
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.order.HardOrderMapper;
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.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.wallet.api.constant.WalletBizEnum;
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 RemoteSupermarketSpuService supermarketSpuService;
private final RemoteShopSkuService remoteShopSkuService;
private final HardManagerMapper hardManagerMapper;
@@ -902,45 +907,51 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
// 查询购物车
List<HardCarEntity> carList = hardCarService.getByParentCarId(order.getParentCarId());
if (ObjectUtil.isEmpty(carList)) throw new RuntimeException("扣减库存错误,购物车不存在");
SupermarketSpuUpdateStockReqDTO dto = new SupermarketSpuUpdateStockReqDTO();
List<SupermarketSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
SupermarketSpuUpdateStockReqDTO.Item item = new SupermarketSpuUpdateStockReqDTO.Item();
item.setId(v.getProductId());
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();
// 线下
if (ObjectUtil.equals(HardOrderTypeEnum.BELOW, orderTypeEnum)) {
SupermarketSpuUpdateStockReqDTO dto = new SupermarketSpuUpdateStockReqDTO();
List<SupermarketSpuUpdateStockReqDTO.Item> list = carList.stream().map(v -> {
SupermarketSpuUpdateStockReqDTO.Item item = new SupermarketSpuUpdateStockReqDTO.Item();
item.setId(v.getProductId());
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 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);
}
double weight = productWeight.multiply(BigDecimal.valueOf(base)).setScale(2, RoundingMode.HALF_UP).doubleValue();
item.setIncrCount(weight);
return item;
}).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;
}).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 + "错误");
log.info("|{}|{},成功,order:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(dto));
return;
}
if (ObjectUtil.equals(HardOrderTypeEnum.RESERVE, orderTypeEnum)) {
return;
}
log.info("|{}|{},成功,order:|{}|,isReduce:|{}|,params:|{}|", TAG, CarErrorMsg, JSON.toJSON(order), isReduce, JSON.toJSON(dto));
return;
}
// 智能柜扣减库存
if (ObjectUtil.equals(hardTypeEnum, HardTypeEnum.DOOR)) {
@@ -62,7 +62,7 @@ public interface RemoteShopSkuService {
* 查询所有sku列表信息,根据条件skuIds
* @return R
*/
@PostMapping("/shopSku/selectListAll")
@GetMapping("/shopSku/selectListAll")
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.RemoteShopCategoryService
com.bsd.pjcloud.supermarket.api.feign.RemoteShopSpuService
com.bsd.pjcloud.supermarket.api.feign.RemoteShopSkuService