From 03f1f3372a10a08f96f3308bfa099e86a55046d0 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期二, 30 一月 2024 09:32:38 +0800 Subject: [PATCH] 修改数据权限bug --- ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java | 100 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 96 insertions(+), 4 deletions(-) diff --git a/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java b/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java index 7f5be8b..8062e06 100644 --- a/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java +++ b/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.member.service.impl.coupon; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.exception.ServiceException; @@ -266,12 +267,103 @@ CouponTotal couponTotal; if(StringUtils.isNotBlank(mgtCouponEditDto.getCouponId())){ coupon = this.getById(mgtCouponEditDto.getCouponId()); - couponTotal = couponTotalService.getById(mgtCouponEditDto.getCouponId()); - if(couponTotal.getSendCount()!=null&&couponTotal.getSendCount()>0){ - throw new ServiceException(AppErrorConstant.COUPON_SENT_EDIT); +// couponTotal = couponTotalService.getById(mgtCouponEditDto.getCouponId()); +// if(couponTotal.getSendCount()!=null&&couponTotal.getSendCount()>0){ +// throw new ServiceException(AppErrorConstant.COUPON_SENT_EDIT); +// } + /** + * 一:不可修改 + * 1、优惠券类型 + * 2、发放方式 + * 3、优惠券金额 + * 4、使用期限类型 + * 5、有效时间段:开始时间不能修改,结束时间可以修改 + * 二:部分可修改 + * 1、发放方式为指定发放时 + * 定时发放:已到发放时间不可修改 + * 立即发放:不可修改 + * 2、适用范围 + * 全部商品:不可修改 + * 部分商品:只能增加商品 + * 3、发放数量:只能增加 + * 不限制:不可修改 + * 4、用户可领数量:只能增加 + * 三:可修改 + * 1、优惠券名称 + * 2、宣传海报 + * 四:发放对象 + * 1、未到发放时间都可以修改 + * 2、已到发放时间,只有自定义时可修改,且只能增加用户 + */ + if(!coupon.getCouponType().equals(mgtCouponEditDto.getCouponType())){ + throw new ServiceException("不能修改优惠券类型"); } + if(!coupon.getSendType().equals(mgtCouponEditDto.getSendType())){ + throw new ServiceException("不能修改优惠券发放方式"); + } + if(null != mgtCouponEditDto.getMoneyThreshold() && coupon.getMoneyThreshold().compareTo(mgtCouponEditDto.getMoneyThreshold()) != 0){ + throw new ServiceException("不能修改优惠券金额"); + } + if(null != mgtCouponEditDto.getDiscountMoney() && coupon.getDiscountMoney().compareTo(mgtCouponEditDto.getDiscountMoney()) != 0){ + throw new ServiceException("不能修改优惠券金额"); + } + if(null != mgtCouponEditDto.getDiscountPercent() && coupon.getDiscountPercent().compareTo(mgtCouponEditDto.getDiscountPercent()) != 0){ + throw new ServiceException("不能修改优惠券折扣"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && null != mgtCouponEditDto.getValidTimeType() && !coupon.getValidTimeType().equals(mgtCouponEditDto.getValidTimeType())){ + throw new ServiceException("不能修改优惠券适用期限类型"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && null != mgtCouponEditDto.getValidTimeType() && coupon.getValidTimeType() == 1 && !coupon.getValidStartTime().equals(mgtCouponEditDto.getValidStartTime())){ + throw new ServiceException("不能修改优惠券有效期开始时间"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 1 && mgtCouponEditDto.getSendTimeType() != 1){ + throw new ServiceException("不能修改优惠券发放方式"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() != 2 && System.currentTimeMillis() <= coupon.getSendTime().getTime()){ + throw new ServiceException("不能修改优惠券发放方式"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime()){ + throw new ServiceException("不能修改优惠券发放时间"); + } + if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && coupon.getUseScope() == 1 && !coupon.getUseScope().equals(mgtCouponEditDto.getUseScope())){ + throw new ServiceException("不能修改优惠券适用范围"); + } + + if(coupon.getUseScope() == 2 && coupon.getUseScope().equals(mgtCouponEditDto.getUseScope())){ + List<String> relGoodsIdList = mgtCouponEditDto.getRelGoodsIdList(); + List<CouponRelGoods> list = couponRelGoodsService.list(new QueryWrapper<CouponRelGoods>().eq("coupon_id", coupon.getCouponId()).eq("del_flag", 0)); + for (CouponRelGoods couponRelGoods : list) { + if(!relGoodsIdList.contains(couponRelGoods.getGoodsId())){ + throw new ServiceException("不能删除优惠券适用商品"); + } + } + } + if(coupon.getSendLimitFlag() == 0 && mgtCouponEditDto.getSendLimitFlag() != 0){ + throw new ServiceException("不能修改优惠券发放数量限制"); + } + if(coupon.getSendLimitFlag() == 1 && mgtCouponEditDto.getSendLimitFlag() == 1 && coupon.getSendLimitNumber().compareTo(mgtCouponEditDto.getSendLimitNumber()) > 0){ + throw new ServiceException("不能修改优惠券发放数量限制"); + } + if(coupon.getLimitNumber().compareTo(mgtCouponEditDto.getLimitNumber()) > 0){ + throw new ServiceException("只能增加优惠券领取数量"); + } + List<CouponRelUser> list = couponRelUserService.list(new QueryWrapper<CouponRelUser>().eq("coupon_id", coupon.getCouponId()).eq("del_flag", 0)); + List<Long> relUserIdList = mgtCouponEditDto.getRelUserIdList(); + for (CouponRelUser couponRelUser : list) { + if(!relUserIdList.contains(couponRelUser.getUserId())){ + throw new ServiceException("只能增加优惠发放对象"); + } + } + if(relUserIdList.size() != list.size() && coupon.getSendType() == 2 && coupon.getSendTimeType() == 1){ + throw new ServiceException("只能修改优惠发放对象"); + } + if(relUserIdList.size() != list.size() && coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && System.currentTimeMillis() <= coupon.getSendTime().getTime()){ + throw new ServiceException("只能修改优惠发放对象"); + } + couponRelUserService.deleteCouponRelByCouponId(coupon.getCouponId()); couponRelGoodsService.deleteCouponRelByCouponId(coupon.getCouponId()); + }else{ coupon = new Coupon(); String couponId = IdUtils.simpleUUID(); @@ -358,7 +450,7 @@ coupon.setRelUserIds(userIdSj.toString()); } //处理优惠券发放 - if(coupon.getSendType()==2&&coupon.getSendTimeType()==1){ + if(coupon.getSendFlag() == 0 && coupon.getSendType()==2&&coupon.getSendTimeType()==1){ sendCoupon(coupon,relUserIdList); coupon.setSendFlag(1); this.saveOrUpdate(coupon); -- Gitblit v1.7.1