Commit bcb79f3f by 吕明尚

修改订单价格计算

parent 042e8a9c
......@@ -1208,7 +1208,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
MemberConfig one = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>()
// .eq(MemberConfig::getMemberType, consumerMember.getMemberType())
.eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel() + 1L));
if (consumerMember.getMemberType().equals(MemberTypeEnum.NORMAL.getIndex())) {
// if (consumerMember.getMemberType().equals(MemberTypeEnum.NORMAL.getIndex())) {
if (consumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex())) {
// consumerMember.setMemberType(MemberTypeEnum.RECHARGE.getIndex());
if (ObjectUtil.isNotEmpty(one) && membershipProgress.compareTo(BigDecimal.valueOf(one.getLimitRequirements())) >= 0) {
......@@ -2480,28 +2480,18 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
);
// if (ObjectUtil.isNotEmpty(consumerMember)) {
// queryWrapper.eq(Activity::getIsOpen, YesNoEnum.yes.getIndex());
// queryWrapper.eq(Activity::getMemberType, consumerMember.getMemberType());
// if (consumerMember.getIsRights().equals(YesNoEnum.yes.getIndex())) {
// queryWrapper.eq(Activity::getMemberType, MemberTypeEnum.RIGHTS.getIndex());
// } else if (consumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex()) && consumerMember.getIsRights().equals(YesNoEnum.no.getIndex())) {
// queryWrapper.eq(Activity::getMemberType, MemberTypeEnum.RECHARGE.getIndex());
// } else {
// queryWrapper.eq(Activity::getMemberType, MemberTypeEnum.NORMAL.getIndex());
// }
// }
// if (ObjectUtil.isNotEmpty(consumerWallet)) {
// priceResponse.setAvailableBalance(consumerWallet.getBalance());
// priceResponse.setAvailableDuration(consumerWallet.getRemainingDuration());
// }
consumerWallet = consumerWalletService.getOne(new LambdaQueryWrapper<ConsumerWallet>().eq(ConsumerWallet::getConsumerId, user.getId()));
consumerMember = consumerMemberService.getOne(new LambdaQueryWrapper<ConsumerMember>().eq(ConsumerMember::getConsumerId, user.getId()));
if (ObjectUtil.isNotEmpty(consumerMember)) {
queryWrapper.eq(Activity::getIsOpen, YesNoEnum.yes.getIndex());
if (consumerMember.getIsRights().equals(YesNoEnum.yes.getIndex())) {
queryWrapper.eq(Activity::getMemberType, MemberTypeEnum.RIGHTS.getIndex());
} else if (consumerMember.getIsRecharge().equals(YesNoEnum.yes.getIndex()) && consumerMember.getIsRights().equals(YesNoEnum.no.getIndex())) {
queryWrapper.eq(Activity::getMemberType, MemberTypeEnum.RECHARGE.getIndex());
} else {
queryWrapper.eq(Activity::getMemberType, MemberTypeEnum.NORMAL.getIndex());
}
}
if (ObjectUtil.isNotEmpty(consumerWallet)) {
priceResponse.setAvailableBalance(consumerWallet.getBalance());
priceResponse.setAvailableDuration(consumerWallet.getRemainingDuration());
}
}
SRoom room = roomService.getById(request.getRoomId());
BigDecimal totalPrice = computeTotalPrice(room.getPrice(), request.getPreStartDate(), request.getPreEndDate());
......@@ -2521,6 +2511,8 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
// priceResponse.setTotalFeeNow(totalFee);
// priceResponse.setMemberDiscount(payPrice.subtract(totalFee));
//// priceResponse.setTotalFeeNow(totalFee);
//// priceResponse.setMemberDiscount(payPrice.subtract(totalFee));
//// priceResponse.setTotalFeeNow(totalFee);
// priceResponse.setDiscount(totalFee.divide(payPrice, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
// totalFee = getBigDecimal(consumerWallet, activity, timeLong, priceResponse, totalFee, room, request, consumerMember);
// }
......@@ -2631,7 +2623,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
priceResponse.setRemainingDuration(new BigDecimal(0));
if (priceResponse.getPayFee().compareTo(new BigDecimal(0)) > 0) {
// if (ObjectUtil.isNotEmpty(consumerMember)) {
// MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getId, consumerMember.getMemberConfigId()));
// MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel()));
//
// BigDecimal payFee = priceResponse.getPayFee();
// BigDecimal divide = priceResponse.getPayFee().multiply(memberConfig.getDiscountRatio()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
......@@ -2665,41 +2657,6 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
// priceResponse.setTotalFeeNow(priceResponse.getPayFee());
// priceResponse.setMemberDiscount(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
// }
if (ObjectUtil.isNotEmpty(consumerMember)) {
MemberConfig memberConfig = memberConfigService.getOne(new LambdaQueryWrapper<MemberConfig>().eq(MemberConfig::getMembershipLevel, consumerMember.getMembershipLevel()));
BigDecimal payFee = priceResponse.getPayFee();
BigDecimal divide = priceResponse.getPayFee().multiply(memberConfig.getDiscountRatio()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
if (payFee.compareTo(divide) == 0) {
priceResponse.setDiscount(BigDecimal.ZERO);
}
//总金额乘以折扣比例除以100
priceResponse.setPayFee(divide);
priceResponse.setDiscountFee(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
priceResponse.setTotalFeeNow(divide);
priceResponse.setMemberDiscount(payFee.subtract(divide));
// priceResponse.setCouponFee(priceResponse.getDiscountFee());
if (ObjectUtil.isNotEmpty(priceResponse.getDiscountFee()) && priceResponse.getTotalFee().compareTo(new BigDecimal(0.00)) > 0) {
priceResponse.setDiscountRatio(priceResponse.getDiscountFee().divide(priceResponse.getTotalFee(), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)));
} else {
priceResponse.setDiscountRatio(new BigDecimal(0));
}
}
if (ObjectUtil.isNotEmpty(consumerWallet)) {
if (consumerWallet.getBalance().compareTo(priceResponse.getPayFee()) >= 0) {
priceResponse.setBalance(priceResponse.getPayFee());
priceResponse.setRemainingBalance(consumerWallet.getBalance().subtract(priceResponse.getPayFee()));
totalFee = new BigDecimal(0);
} else if (consumerWallet.getBalance().compareTo(priceResponse.getPayFee()) < 0) {
priceResponse.setBalance(consumerWallet.getBalance());
totalFee = priceResponse.getPayFee().subtract(consumerWallet.getBalance());
}
priceResponse.setPayFee(totalFee);
}
if (ObjectUtil.isEmpty(consumerWallet) && ObjectUtil.isEmpty(consumerMember)) {
priceResponse.setTotalFeeNow(priceResponse.getPayFee());
priceResponse.setMemberDiscount(priceResponse.getTotalFee().subtract(priceResponse.getPayFee()));
}
} else {
priceResponse.setDiscount(BigDecimal.ZERO);
......@@ -2943,6 +2900,46 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
return payPrice;
}
private BigDecimal getBigDecimal(ConsumerMonthlyCard consumerMonthlyCard, BigDecimal timeLong,
ComputedOrderPriceResponse priceResponse, BigDecimal totalFee, SRoom room) {
if (consumerMonthlyCard.getFreeDuration().compareTo(timeLong) >= 0) {
priceResponse.setDuration(timeLong);
priceResponse.setRemainingDuration(consumerMonthlyCard.getFreeDuration().subtract(timeLong));
priceResponse.setDiscount(BigDecimal.ZERO);
totalFee = new BigDecimal(0);
priceResponse.setMemberDiscount(new BigDecimal(0.00));
priceResponse.setTotalFeeNow(priceResponse.getTotalFee());
priceResponse.setPayFee(BigDecimal.ZERO);
priceResponse.setMonthlyCardId(consumerMonthlyCard.getId());
} else if (consumerMonthlyCard.getFreeDuration().compareTo(timeLong) < 0) {
priceResponse.setDuration(consumerMonthlyCard.getFreeDuration());
priceResponse.setRemainingDuration(new BigDecimal(0));
BigDecimal remainingBalance = consumerMonthlyCard.getFreeDuration().multiply(room.getPrice());
remainingBalance = totalFee.subtract(remainingBalance);
priceResponse.setTotalFeeNow(remainingBalance);
priceResponse.setMemberDiscount(totalFee.subtract(remainingBalance));
totalFee = remainingBalance;
priceResponse.setPayFee(remainingBalance);
priceResponse.setMonthlyCardId(consumerMonthlyCard.getId());
}
return totalFee;
}
private BigDecimal getBigDecimal(List<ConsumerSecondaryCard> consumerSecondaryCardList,
ComputedOrderPriceResponse priceResponse, SPack byId, BigDecimal payPrice) {
//获取集合中次数最少的次卡,次数不低于0
ConsumerSecondaryCard consumerSecondaryCard = consumerSecondaryCardList.stream().min(Comparator.comparing(ConsumerSecondaryCard::getNumber)).get();
if (consumerSecondaryCard.getPackId().equals(byId.getId())) {
priceResponse.setDiscount(BigDecimal.ZERO);
priceResponse.setMemberDiscount(BigDecimal.ZERO);
priceResponse.setTotalFeeNow(payPrice);
priceResponse.setPayFee(BigDecimal.ZERO);
priceResponse.setSecondaryCardId(consumerSecondaryCard.getId());
payPrice = BigDecimal.ZERO;
}
return payPrice;
}
private BigDecimal computeTotalPrice(Long packId, BigDecimal totalPrice) {
SPack pack = packService.getById(packId);
if (Objects.isNull(pack)) {
......
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