From 118623071a97b66f21c29e2bc02b8f15855ede5d Mon Sep 17 00:00:00 2001 From: Cui Zhi Feng <cuizf@fengyuntec.com> Date: 星期三, 25 九月 2024 19:54:11 +0800 Subject: [PATCH] 均价计算 优化 --- src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateActivyController.java | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateActivyController.java b/src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateActivyController.java index 09721fe..08026a8 100644 --- a/src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateActivyController.java +++ b/src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateActivyController.java @@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; +import java.time.LocalDateTime; /** @@ -133,6 +134,27 @@ throw new ValidationException("优惠券不存在"); } + // 判断当前时间是否在优惠券的领取时间范围内 + LocalDateTime now = LocalDateTime.now(); +// if (couponTemplateDO.getGetStartDate() != null && couponTemplateDO.getGetEndDate() != null) { +// if (now.isBefore(couponTemplateDO.getGetStartDate()) || now.isAfter(couponTemplateDO.getGetEndDate())) { +// throw new ValidationException("当前时间不在优惠券领取时间范围内,不能发布优惠券。"); +// } +// } else { +// throw new ValidationException("优惠券的领取时间未设置。"); +// } + + // 检查结束时间是否存在 + if (couponTemplateDO.getGetEndDate() != null) { + // 如果当前时间小于结束时间,允许发布 + if (now.isAfter(couponTemplateDO.getGetEndDate())) { + throw new ValidationException("当前时间已超过优惠券领取结束时间,不能发布优惠券。"); + } + } else { + throw new ValidationException("优惠券的领取结束时间未设置。"); + } + + couponTemplateService.activeCouponTemplate(id); return returnData(R.SUCCESS.getCode(), null); @@ -155,11 +177,22 @@ private void valid(CreateCouponTemplateActivyDTO dto){ - if (StringUtils.isNotBlank(dto.getCouponDiscountType()) - && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) - && dto.getMinOrderAmount().compareTo(dto.getCouponDiscountValue()) < 0) { - throw new ValidationException("订单金额不能小于折扣金额"); +// if (StringUtils.isNotBlank(dto.getCouponDiscountType()) +// && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) +// && dto.getMinOrderAmount().compareTo(dto.getCouponDiscountValue()) < 0) { +// throw new ValidationException("优惠券使用条件不能小于面值金额"); +// } + if (StringUtils.isNotBlank(dto.getCouponDiscountType()) && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType())) { + + if(dto.getMinOrderAmount().compareTo(BigDecimal.ZERO)<=0){ + throw new ValidationException("优惠券使用条件不能小于0"); + } + if(dto.getMinOrderAmount().compareTo(dto.getCouponDiscountValue()) < 0){ + throw new ValidationException("优惠券使用条件不能小于面值金额"); + } + } + if (StringUtils.isNotBlank(dto.getCouponDiscountType()) && dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) && dto.getCouponDiscountValue().compareTo(BigDecimal.ZERO) <= 0) { @@ -181,6 +214,19 @@ if(dto.getUsageEndDate()==null){ throw new ValidationException("固定时间结束日期不能为空"); } + + if(dto.getUsageStartDate().isAfter(dto.getUsageEndDate())){ + throw new ValidationException("固定时间开始时间不能大于结束日期"); + } + + + // 固定时间的使用开始时间必须大于领取的结束时间 + + if(null!=dto.getGetEndDate() && null!=dto.getUsageStartDate() && dto.getGetEndDate().isAfter(dto.getUsageStartDate())){ + throw new ValidationException("使用开始时间必须大于领取结束时间!"); + } + + } // 领取后 有效时间 @@ -207,6 +253,8 @@ } } + // + } } -- Gitblit v1.9.3