| | |
| | | // 检查库存总数是否足够 |
| | | List<TOrder> order = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId) |
| | | .eq(TOrder::getDisabled, 0).list(); |
| | | int item; |
| | | if (!order.isEmpty()) { |
| | | int totalNumber = order.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | item = order.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | boolean canBuy = good.getTotal() - totalNumber >= number; |
| | | if (!canBuy) { |
| | | throw new GlobalException("商品库存不足,兑换失败!"); |
| | | } |
| | | } else { |
| | | item = 0; |
| | | } |
| | | boolean canBuy = good.getTotal() - item >= number; |
| | | if (!canBuy) { |
| | | throw new GlobalException("商品库存不足,兑换失败!"); |
| | | } |
| | | // 检查用户兑换数量是否超过单用户最大兑换数量 |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) |
| | | .eq(TOrder::getGoodsId, goodId).list(); |
| | | // 该商品订单为空、订单数量未超过商品的单个用户兑换上限数量时,可以进行兑换 |
| | | int totalNumber = orderList.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | int totalNumber; |
| | | if (orderList.isEmpty()) { |
| | | totalNumber = 0; |
| | | } else { |
| | | // 该商品订单为空、订单数量未超过商品的单个用户兑换上限数量时,可以进行兑换 |
| | | totalNumber = orderList.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | } |
| | | boolean canExchange = orderList.isEmpty() || null == good.getUserCount() || |
| | | (totalNumber + number) <= good.getUserCount(); |
| | | if (!canExchange) { |
| | |
| | | return R.exchangeError("商品兑换失败!"); |
| | | } |
| | | } else { |
| | | if (null != good.getUserCount()) { |
| | | // 检查用户兑换数量是否超过单用户最大兑换数量 |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) |
| | | .eq(TOrder::getGoodsId, goodId).list(); |
| | | int totalNumber; |
| | | if (orderList.isEmpty()) { |
| | | totalNumber = 0; |
| | | } else { |
| | | // 该商品订单为空、订单数量未超过商品的单个用户兑换上限数量时,可以进行兑换 |
| | | totalNumber = orderList.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | } |
| | | Integer userCount = good.getUserCount(); |
| | | if (good.getUserCount() > totalNumber) { |
| | | int i = userCount - totalNumber; |
| | | if (number > i) { |
| | | return R.exchangeError("兑换失败,当前兑换数量已超过最大兑换数量,剩余兑换数量为: " + |
| | | i + "!"); |
| | | } |
| | | } |
| | | } |
| | | boolean result = exchangeGood(goodExchange, recipient, number, goodId, needIntegral); |
| | | if (!result) { |
| | | return R.exchangeError("商品兑换失败!"); |
| | |
| | | return R.exchangeError("兑换失败,当前剩余积分不足!"); |
| | | } |
| | | if (null != good.getTotal()) { |
| | | // 检查库存总数是否足够 |
| | | List<TOrder> order = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId) |
| | | .eq(TOrder::getDisabled, 0).list(); |
| | | int item; |
| | | if (!order.isEmpty()) { |
| | | item = order.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | } else { |
| | | item = 0; |
| | | } |
| | | boolean canBuy = good.getTotal() - item >= number; |
| | | if (!canBuy) { |
| | | throw new GlobalException("商品库存不足,兑换失败!"); |
| | | } |
| | | // 检查用户兑换数量是否超过单用户最大兑换数量 |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) |
| | | .eq(TOrder::getGoodsId, goodId).list(); |
| | | // 该商品订单为空、订单数量未超过商品的单个用户兑换上限数量时,可以进行兑换 |
| | | int totalNumber = orderList.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | int totalNumber; |
| | | if (orderList.isEmpty()) { |
| | | totalNumber = 0; |
| | | } else { |
| | | // 该商品订单为空、订单数量未超过商品的单个用户兑换上限数量时,可以进行兑换 |
| | | totalNumber = orderList.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | } |
| | | boolean canExchange = orderList.isEmpty() || null == good.getUserCount() || |
| | | (totalNumber + number) <= good.getUserCount(); |
| | | if (!canExchange) { |
| | |
| | | return R.exchangeError("商品兑换失败!"); |
| | | } |
| | | } else { |
| | | if (null != good.getUserCount()) { |
| | | // 检查用户兑换数量是否超过单用户最大兑换数量 |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) |
| | | .eq(TOrder::getGoodsId, goodId).list(); |
| | | int totalNumber; |
| | | if (orderList.isEmpty()) { |
| | | totalNumber = 0; |
| | | } else { |
| | | // 该商品订单为空、订单数量未超过商品的单个用户兑换上限数量时,可以进行兑换 |
| | | totalNumber = orderList.stream().map(TOrder::getCount).collect(Collectors.toList()) |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | } |
| | | Integer userCount = good.getUserCount(); |
| | | if (good.getUserCount() > totalNumber) { |
| | | int i = userCount - totalNumber; |
| | | if (number > i) { |
| | | return R.exchangeError("兑换失败,当前兑换数量已超过最大兑换数量,剩余兑换数量为: " + |
| | | i + "!"); |
| | | } |
| | | } |
| | | } |
| | | boolean result = exchangeGoodParent(goodExchange, recipient, number, goodId, needIntegral); |
| | | if (!result) { |
| | | return R.exchangeError("商品兑换失败!"); |