Commit 7bb538d0 by wuwenlong

check coupon dev;

parent 0da87a87
...@@ -28,6 +28,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils ...@@ -28,6 +28,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
public static String YYYY_MM_DD_HH= "yyyy-MM-dd HH"; public static String YYYY_MM_DD_HH= "yyyy-MM-dd HH";
public static String YYYY_MM_DD_HH_MM= "yyyy-MM-dd HH:mm";
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
......
...@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty; ...@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import share.common.annotation.Excel;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
...@@ -29,6 +30,13 @@ public class CouponRequest { ...@@ -29,6 +30,13 @@ public class CouponRequest {
@NotNull(message = "下单模式不能为空") @NotNull(message = "下单模式不能为空")
private Integer orderMode; private Integer orderMode;
@ApiModelProperty(value = "下单类型(1:预定,2:续单)", required = true)
@NotNull(message = "下单类型不能为空")
private Integer orderType;
@ApiModelProperty(value = "套餐ID")
private Long packageId;
/** /**
* 预约开始时间 * 预约开始时间
*/ */
......
...@@ -1048,7 +1048,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1048,7 +1048,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
// 判断优惠券是否可以使用 // 判断优惠券是否可以使用
if(Objects.nonNull(user)&&Objects.nonNull(request.getCouponId())) { if(Objects.nonNull(user)&&Objects.nonNull(request.getCouponId())) {
SConsumerCoupon consumerCoupon = consumerCouponService.getById(request.getCouponId()); SConsumerCoupon consumerCoupon = consumerCouponService.getById(request.getCouponId());
computedCouponPrice(priceResponse, user, consumerCoupon); computedCouponPrice(request, priceResponse, user, consumerCoupon);
} }
} }
return priceResponse; return priceResponse;
...@@ -1065,7 +1065,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1065,7 +1065,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
/** /**
* 计算使用优惠券后的订单金额 * 计算使用优惠券后的订单金额
*/ */
private void computedCouponPrice(ComputedOrderPriceResponse priceResponse, SConsumer user, SConsumerCoupon consumerCoupon) { private void computedCouponPrice(OrderComputedPriceRequest request, ComputedOrderPriceResponse priceResponse
, SConsumer user, SConsumerCoupon consumerCoupon) {
if (ObjectUtil.isNull(consumerCoupon) || !consumerCoupon.getConsumerId().equals(user.getId())) { if (ObjectUtil.isNull(consumerCoupon) || !consumerCoupon.getConsumerId().equals(user.getId())) {
throw new BaseException("优惠券领取记录不存在!"); throw new BaseException("优惠券领取记录不存在!");
} }
...@@ -1085,7 +1086,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1085,7 +1086,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
case DISCOUNT://TODO 折扣券 case DISCOUNT://TODO 折扣券
break; break;
case PACKAGE://套餐券 case PACKAGE://套餐券
case CASH://现金券 case CASH://现金券(团购券)
//判断优惠券最小使用金额 //判断优惠券最小使用金额
if (consumerCoupon.getMinPrice().compareTo(priceResponse.getTotalFee()) > 0) { if (consumerCoupon.getMinPrice().compareTo(priceResponse.getTotalFee()) > 0) {
throw new BaseException("总金额小于优惠券最小使用金额"); throw new BaseException("总金额小于优惠券最小使用金额");
...@@ -1099,7 +1100,19 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1099,7 +1100,19 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setPayFee(subtract); priceResponse.setPayFee(subtract);
} }
break; break;
case DURATION://TODO 时长券 case DURATION://时长券
BigDecimal timeLong = DateUtils.differentHour(request.getPreStartDate(), request.getPreEndDate());
if(new BigDecimal(consumerCoupon.getMinDuration()).compareTo(timeLong)>0){
throw new BaseException("总时长小于优惠券最小使用时长");
}
BigDecimal duration = new BigDecimal(consumerCoupon.getDuration());
if(duration.compareTo(timeLong)>=0){
priceResponse.setPayFee(BigDecimal.ZERO);
} else {
BigDecimal unitPrice = priceResponse.getTotalFee().divide(timeLong);
priceResponse.setPayFee(unitPrice.multiply(timeLong.subtract(duration)));
priceResponse.setCouponFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
}
break; break;
default: default:
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment