1.优惠券-使用条件-根据满减还是无门槛控制
2.商品限购-根据payment_time来控制
已修改11个文件
131 ■■■■ 文件已修改
src/main/java/com/mzl/flower/dto/request/coupon/CreateCouponTemplateActivyDTO.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/coupon/CreateCouponTemplatePointDTO.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/coupon/CreateCouponTemplateUserDTO.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/coupon/CreateCouponTemplateVipDTO.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/mapper/payment/OrderMapper.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/service/payment/OrderService.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateActivyController.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplatePointController.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateUserController.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateVipController.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/payment/OrderMapper.xml 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/mzl/flower/dto/request/coupon/CreateCouponTemplateActivyDTO.java
@@ -111,7 +111,7 @@
    @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;
    /**
src/main/java/com/mzl/flower/dto/request/coupon/CreateCouponTemplatePointDTO.java
@@ -61,7 +61,7 @@
    @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;
    /**
src/main/java/com/mzl/flower/dto/request/coupon/CreateCouponTemplateUserDTO.java
@@ -59,7 +59,7 @@
    @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;
    /**
src/main/java/com/mzl/flower/dto/request/coupon/CreateCouponTemplateVipDTO.java
@@ -53,7 +53,7 @@
    @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;
src/main/java/com/mzl/flower/mapper/payment/OrderMapper.java
@@ -50,5 +50,6 @@
            "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);
}
src/main/java/com/mzl/flower/service/payment/OrderService.java
@@ -65,6 +65,7 @@
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;
@@ -1575,7 +1576,31 @@
    }
    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;
    }
}
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateActivyController.java
@@ -177,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) {
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplatePointController.java
@@ -216,11 +216,17 @@
    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) {
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateUserController.java
@@ -6,6 +6,7 @@
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;
@@ -45,14 +46,8 @@
    @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);
@@ -77,14 +72,7 @@
        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) {
@@ -187,4 +175,22 @@
    }
    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");
        }
    }
}
src/main/java/com/mzl/flower/web/v2/coupon/CouponTemplateVipController.java
@@ -162,11 +162,17 @@
            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) {
src/main/resources/mapper/payment/OrderMapper.xml
@@ -261,15 +261,15 @@
        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>