hjl
2024-07-02 133ddd233e5c552fe02150b62ab1691838cbce57
fix: 学习端、家长端商城兑换bug
2个文件已修改
27 ■■■■ 已修改文件
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/TGoodsServiceImpl.java 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/service/impl/TGoodsServiceImpl.java
@@ -66,7 +66,8 @@
        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()) {
@@ -88,6 +89,7 @@
    @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();
@@ -122,6 +124,7 @@
            // 检查用户兑换数量是否超过单用户最大兑换数量
            List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getUserId, user.getId())
                    .eq(TOrder::getGoodsId, goodId).list();
            // 用户已兑换数量
            int totalNumber;
            if (orderList.isEmpty()) {
                totalNumber = 0;
@@ -130,8 +133,14 @@
                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) + "!");
@@ -259,8 +268,14 @@
                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) + "!");
ruoyi-service/ruoyi-study/src/main/java/com/ruoyi/study/controller/TStudyController.java
@@ -967,7 +967,7 @@
     */
    @GetMapping("/exitGameOrStory")
    @ApiOperation(value = "退出游戏/故事学习", tags = {"学习端-题目"})
    public R<Boolean> exitGameOrStory(@RequestParam Integer studyTime) {
    public R<Boolean> exitGameOrStory(@RequestParam("studyTime") Integer studyTime) {
        LoginUserParent loginStudy = tokenService.getLoginUserStudy();
        if (null == loginStudy) {
            return R.tokenError("登录失效!");