From b3bc4f358434ec82f90eaa8b87f68b68a2652fa7 Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期二, 22 十月 2024 15:08:17 +0800
Subject: [PATCH] fix: id
---
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateActivyController.java | 84 +++++++++++++++++++++++++++++++++++------
1 files changed, 71 insertions(+), 13 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 b0d20bc..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
@@ -11,10 +11,7 @@
import com.mzl.flower.dto.response.coupon.CouponTemplatePointVO;
import com.mzl.flower.dto.response.coupon.CouponTemplateVO;
import com.mzl.flower.entity.coupon.CouponTemplateDO;
-import com.mzl.flower.enums.CouponCategoryEnum;
-import com.mzl.flower.enums.CouponGetUserTypeEnum;
-import com.mzl.flower.enums.CouponTypeEnum;
-import com.mzl.flower.enums.CouponUsageTypeEnum;
+import com.mzl.flower.enums.*;
import com.mzl.flower.service.coupon.CouponTemplateService2;
import com.mzl.flower.utils.ConverterUtil;
import io.swagger.annotations.Api;
@@ -27,6 +24,7 @@
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
+import java.time.LocalDateTime;
/**
@@ -52,7 +50,7 @@
CreateCouponTemplateBO couponTemplateBO = new CreateCouponTemplateBO();
BeanUtils.copyProperties(dto, couponTemplateBO);
- // 设置成积分优惠券
+ // 设置成活动优惠券
couponTemplateBO.setCategory(CouponCategoryEnum.ACTIVITY.getStatus());
couponTemplateBO.setGetUserType(CouponGetUserTypeEnum.ALL.getType());
@@ -65,8 +63,10 @@
@PutMapping("/{id}")
@ApiOperation(value = "修改", notes = "修改")
- public ResponseEntity<ReturnDataDTO> update(@Validated @RequestBody CreateCouponTemplateActivyDTO dto) {
+ public ResponseEntity<ReturnDataDTO> update(@PathVariable String id,@Validated @RequestBody CreateCouponTemplateActivyDTO dto) {
+ // 手动设置id值
+ dto.setId(id);
// 信息验证
valid(dto);
@@ -76,9 +76,10 @@
}
CreateCouponTemplateBO couponTemplateBO = new CreateCouponTemplateBO();
+ BeanUtils.copyProperties(couponTemplateDO,couponTemplateBO);
BeanUtils.copyProperties(dto, couponTemplateBO);
- // 设置成积分优惠券
+ // 设置成活动优惠券
couponTemplateBO.setCategory(CouponCategoryEnum.ACTIVITY.getStatus());
couponTemplateBO.setGetUserType(CouponGetUserTypeEnum.ALL.getType());
@@ -109,7 +110,7 @@
@GetMapping("/page")
@ApiOperation(value = "查询-分页", notes = "查询-分页")
public ResponseEntity<ReturnDataDTO<Page<CouponTemplatePointVO>>> page(Page page, QueryCouponDTO dto) {
- // 设置只查询积分优惠券的
+ // 设置只查询活动优惠券的
dto.setCategory(CouponCategoryEnum.ACTIVITY.getStatus());
Page<CouponTemplateVO> resultPage = couponTemplateService.getPage(page, dto);
return returnData(R.SUCCESS.getCode(), ConverterUtil.transPage(resultPage, CouponTemplateActivyVO.class));
@@ -118,7 +119,7 @@
@GetMapping("/list")
@ApiOperation(value = "查询-全部", notes = "查询-全部")
public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> list(QueryCouponDTO dto) {
- // 设置只查询积分优惠券的
+ // 设置只查询活动优惠券的
dto.setCategory(CouponCategoryEnum.ACTIVITY.getStatus());
return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(couponTemplateService.getList(dto), CouponTemplateActivyVO.class));
}
@@ -132,6 +133,27 @@
if (null == couponTemplateDO) {
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);
@@ -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("使用开始时间必须大于领取结束时间!");
+ }
+
+
}
// 领取后 有效时间
@@ -197,6 +243,18 @@
throw new ValidationException("领取后有效时间整数需要大于0");
}
}
+
+ // 用户获取的类型是首页领取的话
+ if(StringUtils.isNotBlank(dto.getGetType()) && dto.getGetType().equals(dto.getGetType().equals(CouponGetTypeEnum.HOME.getType()))
+ ){
+ // 优惠券图片校验
+ if(StringUtils.isBlank(dto.getImageUrl())){
+ throw new ValidationException("优惠券图片不能为空");
+ }
+ }
+
+ //
+
}
}
--
Gitblit v1.9.3