Commit 4d4d4eb8 by 吕明尚

修改计算订单金额

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