Browse Source

fix:重新支付不重新算余额

liujunchi 2 years ago
parent
commit
7ab520733d

+ 22 - 14
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -1085,18 +1085,22 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             }
         }
 
+
+        // 余额支付
+        BigDecimal amount =  BigDecimal.ZERO;
+        BigDecimal balance = BigDecimal.ZERO;
+
         if (StringUtils.isNotEmpty(model.getOldOrderNo())) {
             StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(model.getOldOrderNo());
             if (orderByOrderNo == null) {
                 throw new BizException("未找到原订单");
             }
+            amount = orderByOrderNo.getActualAmount();
+            balance = orderByOrderNo.getBalancePaymentAmount();
             // 已有订单,先关单
             orderByOrderNo.setStatus(CLOSE);
             orderByOrderNo.setMemo("关闭订单");
             studentPaymentOrderService.update(orderByOrderNo);
-            if (orderByOrderNo.getBalancePaymentAmount() != null && orderByOrderNo.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
-                sysUserCashAccountService.updateBalance(orderByOrderNo.getUserId(), orderByOrderNo.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "关闭订单");
-            }
             //退优惠券
             sysCouponCodeService.quit(orderByOrderNo.getCouponCodeId());
         }
@@ -1128,19 +1132,23 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         studentPaymentOrder.setVersion(studentPaymentOrder.getVersion());
 
         // 余额支付
-        BigDecimal amount = studentPaymentOrder.getActualAmount();
-        BigDecimal balance = BigDecimal.ZERO;
-        if (model.isUseBalance() && amount.compareTo(BigDecimal.ZERO) > 0) {
-            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(model.getUserId());
-            if (userCashAccount == null) {
-                throw new BizException("用户账户不存在");
-            }
-            if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
-                balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
-                amount = amount.subtract(balance);
+        if (model.isUseBalance() && amount.compareTo(BigDecimal.ZERO) > 0 ) {
+            if (!StringUtils.isEmpty(model.getOldOrderNo())) {
                 studentPaymentOrder.setActualAmount(amount);
                 studentPaymentOrder.setBalancePaymentAmount(balance);
-                sysUserCashAccountService.updateBalance(model.getUserId(), balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "商品销售");
+            } else {
+                SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(model.getUserId());
+                if (userCashAccount == null) {
+                    throw new BizException("用户账户不存在");
+                }
+                if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
+                    balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
+                    amount = amount.subtract(balance);
+                    studentPaymentOrder.setActualAmount(amount);
+                    studentPaymentOrder.setBalancePaymentAmount(balance);
+                    sysUserCashAccountService.updateBalance(model.getUserId(), balance.negate(),
+                                                            PlatformCashAccountDetailTypeEnum.PAY_FEE, "商品销售");
+                }
             }
         }
         studentPaymentOrderService.update(studentPaymentOrder);