1.优惠券-使用条件-根据满减还是无门槛控制
2.商品限购-根据payment_time来控制
 
	
	
	
	
	
	
	
	
	
	
	
	
	
 |  |  | 
 |  |  |     @ApiModelProperty(value = "使用条件,满多少钱") | 
 |  |  |     @NotNull(message = "使用条件不能为空") | 
 |  |  |     @Max(value = 99999999,message = "使用条件不能超过99999999") | 
 |  |  |     @DecimalMin(value = "0.01", inclusive = true,message = "使用条件大于0") | 
 |  |  | //    @DecimalMin(value = "0.01", inclusive = true,message = "使用条件大于0") | 
 |  |  |     private BigDecimal minOrderAmount; | 
 |  |  |  | 
 |  |  |     /** | 
 
 |  |  | 
 |  |  |     @ApiModelProperty(value = "使用条件") | 
 |  |  |     @NotNull(message = "使用条件不能为空") | 
 |  |  |     @Max(value = 99999999,message = "使用条件不能超过99999999") | 
 |  |  |     @DecimalMin(value = "0.01", inclusive = true,message = "使用条件大于0") | 
 |  |  | //    @DecimalMin(value = "0.01", inclusive = true,message = "使用条件大于0") | 
 |  |  |     private BigDecimal minOrderAmount; | 
 |  |  |  | 
 |  |  |     /** | 
 
 |  |  | 
 |  |  |     @ApiModelProperty(value = "使用条件") | 
 |  |  |     @NotNull(message = "使用条件不能为空") | 
 |  |  |     @Max(value = 99999999,message = "使用条件不能超过99999999") | 
 |  |  |     @DecimalMin(value = "0.01", inclusive = true,message = "使用条件大于0") | 
 |  |  | //    @DecimalMin(value = "0.01", inclusive = true,message = "使用条件大于0") | 
 |  |  |     private BigDecimal minOrderAmount; | 
 |  |  |  | 
 |  |  |     /** | 
 
 |  |  | 
 |  |  |     @ApiModelProperty(value = "使用条件") | 
 |  |  |     @NotNull(message = "使用条件不能为空") | 
 |  |  |     @Max(value = 99999999,message = "使用条件不能超过99999999") | 
 |  |  |     @DecimalMin(value = "0.01", inclusive = true,message = "使用条件大于0") | 
 |  |  | //    @DecimalMin(value = "0.01", inclusive = true,message = "使用条件大于0") | 
 |  |  |     private BigDecimal minOrderAmount; | 
 |  |  |  | 
 |  |  |  | 
 
 |  |  | 
 |  |  |             "LEFT JOIN t_customer_info c ON t1.create_by = c.user_id ") | 
 |  |  |     List<Order> getOrderInfoByReceiveTime(); | 
 |  |  |  | 
 |  |  |     Integer getFlowerCompleteNumToday(@Param("userId") String userId,@Param("flowerId") Long flowerId); | 
 |  |  |     int getFlowerCompleteNumWithinTimeRange(@Param("userId") String userId ,@Param("flowerId") Long flowerId, | 
 |  |  |                                             @Param("startTime") LocalDateTime startTime, @Param("endTime") LocalDateTime endTime); | 
 |  |  | } | 
 
 |  |  | 
 |  |  | import java.math.RoundingMode; | 
 |  |  | import java.time.LocalDate; | 
 |  |  | import java.time.LocalDateTime; | 
 |  |  | import java.time.LocalTime; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.HashMap; | 
 |  |  | import java.util.List; | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public Integer getFlowerCompleteNumToday(String userId,Long flowerId){ | 
 |  |  |         Integer completeNum= orderMapper.getFlowerCompleteNumToday(userId,flowerId); | 
 |  |  |  | 
 |  |  |         int completeNum = 0; | 
 |  |  |         // 获取当前时间 | 
 |  |  |         LocalDateTime now = LocalDateTime.now(); | 
 |  |  |         // 构造今天的17:00 | 
 |  |  |         LocalDateTime todayAtFivePM = LocalDateTime.of(LocalDate.now(), LocalTime.of(17, 0)); | 
 |  |  |         // 定义时间区间的开始和结束时间 | 
 |  |  |         LocalDateTime startTime; | 
 |  |  |         LocalDateTime endTime; | 
 |  |  |  | 
 |  |  |         if (now.isAfter(todayAtFivePM)) { | 
 |  |  |             // 当前时间大于今天的17:00,取今天17:00到明天17:00的区间 | 
 |  |  |             startTime = todayAtFivePM; | 
 |  |  |             endTime = todayAtFivePM.plusDays(1);  // 明天的17:00 | 
 |  |  |         } else { | 
 |  |  |             // 当前时间小于今天的17:00,取昨天17:00到今天17:00的区间 | 
 |  |  |             startTime = todayAtFivePM.minusDays(1);  // 昨天的17:00 | 
 |  |  |             endTime = todayAtFivePM;  // 今天的17:00 | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 调用Mapper方法,传递开始时间和结束时间 | 
 |  |  |         completeNum = orderMapper.getFlowerCompleteNumWithinTimeRange(userId, flowerId, startTime, endTime); | 
 |  |  |  | 
 |  |  |         return completeNum; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     } | 
 |  |  | } | 
 
 |  |  | 
 |  |  |  | 
 |  |  |     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) { | 
 
 |  |  | 
 |  |  |  | 
 |  |  |     private void valid(CreateCouponTemplatePointDTO 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())) { | 
 |  |  |  | 
 |  |  |             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) { | 
 
 |  |  | 
 |  |  | 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"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } | 
 
 |  |  | 
 |  |  |             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) { | 
 
 |  |  | 
 |  |  |         join t_order_point_goods opg on opg.goods_record_id = gr.id | 
 |  |  |         where opg.order_id = #{orderId} | 
 |  |  |     </select> | 
 |  |  |     <select id="getFlowerCompleteNumToday" resultType="java.lang.Integer"> | 
 |  |  |     <select id="getFlowerCompleteNumWithinTimeRange" resultType="java.lang.Integer"> | 
 |  |  |         select IFNULL(sum(oi.num),0) as complete_num | 
 |  |  |         from t_order o | 
 |  |  |         left join t_order_item oi | 
 |  |  |         on o.id=oi.order_id | 
 |  |  |         where o.DELETEd=0 and oi.DELETEd=0 | 
 |  |  |         and o.status_backend not in ('PENDING','CANCEL','REFUND') | 
 |  |  |         and o.create_by=#{userId} | 
 |  |  |         AND oi.flower_id=#{flowerId} | 
 |  |  |         AND o.complete_time BETWEEN  DATE_SUB(CURDATE(), INTERVAL 1 DAY) + INTERVAL 17 HOUR  AND CURDATE() + INTERVAL 17 HOUR | 
 |  |  |           and o.status_backend not in ('PENDING','CANCEL','REFUND') | 
 |  |  |           and o.create_by=#{userId} | 
 |  |  |           AND oi.flower_id=#{flowerId} | 
 |  |  |           AND o.payment_time BETWEEN  #{startTime}  AND #{endTime} | 
 |  |  |     </select> | 
 |  |  | </mapper> |