zouxuan 4 年之前
父节点
当前提交
e23a160f51
共有 1 个文件被更改,包括 28 次插入35 次删除
  1. 28 35
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

+ 28 - 35
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -130,8 +130,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         }
         studentDao.lockUser(studentId);
         SysUser student = sysUserFeignService.queryUserById(studentId);
-        String orderNo = idGeneratorService.generatorId("payment") + "";
-        studentGoodsSell.setOrderNo(orderNo);
         if(studentGoodsSell.getTeacherId() == null){
             //获取学员第一个教务老师
             studentGoodsSell.setTeacherId(musicGroupDao.getFirstEduTeacherId(studentGoodsSell.getUserId()));
@@ -164,9 +162,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
             MapUtil.populateMap(repairInfoMap, studentGoodsSell);
             return repairInfoMap;
         }
-
-//        List<Goods> goods = goodsService.findGoodsByIds(StringUtils.join(goodsIds,","));
-
+        String orderNo = idGeneratorService.generatorId("payment") + "";
         StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
         studentPaymentOrder.setUserId(studentId);
         studentPaymentOrder.setGroupType(GroupType.GOODS_SELL);
@@ -179,29 +175,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentPaymentOrder.setRoutingOrganId(student.getOrganId());
         studentPaymentOrderService.insert(studentPaymentOrder);
 
-        /*Map<Integer, List<Goods>> collect = goods.stream().collect(Collectors.groupingBy(Goods::getId));
-        List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
-        for (String id : goodsIds) {
-            Goods e = collect.get(id).get(0);
-            StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
-            studentPaymentOrderDetail.setRemitFee(BigDecimal.ZERO);
-            OrderDetailTypeEnum type = null;
-            if (e.getType() == GoodsType.INSTRUMENT) {
-                type = OrderDetailTypeEnum.MUSICAL;
-            } else if (e.getType() == GoodsType.ACCESSORIES) {
-                type = OrderDetailTypeEnum.ACCESSORIES;
-            } else if (e.getType() == GoodsType.OTHER) {
-                type = OrderDetailTypeEnum.TEACHING;
-            }
-            studentPaymentOrderDetail.setType(type);
-            studentPaymentOrderDetail.setPrice(e.getGroupPurchasePrice());
-            studentPaymentOrderDetail.setGoodsIdList(id);
-            studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
-            studentPaymentOrderDetail.setKitGroupPurchaseType(KitGroupPurchaseTypeEnum.GROUP);
-            studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
-        }
-        studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);*/
-
         studentPaymentOrder.setVersion(0);
         BigDecimal balance = BigDecimal.ZERO;
         if (studentGoodsSell.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
@@ -275,11 +248,31 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         if(amount.signum() < 0){
             throw new BizException("操作失败:订单金额异常");
         }
-
-        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
+        String orderNo1 = studentGoodsSell.getOrderNo();
+        String orderNo = idGeneratorService.generatorId("payment") + "";
+        studentGoodsSell.setOrderNo(orderNo);
+        StudentPaymentOrder studentPaymentOrder = null;
+        if(StringUtils.isNotEmpty(orderNo1)){
+            studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(orderNo1);
+            //关闭老订单
+            if(studentPaymentOrder.getBalancePaymentAmount() != null){
+                studentGoodsSell.setIsUseBalancePayment(true);
+            }else {
+                studentGoodsSell.setIsUseBalancePayment(false);
+            }
+            studentPaymentOrder.setStatus(DealStatusEnum.CLOSE);
+            studentPaymentOrderService.update(studentPaymentOrder);
+            if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
+                sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "关闭订单");
+            }
+            studentGoodsSellDao.insert(studentGoodsSell);
+        }else {
+            studentGoodsSellDao.update(studentGoodsSell);
+        }
+        studentPaymentOrder = new StudentPaymentOrder();
         studentPaymentOrder.setUserId(studentId);
         studentPaymentOrder.setGroupType(GroupType.GOODS_SELL);
-        studentPaymentOrder.setOrderNo(studentGoodsSell.getOrderNo());
+        studentPaymentOrder.setOrderNo(orderNo);
         studentPaymentOrder.setType(OrderTypeEnum.GOODS_SELL);
         studentPaymentOrder.setExpectAmount(amount);
         studentPaymentOrder.setActualAmount(amount);
@@ -307,12 +300,12 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
 
         if (amount.compareTo(BigDecimal.ZERO) == 0) {
-            studentPaymentRouteOrderService.addRouteOrder(studentGoodsSell.getOrderNo(), student.getOrganId(), balance);
+            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", studentGoodsSell.getOrderNo());
+            notifyMap.put("orderNo", orderNo);
             return notifyMap;
         }
 
@@ -321,9 +314,9 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
         Map payMap = payService.getPayMap(
                 amount,
                 balance,
-                studentGoodsSell.getOrderNo(),
+                orderNo,
                 baseApiUrl + "/api-student/studentOrder/notify",
-                baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + studentGoodsSell.getOrderNo(),
+                baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + orderNo,
                 "商品销售",
                 "商品销售",
                 student.getOrganId(),