Commit 4d4d4eb8 by 吕明尚

修改计算订单金额

parent 1dbdec0b
...@@ -52,4 +52,7 @@ public class OrderComputedPriceRequest { ...@@ -52,4 +52,7 @@ public class OrderComputedPriceRequest {
@ApiModelProperty(value = "预约结束时间 yyyy-MM-dd HH:mm", required = true) @ApiModelProperty(value = "预约结束时间 yyyy-MM-dd HH:mm", required = true)
@NotNull(message = "预约结束时间不能为空") @NotNull(message = "预约结束时间不能为空")
private Date preEndDate; private Date preEndDate;
@ApiModelProperty(value = "标签id")
private Long roomLabelId;
} }
...@@ -44,8 +44,8 @@ import share.system.response.ComputedOrderPriceResponse; ...@@ -44,8 +44,8 @@ import share.system.response.ComputedOrderPriceResponse;
import share.system.response.OrderPayResultResponse; import share.system.response.OrderPayResultResponse;
import share.system.service.*; import share.system.service.*;
import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -123,6 +123,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -123,6 +123,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
@Autowired @Autowired
private SaobeiApiLogService saobeiApiLogService; private SaobeiApiLogService saobeiApiLogService;
@Resource
private RoomLabelService roomLabelService;
private final static Long FIVE = 5l; private final static Long FIVE = 5l;
...@@ -1808,11 +1811,16 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1808,11 +1811,16 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
break; break;
case PACKAGE://套餐券 case PACKAGE://套餐券
case CASH://现金券(团购券) case CASH://现金券(团购券)
case DURATION://时长券
//判断优惠券最小使用金额 //判断优惠券最小使用金额
if (consumerCoupon.getMinPrice().compareTo(priceResponse.getTotalFee()) > 0) { if (consumerCoupon.getMinPrice().compareTo(priceResponse.getTotalFee()) > 0) {
throw new BaseException("总金额小于优惠券最小使用金额"); throw new BaseException("总金额小于优惠券最小使用金额");
} }
BigDecimal subtract = priceResponse.getTotalFee().subtract(consumerCoupon.getSubPrice()); RoomLabel roomLabel = roomLabelService.selectRoomLabelById(request.getRoomLabelId());
//(促销价-优惠券促销价)+((时长-促销时长)*单价)
SRoom room = roomService.getById(request.getRoomId());
BigDecimal subtract = roomLabel.getPromotionAmount().subtract(consumerCoupon.getPromotionPrice()).
add((DateUtils.differentHour(request.getPreStartDate(), request.getPreEndDate()).subtract(new BigDecimal(roomLabel.getPromotionDuration()))).multiply(room.getPrice()));
//判断是否为负数 //判断是否为负数
if (subtract.compareTo(BigDecimal.ZERO) < 0) { if (subtract.compareTo(BigDecimal.ZERO) < 0) {
priceResponse.setPayFee(BigDecimal.ZERO); priceResponse.setPayFee(BigDecimal.ZERO);
...@@ -1822,21 +1830,34 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -1822,21 +1830,34 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setCouponFee(priceResponse.getTotalFee().subtract(subtract)); priceResponse.setCouponFee(priceResponse.getTotalFee().subtract(subtract));
} }
break; break;
case DURATION://时长券 //
BigDecimal timeLong = DateUtils.differentHour(request.getPreStartDate(), request.getPreEndDate()); // BigDecimal timeLong = DateUtils.differentHour(request.getPreStartDate(), request.getPreEndDate());
if (new BigDecimal(consumerCoupon.getMinDuration()).compareTo(timeLong) > 0) { // if (new BigDecimal(consumerCoupon.getMinDuration()).compareTo(timeLong) > 0) {
throw new BaseException("总时长小于优惠券最小使用时长"); // throw new BaseException("总时长小于优惠券最小使用时长");
} // }
BigDecimal duration = new BigDecimal(consumerCoupon.getDuration()); // roomLabel = roomLabelService.selectRoomLabelById(request.getRoomLabelId());
if (duration.compareTo(timeLong) >= 0) { // //(促销价-优惠券促销价)+((时长-促销时长)*单价)
priceResponse.setPayFee(BigDecimal.ZERO); // room = roomService.getById(request.getRoomId());
priceResponse.setCouponFee(priceResponse.getTotalFee()); // subtract = roomLabel.getPromotionAmount().subtract(consumerCoupon.getPromotionPrice()).
} else { // add((DateUtils.differentHour(request.getPreStartDate(), request.getPreEndDate()).subtract(new BigDecimal(roomLabel.getPromotionDuration()))).multiply(room.getPrice()));
BigDecimal unitPrice = priceResponse.getTotalFee().divide(timeLong); // BigDecimal duration = new BigDecimal(consumerCoupon.getDuration());
priceResponse.setPayFee(unitPrice.multiply(timeLong.subtract(duration)).setScale(2, RoundingMode.HALF_DOWN)); // if (duration.compareTo(timeLong) >= 0) {
priceResponse.setCouponFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee())); // priceResponse.setPayFee(BigDecimal.ZERO);
} // priceResponse.setCouponFee(priceResponse.getTotalFee());
break; // } else {
// BigDecimal unitPrice = priceResponse.getTotalFee().divide(timeLong);
// priceResponse.setPayFee(unitPrice.multiply(timeLong.subtract(duration)).setScale(2, RoundingMode.HALF_DOWN));
// priceResponse.setCouponFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
// }
//判断是否为负数
// if (subtract.compareTo(BigDecimal.ZERO) < 0) {
// priceResponse.setPayFee(BigDecimal.ZERO);
// priceResponse.setCouponFee(priceResponse.getTotalFee());
// } else {
// priceResponse.setPayFee(subtract);
// priceResponse.setCouponFee(priceResponse.getTotalFee().subtract(subtract));
// }
// 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