zoujiajian 1 tahun lalu
induk
melakukan
4f11afb533

+ 25 - 0
netflix-service/src/main/java/com/cyksj/service/mange/vip/impl/CmsVipOrderServiceImpl.java

@@ -206,6 +206,31 @@ public class CmsVipOrderServiceImpl implements CmsVipOrderService {
 		if (vipUser == null) {
 			throw BusinessRuntimeException.getInstance("用户会员已过期,无法退款");
 		}
+		String refundType = refundReq.getRefundType();
+		BigDecimal refundMoney = refundReq.getRefundMoney();
+		BigDecimal money = orderDon.getMoney();
+		BigDecimal orderDonRefundMoney = Optional.ofNullable(orderDon.getRefundMoney()).orElse(BigDecimal.ZERO);
+		BigDecimal orderDonRefundBalance = Optional.ofNullable(orderDon.getRefundBalance()).orElse(BigDecimal.ZERO);
+		//余额退款
+		if (OrderDon.Type.BALANCE.getType().equals(refundType)) {
+			BigDecimal balance = orderDon.getBalance();
+			refundMoney = orderDonRefundBalance.add(refundMoney);
+			if (VipOrderDon.Type.BALANCE == orderDon.getType() && refundMoney.compareTo(balance) > 0) {
+				throw BusinessRuntimeException.getInstance("退款余额大于订单支付余额");
+			}
+			if (VipOrderDon.Type.BALANCE != orderDon.getType() && refundMoney.compareTo(money) > 0) {
+				throw BusinessRuntimeException.getInstance("退款余额大于订单支付金额");
+			}
+			orderDon.setRefundBalance(refundMoney);
+			orderDon.setRefundMoney(BigDecimal.ZERO);
+		} else {
+			//退金额
+			refundMoney = orderDonRefundMoney.add(refundMoney);
+			if (refundMoney.compareTo(money) > 0) {
+				throw BusinessRuntimeException.getInstance("退款金额大于订单支付金额");
+			}
+			orderDon.setRefundMoney(refundMoney);
+		}
 	}
 
 	/**