hjl
2024-06-21 a9bf1fc6ffb80c2de56e1730595b3abde4910484
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/TGoodsServiceImpl.java
@@ -68,7 +68,10 @@
            String key = String.format(RedisConstants.GOOD_STOCK, goods.getId());
            List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId)
                    .eq(TOrder::getDisabled, 0).list();
            int sum = orderList.stream().map(TOrder::getCount).mapToInt(Integer::intValue).sum();
            int sum = 0;
            if (!orderList.isEmpty()) {
                sum = orderList.stream().map(TOrder::getCount).mapToInt(Integer::intValue).sum();
            }
            // 计算商品剩余可兑换数量
            int number = goods.getTotal() - sum;
            if (number <= 0) {
@@ -127,9 +130,6 @@
            }
            // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务)
            boolean result = exchangeGood(goodExchange, recipient, number, goodId, needIntegral);
            // 扣除库存
            result = result && this.lambdaUpdate().set(TGoods::getTotal, good.getTotal() - number)
                    .eq(TGoods::getId, good.getId()).update();
            if (!result) {
                semaphore.release(number);
                return R.exchangeError("商品兑换失败!");