| | |
| | | if (null != goods.getTotal()) { |
| | | // 库存预热,redisson分布式锁 |
| | | String key = String.format(RedisConstants.GOOD_STOCK, goods.getId()); |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId) |
| | | List<TOrder> orderList = orderService.lambdaQuery() |
| | | .eq(TOrder::getGoodsId, goodId) |
| | | .eq(TOrder::getDisabled, 0).list(); |
| | | int sum = 0; |
| | | if (!orderList.isEmpty()) { |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R<String> goodExchange(GoodExchangeDTO goodExchange, Recipient recipient) { |
| | | // 用户本次兑换数量 |
| | | Integer number = goodExchange.getNumber(); |
| | | Integer goodId = goodExchange.getGoodId(); |
| | | TGoods good = lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | |
| | | // 检查用户兑换数量是否超过单用户最大兑换数量 |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) |
| | | .eq(TOrder::getGoodsId, goodId).list(); |
| | | // 用户已兑换数量 |
| | | int totalNumber; |
| | | if (orderList.isEmpty()) { |
| | | totalNumber = 0; |
| | |
| | | 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(); |
| | | boolean canExchange = true; |
| | | if (null != good.getUserCount()) { |
| | | if (number > good.getUserCount()) { |
| | | canExchange = false; |
| | | } else { |
| | | canExchange = (totalNumber + number) <= good.getUserCount(); |
| | | } |
| | | } |
| | | if (!canExchange) { |
| | | return R.exchangeError("兑换失败,当前兑换数量已超过最大兑换数量,剩余兑换数量为: " + |
| | | (good.getUserCount() - totalNumber) + "!"); |
| | |
| | | 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(); |
| | | boolean canExchange = true; |
| | | if (null != good.getUserCount()) { |
| | | if (number > good.getUserCount()) { |
| | | canExchange = false; |
| | | } else { |
| | | canExchange = (totalNumber + number) <= good.getUserCount(); |
| | | } |
| | | } |
| | | if (!canExchange) { |
| | | return R.exchangeError("兑换失败,当前兑换数量已超过最大兑换数量,剩余兑换数量为: " + |
| | | (good.getUserCount() - totalNumber) + "!"); |