Commit 412ea1a4 by 吕明尚

修改订单计算

parent 829874d7
...@@ -114,5 +114,11 @@ public class OrderVo { ...@@ -114,5 +114,11 @@ public class OrderVo {
private BigDecimal payPrice; private BigDecimal payPrice;
private BigDecimal duration;
private BigDecimal balance;
private BigDecimal discountRatio;
} }
...@@ -42,6 +42,10 @@ public class ComputedOrderPriceResponse implements Serializable { ...@@ -42,6 +42,10 @@ public class ComputedOrderPriceResponse implements Serializable {
@ApiModelProperty(value = "折扣比例") @ApiModelProperty(value = "折扣比例")
private BigDecimal discountRatio; private BigDecimal discountRatio;
//会员折扣
@ApiModelProperty(value = "会员折扣")
private BigDecimal memberDiscount;
@ApiModelProperty(value = "可用时长") @ApiModelProperty(value = "可用时长")
private BigDecimal availableDuration; private BigDecimal availableDuration;
......
...@@ -2310,6 +2310,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2310,6 +2310,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setRemainingDuration(BigDecimal.ZERO); priceResponse.setRemainingDuration(BigDecimal.ZERO);
priceResponse.setAvailableDuration(BigDecimal.ZERO); priceResponse.setAvailableDuration(BigDecimal.ZERO);
priceResponse.setDiscount(BigDecimal.ZERO); priceResponse.setDiscount(BigDecimal.ZERO);
priceResponse.setMemberDiscount(BigDecimal.ZERO);
Activity activity = null; Activity activity = null;
ConsumerMember consumerMember = null; ConsumerMember consumerMember = null;
ConsumerWallet consumerWallet = null; ConsumerWallet consumerWallet = null;
...@@ -2340,10 +2341,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2340,10 +2341,10 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
queryWrapper.eq(Activity::getLabelId, roomLabel.getLabelId()); queryWrapper.eq(Activity::getLabelId, roomLabel.getLabelId());
activity = activityService.getOne(queryWrapper); activity = activityService.getOne(queryWrapper);
totalFee = getBigDecimal(request, activity, payPrice, user, consumerMember); totalFee = getBigDecimal(request, activity, payPrice, user, consumerMember);
priceResponse.setTotalFeeNow(totalFee); // priceResponse.setTotalFeeNow(totalFee);
priceResponse.setDiscount(totalFee.divide(payPrice).multiply(new BigDecimal(100))); priceResponse.setDiscount(totalFee.divide(payPrice).multiply(new BigDecimal(100)));
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, room, request, consumerMember);
} }
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, room, request);
} else { } else {
SPack byId = packService.getById(roomLabel.getPackId()); SPack byId = packService.getById(roomLabel.getPackId());
if (!ObjectUtils.isEmpty(byId) && byId.getIsOpen().equals(YesNoEnum.yes.getIndex())) { if (!ObjectUtils.isEmpty(byId) && byId.getIsOpen().equals(YesNoEnum.yes.getIndex())) {
...@@ -2355,10 +2356,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2355,10 +2356,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
activity = activityService.getOne(queryWrapper); activity = activityService.getOne(queryWrapper);
totalFee = getBigDecimal(request, activity, payPrice, user, consumerMember); totalFee = getBigDecimal(request, activity, payPrice, user, consumerMember);
priceResponse.setTotalFeeNow(totalFee); priceResponse.setTotalFeeNow(totalFee);
priceResponse.setMemberDiscount(payPrice.subtract(totalFee));
priceResponse.setDiscount(totalFee.divide(payPrice).multiply(new BigDecimal(100))); priceResponse.setDiscount(totalFee.divide(payPrice).multiply(new BigDecimal(100)));
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, byId, request);
} }
// totalFee = getBigDecimal(consumerWallet, timeLong, priceResponse, totalFee, byId); // totalFee = getBigDecimal(consumerWallet, timeLong, priceResponse, totalFee, byId);
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, byId, request);
} else { } else {
payPrice = totalPrice; payPrice = totalPrice;
priceResponse.setTotalFeeNow(payPrice); priceResponse.setTotalFeeNow(payPrice);
...@@ -2367,11 +2370,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2367,11 +2370,12 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
queryWrapper.eq(Activity::getLabelId, roomLabel.getLabelId()); queryWrapper.eq(Activity::getLabelId, roomLabel.getLabelId());
activity = activityService.getOne(queryWrapper); activity = activityService.getOne(queryWrapper);
totalFee = getBigDecimal(request, activity, payPrice, user, consumerMember); totalFee = getBigDecimal(request, activity, payPrice, user, consumerMember);
priceResponse.setTotalFeeNow(totalFee); // priceResponse.setTotalFeeNow(totalFee);
priceResponse.setDiscount(totalFee.divide(payPrice).multiply(new BigDecimal(100))); priceResponse.setDiscount(totalFee.divide(payPrice).multiply(new BigDecimal(100)));
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, room, request, consumerMember);
} }
// totalFee = getBigDecimal(consumerWallet, timeLong, priceResponse, totalFee, room); // totalFee = getBigDecimal(consumerWallet, timeLong, priceResponse, totalFee, room);
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, room, request);
} }
} }
} else if (!ObjectUtils.isEmpty(request.getPackId())) { } else if (!ObjectUtils.isEmpty(request.getPackId())) {
...@@ -2384,9 +2388,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2384,9 +2388,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
activity = activityService.getOne(queryWrapper); activity = activityService.getOne(queryWrapper);
totalFee = getBigDecimal(request, activity, payPrice, user, consumerMember); totalFee = getBigDecimal(request, activity, payPrice, user, consumerMember);
priceResponse.setTotalFeeNow(totalFee); priceResponse.setTotalFeeNow(totalFee);
priceResponse.setMemberDiscount(payPrice.subtract(totalFee));
priceResponse.setDiscount(totalFee.divide(payPrice).multiply(new BigDecimal(100))); priceResponse.setDiscount(totalFee.divide(payPrice).multiply(new BigDecimal(100)));
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, byId, request);
} }
totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, byId, request);
} }
priceResponse.setTotalFee(payPrice); priceResponse.setTotalFee(payPrice);
if (ObjectUtil.isEmpty(consumerWallet) && totalFee.compareTo(new BigDecimal(0)) == 0) { if (ObjectUtil.isEmpty(consumerWallet) && totalFee.compareTo(new BigDecimal(0)) == 0) {
...@@ -2457,8 +2463,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2457,8 +2463,9 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
} }
private BigDecimal getBigDecimal(ConsumerWallet consumerWallet, Activity activity, BigDecimal timeLong, private BigDecimal getBigDecimal(ConsumerWallet consumerWallet, Activity activity, BigDecimal timeLong,
ComputedOrderPriceResponse priceResponse, BigDecimal totalFee, SRoom room, OrderComputedPriceRequest request) { ComputedOrderPriceResponse priceResponse, BigDecimal totalFee, SRoom room, OrderComputedPriceRequest request, ConsumerMember consumerMember) {
if (ObjectUtil.isNotEmpty(consumerWallet)) { if (ObjectUtil.isNotEmpty(consumerWallet) && ObjectUtil.isNotEmpty(consumerMember)) {
MemberConfig memberConfig = memberConfigService.getById(consumerMember.getMemberConfigId());
CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)); CronParser cronParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
priceResponse.setDuration(BigDecimal.ZERO); priceResponse.setDuration(BigDecimal.ZERO);
priceResponse.setRemainingDuration(BigDecimal.ZERO); priceResponse.setRemainingDuration(BigDecimal.ZERO);
...@@ -2471,6 +2478,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2471,6 +2478,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
if (consumerWallet.getBalance().compareTo(totalFee) >= 0) { if (consumerWallet.getBalance().compareTo(totalFee) >= 0) {
priceResponse.setBalance(totalFee); priceResponse.setBalance(totalFee);
priceResponse.setRemainingBalance(consumerWallet.getBalance().subtract(totalFee)); priceResponse.setRemainingBalance(consumerWallet.getBalance().subtract(totalFee));
priceResponse.setTotalFeeNow(totalFee);
priceResponse.setMemberDiscount(totalFee);
totalFee = new BigDecimal(0); totalFee = new BigDecimal(0);
} else if (consumerWallet.getBalance().compareTo(totalFee) < 0) { } else if (consumerWallet.getBalance().compareTo(totalFee) < 0) {
priceResponse.setBalance(consumerWallet.getBalance()); priceResponse.setBalance(consumerWallet.getBalance());
...@@ -2485,14 +2494,19 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2485,14 +2494,19 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setDuration(consumerWallet.getRemainingDuration()); priceResponse.setDuration(consumerWallet.getRemainingDuration());
priceResponse.setRemainingDuration(new BigDecimal(0)); priceResponse.setRemainingDuration(new BigDecimal(0));
BigDecimal remainingBalance = consumerWallet.getRemainingDuration().multiply(room.getPrice()); BigDecimal remainingBalance = consumerWallet.getRemainingDuration().multiply(room.getPrice());
remainingBalance = priceResponse.getTotalFeeNow().subtract(remainingBalance); totalFee = totalFee.divide(memberConfig.getDiscountRatio()).multiply(new BigDecimal(100));
if (consumerWallet.getBalance().compareTo(remainingBalance) >= 0) { remainingBalance = totalFee.subtract(remainingBalance);
priceResponse.setBalance(remainingBalance); BigDecimal divide = remainingBalance;
priceResponse.setRemainingBalance(consumerWallet.getBalance().subtract(remainingBalance)); divide = divide.multiply(memberConfig.getDiscountRatio()).divide(new BigDecimal(100));
priceResponse.setTotalFeeNow(divide);
priceResponse.setMemberDiscount(remainingBalance.subtract(divide));
if (consumerWallet.getBalance().compareTo(divide) >= 0) {
priceResponse.setBalance(divide);
priceResponse.setRemainingBalance(consumerWallet.getBalance().subtract(divide));
totalFee = new BigDecimal(0); totalFee = new BigDecimal(0);
} else if (consumerWallet.getBalance().compareTo(remainingBalance) < 0) { } else if (consumerWallet.getBalance().compareTo(divide) < 0) {
priceResponse.setBalance(consumerWallet.getBalance()); priceResponse.setBalance(consumerWallet.getBalance());
totalFee = remainingBalance.subtract(consumerWallet.getBalance()); totalFee = divide.subtract(consumerWallet.getBalance());
} }
} }
} }
...@@ -2504,17 +2518,24 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -2504,17 +2518,24 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
} else if (consumerWallet.getRemainingDuration().compareTo(timeLong) < 0) { } else if (consumerWallet.getRemainingDuration().compareTo(timeLong) < 0) {
priceResponse.setDuration(consumerWallet.getRemainingDuration()); priceResponse.setDuration(consumerWallet.getRemainingDuration());
priceResponse.setRemainingDuration(new BigDecimal(0)); priceResponse.setRemainingDuration(new BigDecimal(0));
//时长的金额
BigDecimal remainingBalance = consumerWallet.getRemainingDuration().multiply(room.getPrice()); BigDecimal remainingBalance = consumerWallet.getRemainingDuration().multiply(room.getPrice());
remainingBalance = priceResponse.getTotalFeeNow().subtract(remainingBalance); //恢复原价
if (consumerWallet.getBalance().compareTo(remainingBalance) >= 0) { totalFee = totalFee.divide(memberConfig.getDiscountRatio()).multiply(new BigDecimal(100));
priceResponse.setBalance(remainingBalance); //原价减时长
priceResponse.setRemainingBalance(consumerWallet.getBalance().subtract(remainingBalance)); remainingBalance = totalFee.subtract(remainingBalance);
BigDecimal divide = remainingBalance;
divide = divide.multiply(memberConfig.getDiscountRatio()).divide(new BigDecimal(100));
priceResponse.setTotalFeeNow(divide);
priceResponse.setMemberDiscount(remainingBalance.subtract(divide));
if (consumerWallet.getBalance().compareTo(divide) >= 0) {
priceResponse.setBalance(divide);
priceResponse.setRemainingBalance(consumerWallet.getBalance().subtract(divide));
totalFee = new BigDecimal(0); totalFee = new BigDecimal(0);
} else if (consumerWallet.getBalance().compareTo(remainingBalance) < 0) { } else if (consumerWallet.getBalance().compareTo(divide) < 0) {
priceResponse.setBalance(consumerWallet.getBalance()); priceResponse.setBalance(consumerWallet.getBalance());
priceResponse.setRemainingBalance(BigDecimal.ZERO); priceResponse.setRemainingBalance(BigDecimal.ZERO);
totalFee = remainingBalance.subtract(consumerWallet.getBalance()); totalFee = divide.subtract(consumerWallet.getBalance());
} }
} }
} }
......
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