| 
					
				 | 
			
			
				@@ -662,16 +662,44 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //开始计算商品的优惠券 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (Objects.nonNull(couponPayParam) && Objects.nonNull(couponPayParam.getCouponTypeInfo())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //如果买乐器送课,那么就是0元买课,那么就先剔除送的课程再算优惠券,但是写入数据流水要加上 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<StudentPaymentOrderDetail> collect = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //按OrderDetailTypeEnum类型 进行聚合分组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Map<OrderDetailTypeEnum, List<StudentPaymentOrderDetail>> orderDetailGroupList = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    WrapperUtil.groupList(studentPaymentOrderDetailList, StudentPaymentOrderDetail::getType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<OrderDetailTypeEnum, List<StudentPaymentOrderDetail>> orderDetailGroupList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal freeNewCourse = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //如果送课 并且 课程不为空,那么就是0元买课 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (goodsDto.isRemitCourseRFeeFlag() && CollectionUtils.isNotEmpty(newCourses)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<String> newCourseType = newCourses.stream().map(a -> a.getCourseType().getCode()).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //获取剔除送的课程的订单明细 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                collect = studentPaymentOrderDetailList.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .filter(a -> !newCourseType.contains(a.getType().getCode())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //得到送课的减免的总额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                freeNewCourse = studentPaymentOrderDetailList.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .filter(a -> newCourseType.contains(a.getType().getCode())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .map(StudentPaymentOrderDetail::getRemitFee) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .reduce(BigDecimal.ZERO, BigDecimal::add); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                orderDetailGroupList = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        WrapperUtil.groupList(collect, StudentPaymentOrderDetail::getType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                orderDetailGroupList = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        WrapperUtil.groupList(studentPaymentOrderDetailList, StudentPaymentOrderDetail::getType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //获取本次交易中各优惠券的使用信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Map<String, CouponPayTypeInfo> couponParam = couponPayParam.getCouponTypeInfo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //计算使用优惠券后的对应的商品应该均摊的金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             calculateCoupon(couponParam, orderDetailGroupList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //获取使用了优惠券之后的总金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             BigDecimal useCouponAmount = WrapperUtil.sumList(studentPaymentOrderDetailList, StudentPaymentOrderDetail::getRemitFee); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            studentPaymentOrder.setCouponRemitFee(useCouponAmount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //赋值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Objects.isNull(studentPaymentOrder.getRemitFee())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentPaymentOrder.setRemitFee(freeNewCourse); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentPaymentOrder.setRemitFee(studentPaymentOrder.getRemitFee().add(freeNewCourse)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //优惠券减免金额应该是要减去 送课金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrder.setCouponRemitFee(useCouponAmount.subtract(freeNewCourse)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //核销优惠券 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             sysCouponCodeService.useCoupon(registerPayDto.getCouponIdList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 |