Ver código fonte

fix 修改油管退款规则 比例退余额

zoujiajian 8 meses atrás
pai
commit
781d35e949

+ 35 - 9
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -2516,7 +2516,12 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 			if (refundBalance.compareTo(BigDecimal.ZERO) > 0) {
 				orderDon.setRefundBalance(refundBalance);
 			}
-			orderDon.setRefundDesc("油管掉会员退款");
+			String refundDesc = StrUtil.EMPTY;
+			if (relationView.getIsFrozen()) {
+				refundDesc = "冻结剩余时长" + relationView.getReservedDays() + "天";
+			}
+			refundDesc += "油管掉会员退款";
+			orderDon.setRefundDesc(refundDesc);
 			orderDonMapper.updateById(orderDon);
 			//记录退款类型
 			String refundType = getRefundType(refundMoney, refundBalance, orderDon);
@@ -2553,20 +2558,27 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		}
 		//剩余几个月
 		Long remainMonths = DateUtil.betweenMonth(now, expiryTime, false) + 1;
+		//剩余几天
+		Long remainDays = DateUtil.betweenDay(now, expiryTime, false) + 1;
 		BigDecimal refundBalance = BigDecimal.ZERO;
 		BigDecimal refundMoney = BigDecimal.ZERO;
 		//订单金额
 		BigDecimal money = orderDon.getMoney();
 		BigDecimal balance = Optional.ofNullable(orderDon.getBalance()).orElse(BigDecimal.ZERO);
 		BigDecimal orderTotalMoney = money.add(balance);
+		//兑换码订单
+		if (orderTotalMoney.compareTo(BigDecimal.ZERO) == 0) {
+			orderTotalMoney = sku.getPrice();
+		}
+		BigDecimal orderRateMoney = orderTotalMoney;
+		//总天数
+		Integer totalDays = 365;
 		//2年
 		if ((sku.getDays() != null && sku.getDays() == 730) || (sku.getMonths() != null && sku.getMonths() == 24)) {
 			if (remainMonths > 12) {
-				//兑换码订单
-				if (orderTotalMoney.compareTo(BigDecimal.ZERO) == 0) {
-					orderTotalMoney = sku.getPrice();
-				}
-				BigDecimal totalRefundMoney = orderTotalMoney.divide(BigDecimal.valueOf(2), RoundingMode.DOWN);
+				BigDecimal totalRefundMoney = orderTotalMoney.divide(BigDecimal.valueOf(2), 0, RoundingMode.DOWN);
+				//计算比例的订单金额 超过一年后剩余可退金额
+				orderRateMoney = totalRefundMoney;
 				if (money.compareTo(BigDecimal.ZERO) == 0) {
 					refundBalance = refundBalance.add(totalRefundMoney);
 				} else {
@@ -2577,18 +2589,32 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 					}
 				}
 				remainMonths = remainMonths - 12;
+				remainDays = remainDays - 365;
+			} else {
+				totalDays = totalDays * 2;
 			}
 		}
+		if (relationView.getIsFrozen()) {
+			remainDays = Long.valueOf(relationView.getReservedDays());
+		}
+		BigDecimal monthRateRefundBalance = BigDecimal.valueOf(remainDays).multiply(orderRateMoney).divide(BigDecimal.valueOf(totalDays), 0, RoundingMode.DOWN);
+		//剩余月份限制最高可退余额
+		BigDecimal remainMonthsRefundBalance;
 		if (remainMonths >= 1 && remainMonths <= 6) {
 			//1-6月买的 退100余额
-			refundBalance = refundBalance.add(BigDecimal.valueOf(10000));
+			remainMonthsRefundBalance = BigDecimal.valueOf(10000);
 		} else if (remainMonths >= 7 && remainMonths <= 11) {
 			//7-11月买的 退150余额
-			refundBalance = refundBalance.add(BigDecimal.valueOf(15000));
+			remainMonthsRefundBalance = BigDecimal.valueOf(15000);
 		} else {
 			//12月买的 退200余额
-			refundBalance = refundBalance.add(BigDecimal.valueOf(20000));
+			remainMonthsRefundBalance = BigDecimal.valueOf(20000);
+		}
+		//按比例退款余额超过对应剩余月份可退余额限制
+		if (monthRateRefundBalance.compareTo(remainMonthsRefundBalance) > 0) {
+			monthRateRefundBalance = remainMonthsRefundBalance;
 		}
+		refundBalance = refundBalance.add(monthRateRefundBalance);
 		//超过订单金额 计算剩余的余额 排除兑换码
 		if (orderTotalMoney.compareTo(BigDecimal.ZERO) > 0 && refundMoney.add(refundBalance).compareTo(orderTotalMoney) > 0) {
 			refundBalance = orderTotalMoney.subtract(refundMoney);