zouxuan преди 1 година
родител
ревизия
e5a0d36daf
променени са 1 файла, в които са добавени 55 реда и са изтрити 48 реда
  1. 55 48
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

+ 55 - 48
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -352,6 +352,58 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentPaymentOrder.setTenantId(student.getTenantId());
         studentPaymentOrderService.insert(studentPaymentOrder);
 
+        this.initStudentPaymentOrderDetail(studentPaymentOrder, goodsSellDtos);
+
+        studentPaymentOrder.setVersion(0);
+        BigDecimal balance = BigDecimal.ZERO;
+        if (studentGoodsSell.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
+            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(studentId);
+            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);
+                studentPaymentOrder.setPaymentChannel("BALANCE");
+                sysUserCashAccountService.updateBalance(studentId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "商品销售");
+            }
+        }
+        studentPaymentOrderService.update(studentPaymentOrder);
+        studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
+
+        if (amount.compareTo(BigDecimal.ZERO) == 0) {
+            studentPaymentRouteOrderService.addRouteOrder(orderNo, student.getOrganId(), balance);
+            Map<String, String> notifyMap = new HashMap<>();
+            notifyMap.put("tradeState", "1");
+            notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
+            studentPaymentOrderService.updateOrder(notifyMap);
+            notifyMap.put("orderNo", orderNo);
+            return notifyMap;
+        }
+
+        String baseApiUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
+
+        Map payMap = payService.getPayMap(
+                amount,
+                balance,
+                orderNo,
+                baseApiUrl + "/api-student/studentOrder/callback/" + orderNo,
+                baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + orderNo,
+                "商品销售",
+                "商品销售",
+                student.getOrganId(),
+                "goodsSell"
+        );
+
+        studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
+        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
+        studentPaymentOrderService.update(studentPaymentOrder);
+        return payMap;
+    }
+
+    public List<StudentPaymentOrderDetail> initStudentPaymentOrderDetail(StudentPaymentOrder studentPaymentOrder, List<GoodsSellDto> goodsSellDtos){
         Date date = new Date();
         //添加订单详情
         List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
@@ -423,54 +475,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         if (studentPaymentOrderDetailList.size() > 0) {
             studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
         }
-
-        studentPaymentOrder.setVersion(0);
-        BigDecimal balance = BigDecimal.ZERO;
-        if (studentGoodsSell.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
-            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(studentId);
-            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);
-                studentPaymentOrder.setPaymentChannel("BALANCE");
-                sysUserCashAccountService.updateBalance(studentId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "商品销售");
-            }
-        }
-        studentPaymentOrderService.update(studentPaymentOrder);
-        studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
-
-        if (amount.compareTo(BigDecimal.ZERO) == 0) {
-            studentPaymentRouteOrderService.addRouteOrder(orderNo, student.getOrganId(), balance);
-            Map<String, String> notifyMap = new HashMap<>();
-            notifyMap.put("tradeState", "1");
-            notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
-            studentPaymentOrderService.updateOrder(notifyMap);
-            notifyMap.put("orderNo", orderNo);
-            return notifyMap;
-        }
-
-        String baseApiUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
-
-        Map payMap = payService.getPayMap(
-                amount,
-                balance,
-                orderNo,
-                baseApiUrl + "/api-student/studentOrder/callback/" + orderNo,
-                baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + orderNo,
-                "商品销售",
-                "商品销售",
-                student.getOrganId(),
-                "goodsSell"
-        );
-
-        studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
-        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
-        studentPaymentOrderService.update(studentPaymentOrder);
-        return payMap;
+        return studentPaymentOrderDetailList;
     }
 
     @Override
@@ -544,6 +549,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentPaymentOrder.setTenantId(studentGoodsSell.getTenantId());
         studentPaymentOrderService.insert(studentPaymentOrder);
 
+        this.initStudentPaymentOrderDetail(studentPaymentOrder, goodsSellDtos);
+
         studentPaymentOrder.setVersion(0);
         BigDecimal balance = BigDecimal.ZERO;
         if (studentGoodsSell.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {