|  | @@ -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()));
 | 
	
	
		
			
				|  | @@ -157,6 +155,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |          studentGoodsSell.setOrganId(student.getOrganId());
 | 
	
		
			
				|  |  |          studentGoodsSell.setTotalAmount(amount);
 | 
	
		
			
				|  |  |          studentGoodsSell.setGoodsJson(JSONObject.toJSONString(goodsSellDtos));
 | 
	
		
			
				|  |  | +        String orderNo = idGeneratorService.generatorId("payment") + "";
 | 
	
		
			
				|  |  | +        studentGoodsSell.setOrderNo(orderNo);
 | 
	
		
			
				|  |  |          studentGoodsSellDao.insert(studentGoodsSell);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if (studentGoodsSell.getType() == 1) {
 | 
	
	
		
			
				|  | @@ -165,8 +165,6 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |              return repairInfoMap;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -//        List<Goods> goods = goodsService.findGoodsByIds(StringUtils.join(goodsIds,","));
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  |          studentPaymentOrder.setUserId(studentId);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setGroupType(GroupType.GOODS_SELL);
 | 
	
	
		
			
				|  | @@ -179,29 +177,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) {
 | 
	
	
		
			
				|  | @@ -256,7 +231,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |          StudentGoodsSell studentGoodsSell = studentGoodsSellDao.get(goodsSellId);
 | 
	
		
			
				|  |  |          Integer studentId = studentGoodsSell.getUserId();
 | 
	
		
			
				|  |  |          studentDao.lockUser(studentId);
 | 
	
		
			
				|  |  | -        SysUser student = sysUserFeignService.queryUserById(studentId);
 | 
	
		
			
				|  |  | +//        SysUser student = sysUserFeignService.queryUserById(studentId);
 | 
	
		
			
				|  |  |          List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(studentGoodsSell.getGoodsJson(),GoodsSellDto.class);
 | 
	
		
			
				|  |  |          List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -275,17 +250,39 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |          if(amount.signum() < 0){
 | 
	
		
			
				|  |  |              throw new BizException("操作失败:订单金额异常");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        String orderNo1 = studentGoodsSell.getOrderNo();
 | 
	
		
			
				|  |  | +        String orderNo = idGeneratorService.generatorId("payment") + "";
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  | +        studentGoodsSell.setOrderNo(orderNo);
 | 
	
		
			
				|  |  | +        StudentPaymentOrder studentPaymentOrder = null;
 | 
	
		
			
				|  |  | +        if(StringUtils.isNotEmpty(orderNo1)){
 | 
	
		
			
				|  |  | +            studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(orderNo1);
 | 
	
		
			
				|  |  | +            if(studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS){
 | 
	
		
			
				|  |  | +                throw new BizException("该订单已支付");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //关闭老订单
 | 
	
		
			
				|  |  | +            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.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);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setOrganId(student.getOrganId());
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setRoutingOrganId(student.getOrganId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setOrganId(studentGoodsSell.getOrganId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setRoutingOrganId(studentGoodsSell.getOrganId());
 | 
	
		
			
				|  |  |          studentPaymentOrderService.insert(studentPaymentOrder);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          studentPaymentOrder.setVersion(0);
 | 
	
	
		
			
				|  | @@ -307,12 +304,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, studentGoodsSell.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,12 +318,12 @@ 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(),
 | 
	
		
			
				|  |  | +                studentGoodsSell.getOrganId(),
 | 
	
		
			
				|  |  |                  "goodsSell"
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -648,6 +645,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |          map.put(userId, userId.toString());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +                contractService.transferProduceContract(userId, null);
 | 
	
		
			
				|  |  | +            } catch (Exception e) {
 | 
	
		
			
				|  |  | +                logger.error("产品协议生成失败", e);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              //插入交易明细
 | 
	
		
			
				|  |  |              BigDecimal amount = studentPaymentOrder.getActualAmount();
 | 
	
		
			
				|  |  |              SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
 |