| | |
| | | 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) { |
| | |
| | | } |
| | | // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用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("商品兑换失败!"); |