|  |  |  | 
|---|
|  |  |  | import com.mzl.flower.base.R; | 
|---|
|  |  |  | import com.mzl.flower.base.ReturnDataDTO; | 
|---|
|  |  |  | import com.mzl.flower.config.exception.ValidationException; | 
|---|
|  |  |  | import com.mzl.flower.dto.request.coupon.CreateCouponTemplateActivyDTO; | 
|---|
|  |  |  | import com.mzl.flower.dto.request.coupon.CreateCouponTemplateBO; | 
|---|
|  |  |  | import com.mzl.flower.dto.request.coupon.CreateCouponTemplateUserDTO; | 
|---|
|  |  |  | import com.mzl.flower.dto.request.coupon.QueryCouponDTO; | 
|---|
|  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "新增", notes = "新增") | 
|---|
|  |  |  | public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateCouponTemplateUserDTO dto) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) && dto.getMinOrderAmount().compareTo(dto.getCouponDiscountValue()) < 0) { | 
|---|
|  |  |  | throw new ValidationException("订单金额不能小于折扣金额"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (dto.getCouponDiscountType().equals(CouponTypeEnum.ZERO.getType()) && dto.getMinOrderAmount().compareTo(BigDecimal.ZERO) != 0) { | 
|---|
|  |  |  | throw new ValidationException("无门槛的订单金额必须为0"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | valid(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CreateCouponTemplateBO couponTemplateBO = new CreateCouponTemplateBO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(dto, couponTemplateBO); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | dto.setId(id); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (dto.getCouponDiscountType().equals(CouponTypeEnum.DISCOUNT.getType()) && dto.getMinOrderAmount().compareTo(dto.getCouponDiscountValue()) < 0) { | 
|---|
|  |  |  | throw new ValidationException("订单金额不能小于折扣金额"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (dto.getCouponDiscountType().equals(CouponTypeEnum.ZERO.getType()) && dto.getMinOrderAmount().compareTo(BigDecimal.ZERO) != 0) { | 
|---|
|  |  |  | throw new ValidationException("无门槛的订单金额必须为0"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | valid(dto); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | CouponTemplateDO couponTemplateDO = couponTemplateService.getById(dto.getId()); | 
|---|
|  |  |  | if (null == couponTemplateDO) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void valid(CreateCouponTemplateUserDTO dto){ | 
|---|
|  |  |  | 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 (dto.getCouponDiscountType().equals(CouponTypeEnum.ZERO.getType()) && dto.getMinOrderAmount().compareTo(BigDecimal.ZERO) != 0) { | 
|---|
|  |  |  | throw new ValidationException("无门槛的订单金额必须为0"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|