puzhibing
2025-01-13 acccff9860b271d55c55dc87486f7c20b9896e6c
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserCouponController.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.api.model.AppUser;
@@ -98,8 +99,6 @@
                }
            }
            record.setCouponInfoVo(vo);
            if (record.getUseTime()==null){
                record.setStatus(1);
@@ -109,7 +108,6 @@
            }else {
                record.setStatus(2);
            }
            AppUser appUser = appUserService.getById(record.getAppUserId());
            record.setUserName(appUser.getName());
@@ -149,8 +147,6 @@
                }
            }
            record.setCouponInfoVo(vo);
            if (record.getUseTime()==null){
                record.setStatus(1);
@@ -160,7 +156,6 @@
            }else {
                record.setStatus(2);
            }
            AppUser appUser = appUserService.getById(record.getAppUserId());
            record.setUserName(appUser.getName());
@@ -184,6 +179,16 @@
        if (data==null){
            return  R.fail("当前优惠券不存在,请刷新后重试");
        }
        long count = userCouponService.count(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getCouponId, couponId).eq(UserCoupon::getDelFlag, 0));
        if(data.getSendNum() <= count){
            return R.fail("当前优惠券已全部领取完毕");
        }
        count = userCouponService.count(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getCouponId, couponId)
                .eq(UserCoupon::getAppUserId, userid).eq(UserCoupon::getDelFlag, 0));
        if(data.getMaxNum() <= count){
            return R.fail("当前优惠券已达到最大领取限制");
        }
        if (data.getSendType()!=1&& byId.getLavePoint().compareTo(data.getNeedPoint().intValue()) < 0){
           return  R.fail("当前积分不足,兑换失败");
        }
@@ -201,7 +206,7 @@
            appUserService.updateById(byId);
            
            UserPoint userPoint = new UserPoint();
            userPoint.setType(4);
            userPoint.setType(11);
            userPoint.setHistoricalPoint(lavePoint);
            userPoint.setVariablePoint(point);
            userPoint.setBalance(byId.getLavePoint());
@@ -321,5 +326,28 @@
        userCouponService.updateById(userCoupon);
        return R.ok();
    }
    /**
     * 获取用户优惠券详情
     * @param id
     * @return
     */
    @PostMapping("/getUserCoupon")
    public R<UserCoupon> getUserCoupon(@RequestParam("id") Long id){
        UserCoupon userCoupon = userCouponService.getById(id);
        return R.ok(userCoupon);
    }
    /**
     * 编辑用户优惠券
     * @return
     */
    @PostMapping("/editUserCoupon")
    public R editUserCoupon(@RequestBody UserCoupon userCoupon){
        userCouponService.updateById(userCoupon);
        return R.ok();
    }
}