|  | @@ -279,7 +279,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional
 | 
	
		
			
				|  |  | -    public StudentPaymentOrder addOrder(StudentRegistration studentRegistration, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, List<CourseFormDto> courseForms,BigDecimal remitFee,BigDecimal courseRemitFee) throws Exception {
 | 
	
		
			
				|  |  | +    public StudentPaymentOrder addOrder(StudentRegistration studentRegistration, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, List<CourseFormDto> courseForms, BigDecimal remitFee, BigDecimal courseRemitFee) throws Exception {
 | 
	
		
			
				|  |  |          Date date = new Date();
 | 
	
		
			
				|  |  |          StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  |          studentPaymentOrder.setUserId(studentRegistration.getUserId());
 | 
	
	
		
			
				|  | @@ -411,7 +411,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional
 | 
	
		
			
				|  |  | -    public StudentPaymentOrder reAddOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, String musicGroupId, StudentPaymentOrder oldOrder, List<CourseFormDto> courseForms,BigDecimal remitFee,BigDecimal courseRemitFee) {
 | 
	
		
			
				|  |  | +    public StudentPaymentOrder reAddOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, String musicGroupId, StudentPaymentOrder oldOrder, List<CourseFormDto> courseForms, BigDecimal remitFee, BigDecimal courseRemitFee) {
 | 
	
		
			
				|  |  |          //关闭老订单
 | 
	
		
			
				|  |  |          oldOrder.setStatus(DealStatusEnum.CLOSE);
 | 
	
		
			
				|  |  |          studentPaymentOrderService.update(oldOrder);
 | 
	
	
		
			
				|  | @@ -907,13 +907,16 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |                  //商品总付款
 | 
	
		
			
				|  |  |                  BigDecimal detailTotalPrice = orderDetails.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  |                  //商品销售占的余额
 | 
	
		
			
				|  |  | -                BigDecimal detailTotalBalance = detailTotalPrice.multiply(totalBalance).divide(totalPrice,2,BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | +                BigDecimal detailTotalBalance = detailTotalPrice.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                        detailTotalPrice.multiply(totalBalance).divide(totalPrice, 2, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  int i = 1;
 | 
	
		
			
				|  |  |                  BigDecimal detailRouteBalance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |                  for (StudentPaymentOrderDetail orderDetail : orderDetails) {
 | 
	
		
			
				|  |  | -                    BigDecimal detailBalance = orderDetail.getPrice().multiply(detailTotalBalance).divide(detailTotalPrice,2,BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -                    if(i == orderDetails.size()){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    BigDecimal detailBalance = orderDetail.getPrice().compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO :
 | 
	
		
			
				|  |  | +                            orderDetail.getPrice().multiply(detailTotalBalance).divide(detailTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | +                    if (i == orderDetails.size()) {
 | 
	
		
			
				|  |  |                          detailBalance = detailTotalBalance.subtract(detailRouteBalance);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                      detailRouteBalance = detailRouteBalance.add(detailBalance);
 | 
	
	
		
			
				|  | @@ -928,11 +931,15 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |                      BigDecimal routeBalance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  |                      int j = 1;
 | 
	
		
			
				|  |  |                      for (Goods goods : orderDetail.getGoodsList()) {
 | 
	
		
			
				|  |  | -                        BigDecimal expectAmount = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -                        BigDecimal balance = goods.getGroupPurchasePrice().multiply(detailBalance).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | -                        if(j==orderDetail.getGoodsList().size()){
 | 
	
		
			
				|  |  | -                            expectAmount  = orderDetail.getPrice().subtract(routePrice);
 | 
	
		
			
				|  |  | -                            balance  = orderDetail.getPrice().subtract(routeBalance);
 | 
	
		
			
				|  |  | +                        BigDecimal expectAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +                        BigDecimal balance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +                        if (goodsTotalPrice.compareTo(BigDecimal.ZERO) > 0) {
 | 
	
		
			
				|  |  | +                            expectAmount = goods.getGroupPurchasePrice().multiply(orderDetail.getPrice()).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | +                            balance = goods.getGroupPurchasePrice().multiply(detailBalance).divide(goodsTotalPrice, 2, BigDecimal.ROUND_HALF_UP);
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        if (j == orderDetail.getGoodsList().size()) {
 | 
	
		
			
				|  |  | +                            expectAmount = orderDetail.getPrice().subtract(routePrice);
 | 
	
		
			
				|  |  | +                            balance = orderDetail.getPrice().subtract(routeBalance);
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                          routePrice = routePrice.add(expectAmount);
 | 
	
		
			
				|  |  |                          routeBalance = routeBalance.add(balance);
 | 
	
	
		
			
				|  | @@ -940,9 +947,9 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                          SellOrder sellOrder = new SellOrder();
 | 
	
		
			
				|  |  |                          Map<String, BigDecimal> CostMap = new HashMap<>();
 | 
	
		
			
				|  |  | -                        CostMap.put("sellCost",goods.getDiscountPrice());
 | 
	
		
			
				|  |  | -                        if(goods.getAgreeCostPrice() != null){
 | 
	
		
			
				|  |  | -                            CostMap.put("SellCost2",goods.getAgreeCostPrice());
 | 
	
		
			
				|  |  | +                        CostMap.put("sellCost", goods.getDiscountPrice());
 | 
	
		
			
				|  |  | +                        if (goods.getAgreeCostPrice() != null) {
 | 
	
		
			
				|  |  | +                            CostMap.put("SellCost2", goods.getAgreeCostPrice());
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                          sellOrder.setOrganId(studentPaymentOrder.getOrganId());
 | 
	
		
			
				|  |  |                          sellOrder.setCooperationOrganId(musicGroup.getCooperationOrganId());
 |