From b6a7f6e41467f73f26fc7f209652e19ff26c3752 Mon Sep 17 00:00:00 2001 From: Cui Zhi Feng <cuizf@fengyuntec.com> Date: 星期二, 03 九月 2024 20:18:32 +0800 Subject: [PATCH] Merge branch 'master' into master-v2 --- src/main/java/com/mzl/flower/service/menber/impl/MemberServiceImpl.java | 89 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 72 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/mzl/flower/service/menber/impl/MemberServiceImpl.java b/src/main/java/com/mzl/flower/service/menber/impl/MemberServiceImpl.java index 710513c..1cb015c 100644 --- a/src/main/java/com/mzl/flower/service/menber/impl/MemberServiceImpl.java +++ b/src/main/java/com/mzl/flower/service/menber/impl/MemberServiceImpl.java @@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.mzl.flower.config.exception.ValidationException; import com.mzl.flower.config.security.SecurityUtils; +import com.mzl.flower.constant.Constants; import com.mzl.flower.dto.request.menber.MemberDTO; import com.mzl.flower.dto.request.menber.MemberQueryDTO; import com.mzl.flower.dto.response.member.MemberVO; import com.mzl.flower.entity.menber.Member; +import com.mzl.flower.mapper.customer.CustomerMapper; import com.mzl.flower.mapper.member.MemberMapper; import com.mzl.flower.service.menber.MemberService; import lombok.RequiredArgsConstructor; @@ -34,27 +36,41 @@ private final MemberMapper memberMapper; + private final CustomerMapper customerMapper; + @Override public void saveMember(Member member) { if (StringUtils.isEmpty(member.getName())) { throw new ValidationException("会员等级名称不能为空"); } + if (StringUtils.isEmpty(member.getDiscountType())) { + throw new ValidationException("会员折扣类型不能为空"); + } + if (Constants.DISCOUNT_TYPE.amount.name().equals(member.getDiscountType()) && StringUtils.isEmpty(member.getDiscountAmount())) { + throw new ValidationException("会员折扣固定金额不能为空"); + } + if (Constants.DISCOUNT_TYPE.ratio.name().equals(member.getDiscountType()) && StringUtils.isEmpty(member.getDiscountRatio())) { + throw new ValidationException("会员折扣百分比不能为空"); + } if (member.getStartPoint() > member.getEndPoint()) { throw new ValidationException("成长点开始不能大于结束"); } - - int discountRatio1 = member.getDiscountRatio().compareTo(BigDecimal.ZERO); - if (discountRatio1 == -1) { - throw new ValidationException("会员折扣百分比不能小于0"); + if (!StringUtils.isEmpty(member.getDiscountRatio())) { + int discountRatio1 = member.getDiscountRatio().compareTo(BigDecimal.ZERO); + if (discountRatio1 == -1) { + throw new ValidationException("会员折扣百分比不能小于0"); + } + int discountRatio2 = member.getDiscountRatio().compareTo(new BigDecimal(100)); + if (discountRatio2 == 1) { + throw new ValidationException("会员折扣百分比不能大于100"); + } } - int discountRatio2 = member.getDiscountRatio().compareTo(new BigDecimal(100)); - if (discountRatio2 == 1) { - throw new ValidationException("会员折扣百分比不能大于100"); - } - int discountAmount = member.getDiscountAmount().compareTo(BigDecimal.ZERO); - if (discountAmount == -1) { - throw new ValidationException("会员折扣固定金额不能小于0"); + if (!StringUtils.isEmpty(member.getDiscountAmount())) { + int discountAmount = member.getDiscountAmount().compareTo(BigDecimal.ZERO); + if (discountAmount == -1) { + throw new ValidationException("会员折扣固定金额不能小于0"); + } } //保存时判断是否有重复的名称 @@ -63,6 +79,9 @@ throw new ValidationException("会员等级名称重复"); } memberMapper.insert(member); + //更新会员等级 + customerMapper.updateMemberLevelByPoint(member.getId(), member.getStartPoint(), member.getEndPoint()); + } @Override @@ -71,29 +90,65 @@ if (memberInfo == null) { throw new ValidationException("会员等级信息不存在"); } -// if (!memberInfo.getCreateBy().equals(SecurityUtils.getUserId())) { -// throw new ValidationException("无权限修改"); -// } + if (StringUtils.isEmpty(memberDTO.getDiscountType())) { + throw new ValidationException("会员折扣类型不能为空"); + } + if (Constants.DISCOUNT_TYPE.amount.name().equals(memberDTO.getDiscountType()) && StringUtils.isEmpty(memberDTO.getDiscountAmount())) { + throw new ValidationException("会员折扣固定金额不能为空"); + } + if (Constants.DISCOUNT_TYPE.ratio.name().equals(memberDTO.getDiscountType()) && StringUtils.isEmpty(memberDTO.getDiscountRatio())) { + throw new ValidationException("会员折扣百分比不能为空"); + } + if (memberDTO.getStartPoint() > memberDTO.getEndPoint()) { + throw new ValidationException("成长点开始不能大于结束"); + } + if (!StringUtils.isEmpty(memberDTO.getDiscountRatio())) { + int discountRatio1 = memberDTO.getDiscountRatio().compareTo(BigDecimal.ZERO); + if (discountRatio1 == -1) { + throw new ValidationException("会员折扣百分比不能小于0"); + } + int discountRatio2 = memberDTO.getDiscountRatio().compareTo(new BigDecimal(100)); + if (discountRatio2 == 1) { + throw new ValidationException("会员折扣百分比不能大于100"); + } + } + if (!StringUtils.isEmpty(memberDTO.getDiscountAmount())) { + int discountAmount = memberDTO.getDiscountAmount().compareTo(BigDecimal.ZERO); + if (discountAmount == -1) { + throw new ValidationException("会员折扣固定金额不能小于0"); + } + } Member memberTemp = memberMapper.getMemberByName(memberDTO.getName()); //判断如果按照会员等级查询到得名称和当前得Id不一致,不能修改。 if (!ObjectUtils.isEmpty(memberTemp)) { - if (memberTemp.getName().equals(memberDTO.getName())) { + if (memberTemp.getId() != memberDTO.getId()) { throw new ValidationException("已存在会员等级名称,无法修改"); } } + //更新会员等级 + if (memberInfo.getStartPoint() != memberDTO.getStartPoint() || memberInfo.getEndPoint() != memberDTO.getEndPoint()) { + customerMapper.updateMemberLevelByPoint(memberInfo.getId(), memberInfo.getStartPoint(), memberInfo.getEndPoint()); + } + BeanUtils.copyProperties(memberDTO,memberInfo); memberInfo.update(SecurityUtils.getUserId()); memberMapper.updateById(memberInfo); + } @Override public void deleteMember(String id) { + if(id.equals(Constants.DEFAULT_MEMBER_ID)){ + throw new ValidationException("默认普通会员只能编辑,不能删除"); + } Member member = memberMapper.selectById(id); if (member == null) { throw new ValidationException("会员等级信息不存在"); } - - // TODO: 2024/8/26 如果当前会员绑定了优惠券,不能删除,等优惠券逻辑完成。 + Integer levelId = customerMapper.getByLevelId(id); + if (levelId > 0) { + throw new ValidationException("当前会员等级用户已使用,无法删除"); + } memberMapper.deleteById(id); } -- Gitblit v1.9.3