| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private Boolean exchangeGood(GoodExchangeDTO goodExchange, Recipient recipient, Integer number, |
| | | Integer goodId, int needIntegral) { |
| | | // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务) |
| | | TOrder order = orderInfo(goodExchange, recipient, number, goodId, needIntegral); |
| | | order.setProvince(recipient.getProvince()); |
| | | order.setCity(recipient.getCity()); |
| | | boolean result = orderService.save(order); |
| | | // 远程调用,生成积分明细 |
| | | result = result && studyClient.addIntegralDetail(Constants.BURDEN + needIntegral, Constants.SHOPPING_CONSUME).getData(); |
| | | // 扣除用户积分 |
| | | result = result && studyClient.exchangeIntegral(needIntegral, Constants.BURDEN).getData(); |
| | | return result; |
| | | } |
| | | |
| | | private Boolean exchangeGoodParent(GoodExchangeDTO goodExchange, Recipient recipient, Integer number, |
| | | Integer goodId, int needIntegral) { |
| | | // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务) |
| | | TOrder order = orderInfoParent(goodExchange, recipient, number, goodId, needIntegral); |
| | | order.setProvince(recipient.getProvince()); |
| | | order.setCity(recipient.getCity()); |
| | | boolean result = orderService.save(order); |
| | | // 远程调用,生成积分明细 |
| | | result = result && studyClient.addIntegralDetailParent(Constants.BURDEN + needIntegral, Constants.SHOPPING_CONSUME).getData(); |
| | | // 扣除用户积分 |
| | | result = result && studyClient.exchangeIntegralParent(needIntegral, Constants.BURDEN).getData(); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R goodExchange1(GoodExchangeDTO goodExchange, Recipient recipient) { |
| | | // 用户本次兑换数量 |
| | | Integer number = goodExchange.getNumber(); |
| | | Integer goodId = goodExchange.getGoodId(); |
| | | TGoods good = this.getById(goodId); |
| | | TGoods good = lambdaQuery().eq(TGoods::getId, goodId).one(); |
| | | if (null == good) { |
| | | return R.exchangeError("商品不存在,请稍后重试!"); |
| | | } |
| | |
| | | // 检查用户兑换数量是否超过单用户最大兑换数量 |
| | | List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId()) |
| | | .eq(TOrder::getGoodsId, goodId).list(); |
| | | // 用户已兑换数量 |
| | | int totalNumber; |
| | | if (orderList.isEmpty()) { |
| | | totalNumber = 0; |
| | |
| | | } |
| | | // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务) |
| | | boolean result = exchangeGoodParent(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("商品兑换失败!"); |
| | |
| | | .stream().mapToInt(Integer::intValue).sum(); |
| | | } |
| | | Integer userCount = good.getUserCount(); |
| | | if (good.getUserCount() > totalNumber) { |
| | | if (userCount > totalNumber) { |
| | | int i = userCount - totalNumber; |
| | | if (number > i) { |
| | | return R.exchangeError("兑换失败,当前兑换数量已超过最大兑换数量,剩余兑换数量为: " + |
| | |
| | | } |
| | | return R.ok(); |
| | | } |
| | | private Boolean exchangeGood(GoodExchangeDTO goodExchange, Recipient recipient, Integer number, |
| | | Integer goodId, int needIntegral) { |
| | | // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务) |
| | | TOrder order = orderInfo(goodExchange, recipient, number, goodId, needIntegral); |
| | | order.setProvince(recipient.getProvince()); |
| | | order.setCity(recipient.getCity()); |
| | | boolean result = orderService.save(order); |
| | | // 远程调用,生成积分明细 |
| | | result = result && studyClient.addIntegralDetail(Constants.BURDEN + needIntegral, Constants.SHOPPING_CONSUME).getData(); |
| | | // 扣除用户积分 |
| | | result = result && studyClient.exchangeIntegral(needIntegral, Constants.BURDEN).getData(); |
| | | return result; |
| | | } |
| | | |
| | | private Boolean exchangeGoodParent(GoodExchangeDTO goodExchange, Recipient recipient, Integer number, |
| | | Integer goodId, int needIntegral) { |
| | | // 兑换成功,生成订单信息、生成积分明细(积分明细需要远程调用rouyi-study服务) |
| | | TOrder order = orderInfoParent(goodExchange, recipient, number, goodId, needIntegral); |
| | | order.setProvince(recipient.getProvince()); |
| | | order.setCity(recipient.getCity()); |
| | | boolean result = orderService.save(order); |
| | | // 远程调用,生成积分明细 |
| | | result = result && studyClient.addIntegralDetailParent(Constants.BURDEN + needIntegral, Constants.SHOPPING_CONSUME).getData(); |
| | | // 扣除用户积分 |
| | | result = result && studyClient.exchangeIntegralParent(needIntegral, Constants.BURDEN).getData(); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void updateOne(TGoods dto) { |