xiaoyong931011
2022-09-13 42fa8b7f0c1c8c5588bd7d0efe26521095c2154e
20220902
1 files modified
144 ■■■■ changed files
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java 144 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -111,86 +111,88 @@
        BigDecimal total = BigDecimal.ZERO;
        BigDecimal carriage = BigDecimal.ZERO;
        for (AddOrderItemDto item : addOrderDto.getItems()) {
            MallOrderItem orderItem = new MallOrderItem();
            synchronized(item){
                MallOrderItem orderItem = new MallOrderItem();
            // 积分商品提交订单
            if (addOrderDto.getOrderType() == 2) {
                MallGoods mallGoods = mallGoodsMapper.selectById(item.getSkuId());
                if (mallGoods.getStock() < item.getCnt()) {
                    throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                }
                // 积分商品提交订单
                if (addOrderDto.getOrderType() == 2) {
                    MallGoods mallGoods = mallGoodsMapper.selectById(item.getSkuId());
                    if (mallGoods.getStock() < item.getCnt()) {
                        throw new FebsException(mallGoods.getGoodsName() + "库存不足");
                    }
                if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                    throw new FebsException(mallGoods.getGoodsName() + "已下架");
                }
                    if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                        throw new FebsException(mallGoods.getGoodsName() + "已下架");
                    }
                BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt()));
                orderItem.setAmount(amount);
                orderItem.setCnt(item.getCnt());
                orderItem.setOrderId(orderInfo.getId());
                orderItem.setPrice(mallGoods.getScore());
                orderItem.setGoodsId(mallGoods.getId());
                orderItem.setGoodsName(mallGoods.getGoodsName());
                orderItem.setStyleName(mallGoods.getGoodsName());
                orderItem.setSkuName(mallGoods.getGoodsName());
                orderItem.setSkuImage(mallGoods.getThumb());
                orderItem.setState(1);
                    BigDecimal amount = mallGoods.getScore().multiply(BigDecimal.valueOf(item.getCnt()));
                    orderItem.setAmount(amount);
                    orderItem.setCnt(item.getCnt());
                    orderItem.setOrderId(orderInfo.getId());
                    orderItem.setPrice(mallGoods.getScore());
                    orderItem.setGoodsId(mallGoods.getId());
                    orderItem.setGoodsName(mallGoods.getGoodsName());
                    orderItem.setStyleName(mallGoods.getGoodsName());
                    orderItem.setSkuName(mallGoods.getGoodsName());
                    orderItem.setSkuImage(mallGoods.getThumb());
                    orderItem.setState(1);
                total = total.add(amount);
            } else {
                MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
                if (sku == null) {
                    throw new FebsException("购买商品或sku不存在");
                }
                    total = total.add(amount);
                } else {
                    MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
                    if (sku == null) {
                        throw new FebsException("购买商品或sku不存在");
                    }
                if (sku.getStock() < item.getCnt()) {
                    throw new FebsException(sku.getSkuName() + "库存不足");
                }
                    if (sku.getStock() < item.getCnt()) {
                        throw new FebsException(sku.getSkuName() + "库存不足");
                    }
                MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
                // 零撸专区购买
                if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) {
                    List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId());
                    if (CollUtil.isNotEmpty(items)) {
                        throw new FebsException("无法重复领取同一个商品");
                    MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
                    // 零撸专区购买
                    if (new BigDecimal(mallGoods.getPresentPrice()).compareTo(BigDecimal.ZERO) == 0) {
                        List<MallOrderItem> items = mallOrderItemMapper.selectItemByGoodsIdUnCancel(mallGoods.getId(), member.getId());
                        if (CollUtil.isNotEmpty(items)) {
                            throw new FebsException("无法重复领取同一个商品");
                        }
                    }
                    if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                        throw new FebsException(mallGoods.getGoodsName() + "已下架");
                    }
                    mallGoods.setStock(mallGoods.getStock() - item.getCnt());
                    mallGoods.setVolume(mallGoods.getVolume() + item.getCnt());
                    mallGoodsMapper.updateById(mallGoods);
                    BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
                    orderItem.setAmount(amount);
                    orderItem.setCnt(item.getCnt());
                    orderItem.setOrderId(orderInfo.getId());
                    orderItem.setPrice(sku.getPresentPrice());
                    orderItem.setGoodsId(sku.getGoodsId());
                    orderItem.setGoodsName(sku.getGoodsName());
                    orderItem.setSkuId(sku.getId());
                    orderItem.setState(1);
                    orderItem.setStyleName(sku.getStyleName());
                    orderItem.setSkuName(sku.getSkuName());
                    orderItem.setSkuImage(sku.getSkuImage());
                    orderItem.setIsNormal(mallGoods.getIsNormal());
                    orderItem.setCostPrice(sku.getCostPrice());
                    total = total.add(amount);
                    carriage = carriage.add(mallGoods.getCarriage());
                    sku.setStock(sku.getStock() - item.getCnt());
                    sku.setSkuVolume(sku.getSkuVolume() + item.getCnt());
                    mallGoodsSkuMapper.updateById(sku);
                    if (addOrderDto.getType() == 1) {
                        mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId());
                    }
                }
                if (MallGoods.ISSALE_STATUS_DISABLED.equals(mallGoods.getIsSale())) {
                    throw new FebsException(mallGoods.getGoodsName() + "已下架");
                }
                mallGoods.setStock(mallGoods.getStock() - item.getCnt());
                mallGoods.setVolume(mallGoods.getVolume() + item.getCnt());
                mallGoodsMapper.updateById(mallGoods);
                BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
                orderItem.setAmount(amount);
                orderItem.setCnt(item.getCnt());
                orderItem.setOrderId(orderInfo.getId());
                orderItem.setPrice(sku.getPresentPrice());
                orderItem.setGoodsId(sku.getGoodsId());
                orderItem.setGoodsName(sku.getGoodsName());
                orderItem.setSkuId(sku.getId());
                orderItem.setState(1);
                orderItem.setStyleName(sku.getStyleName());
                orderItem.setSkuName(sku.getSkuName());
                orderItem.setSkuImage(sku.getSkuImage());
                orderItem.setIsNormal(mallGoods.getIsNormal());
                orderItem.setCostPrice(sku.getCostPrice());
                total = total.add(amount);
                carriage = carriage.add(mallGoods.getCarriage());
                sku.setStock(sku.getStock() - item.getCnt());
                sku.setSkuVolume(sku.getSkuVolume() + item.getCnt());
                mallGoodsSkuMapper.updateById(sku);
                if (addOrderDto.getType() == 1) {
                    mallShoppingCartMapper.delBySkuId(sku.getId(), member.getId());
                }
                mallOrderItemMapper.insert(orderItem);
            }
            mallOrderItemMapper.insert(orderItem);
        }
        //配送费
        BigDecimal delivaryAmount = addOrderDto.getDeliveryAmount() == null ? BigDecimal.ZERO : addOrderDto.getDeliveryAmount();