xiaoyong931011
2022-09-15 c2a0a337498445683f81e33597bf694e0dc9fb68
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -76,6 +76,8 @@
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final MallLeaderAchieveMapper mallLeaderAchieveMapper;
    private final IApiMallTeamLeaderService iApiMallTeamLeaderService;
    private final IMallElectronicFenceService iMallElectronicFenceService;
    private final MallElectronicFenceMapper mallElectronicFenceMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -90,6 +92,17 @@
        MallTeamLeader mallTeamLeader = mallTeamLeaderMapper.selectLeaderByUniqueCode(takeUniqueCode);
        if(ObjectUtil.isEmpty(mallTeamLeader)){
            throw new FebsException("请重新选择团长");
        }
        //订单范围内才允许下单
        MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId());
        MallElectronicFence mallElectronicFence = mallElectronicFenceMapper.selectByTeamLeaderCode(mallTeamLeader.getUniqueCode());
        if(ObjectUtil.isNotEmpty(mallElectronicFence)){
            String inStr = iMallElectronicFenceService.fenceToLocation(mallElectronicFence.getGKey(),
                    mallElectronicFence.getServiceId(), address.getLongitude() + "," + address.getLatitude(), mallElectronicFence.getGid());
            if("1".equals(inStr)){
                throw new FebsException("不在当前团长的配送范围内");
            }
        }
        String orderNo = MallUtils.getOrderNum();
@@ -161,9 +174,12 @@
                        throw new FebsException(mallGoods.getGoodsName() + "已下架");
                    }
                    mallGoods.setStock(mallGoods.getStock() - item.getCnt());
                    mallGoods.setVolume(mallGoods.getVolume() + item.getCnt());
                    mallGoodsMapper.updateById(mallGoods);
//                    mallGoods.setStock(mallGoods.getStock() - item.getCnt());
//                    mallGoods.setVolume(mallGoods.getVolume() + item.getCnt());
                    Integer goodsResult = mallGoodsMapper.upDateStockAndVolumeByGoodsId(mallGoods.getId(), item.getCnt());
                    if(1 != goodsResult){
                        throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                    }
                    BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
                    orderItem.setAmount(amount);
@@ -183,10 +199,13 @@
                    total = total.add(amount);
                    carriage = carriage.add(mallGoods.getCarriage());
                    sku.setStock(sku.getStock() - item.getCnt());
                    sku.setSkuVolume(sku.getSkuVolume() + item.getCnt());
                    mallGoodsSkuMapper.updateById(sku);
//                    sku.setStock(sku.getStock() - item.getCnt());
//                    sku.setSkuVolume(sku.getSkuVolume() + item.getCnt());
//                    mallGoodsSkuMapper.updateById(sku);
                    Integer skuResult = mallGoodsSkuMapper.upDateStockAndVolumeBySkuId(sku.getId(),item.getCnt());
                    if(1 != skuResult){
                        throw new FebsException(sku.getSkuName() + "库存不足");
                    }
                    if (addOrderDto.getType() == 1) {
                        mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId());
                    }
@@ -201,7 +220,6 @@
        }
        orderInfo.setAmount(total);
        MallAddressInfo address = mallAddressInfoMapper.selectAddressInfoByMemberIdAndId(member.getId(), addOrderDto.getAddressId());
        orderInfo.setName(address.getName());
        orderInfo.setPhone(address.getPhone());
        orderInfo.setIsHome(addOrderDto.getIsHome());