| 
					
				 | 
			
			
				@@ -85,6 +85,8 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private Map<ProductType, InitCheckout> initCheckoutCallback = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Map<ProductType, ChangeCheckout> changeCheckoutCallback = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private Map<ProductType, RemoveCheckout> removeCheckoutCallback = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private Map<ProductType, InitOrder> initOrderCallback = new HashMap<>(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -265,6 +267,25 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return checkout; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         })); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        changeCheckoutCallback.put(ProductType.COURSE, (checkout->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Course mainCourse = courseService.get(checkout.getProductId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 判断是否是1v1课程 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (mainCourse.getCourseModule().equals(CourseModule.VS.key)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                checkout.setOriginMoney(mainCourse.getPrice().multiply(BigDecimal.valueOf(checkout.getNumber()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                int percent = toolsService.computeVsMoney(checkout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                checkout.setMoney(checkout.getOriginMoney().multiply(BigDecimal.valueOf(percent)).divide(BigDecimal.valueOf(100), BigDecimal.ROUND_HALF_UP)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 设定有效期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                checkout.setExpireDays(mainCourse.getExpireDays()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                checkout.setUseExpireDays(courseExtendService.computeExpire(checkout.getNumber(), mainCourse)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return checkout; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 无法修改 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new ParameterException("记录无法修改"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        })); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         removeCheckoutCallback.put(ProductType.COURSE, ((checkout, userOrderCheckoutList)->{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 子项目不允许参数,则无需处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         })); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -510,6 +531,7 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if(record.getService().equals(ServiceKey.VIP.key)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 // VIP直接开通 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 record = useRecordCallback.get(ProductType.SERVICE).callback(record); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                record.setProductType(ProductType.SERVICE.key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ServiceKey serviceKey = ServiceKey.ValueOf(record.getService()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 Date startTime = new Date(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -694,7 +716,7 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         UserOrder userOrder = userOrderService.get(orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (userOrder == null) return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (userOrder.getPayStatus() > 0) return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        userOrder = userOrderService.edit(UserOrder.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userOrderService.edit(UserOrder.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .id(userOrder.getId()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .payId(payId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .payMethod(payMethod.key) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -702,7 +724,11 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .transactionNo(transactionNo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .payStatus(1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .build()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userOrder.setPayId(payId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userOrder.setPayMethod(payMethod.key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userOrder.setPayTime(payTime); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userOrder.setTransactionNo(transactionNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        userOrder.setPayStatus(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 转换购物车记录为购买记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<UserOrderCheckout> checkoutList = userOrderCheckoutService.allByUser(userId, orderId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<UserOrderCheckout> pList = checkoutList.stream().filter((checkout)-> checkout.getParentId() == 0).collect(Collectors.toList()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -775,9 +801,9 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<UserOrderCheckout> list = userOrderCheckoutService.allByUser(userId, 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         InitCheckout callback = initCheckoutCallback.get(ProductType.ValueOf(checkout.getProductType())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         checkout = callback.callback(checkout, list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (checkout == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (checkout == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             // 无需操作 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        }else if(checkout.getId() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else if(checkout.getId() != null && checkout.getId() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             userOrderCheckoutService.edit(checkout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             userOrderCheckoutService.add(checkout); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -788,6 +814,31 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 修改购物车 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param userId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param checkout 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public int changeCheckout(Integer userId, UserOrderCheckout checkout){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ChangeCheckout callback = changeCheckoutCallback.get(ProductType.ValueOf(checkout.getProductType())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (callback == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new ParameterException("无法修改记录"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        checkout = callback.callback(checkout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (checkout == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 无需操作 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userOrderCheckoutService.edit(checkout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 计算购物车数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return userOrderCheckoutService.allByUser(userId, 0).size(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 删除购物车 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param checkoutId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param userId 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -848,23 +899,26 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 课程: 并包含套餐 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<UserOrderCheckout> courseCheckout = list.stream().filter((checkout)-> checkout.getProductType().equals(ProductType.COURSE.key) || checkout.getProductType().equals(ProductType.COURSE_PACKAGE.key)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        callback = initOrderCallback.get(ProductType.COURSE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        callback.callback(order, courseCheckout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(courseCheckout.size() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            callback = initOrderCallback.get(ProductType.COURSE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            callback.callback(order, courseCheckout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             productTypes.add(ProductType.COURSE.key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 资料 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<UserOrderCheckout> dataCheckout = list.stream().filter((checkout)-> checkout.getProductType().equals(ProductType.DATA.key)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        callback = initOrderCallback.get(ProductType.DATA); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        callback.callback(order, courseCheckout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (dataCheckout.size() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            callback = initOrderCallback.get(ProductType.DATA); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            callback.callback(order, dataCheckout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             productTypes.add(ProductType.DATA.key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 服务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<UserOrderCheckout> serviceCheckout = list.stream().filter((checkout)-> checkout.getProductType().equals(ProductType.SERVICE.key)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        callback = initOrderCallback.get(ProductType.SERVICE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        callback.callback(order, courseCheckout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(serviceCheckout.size() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            callback = initOrderCallback.get(ProductType.SERVICE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            callback.callback(order, serviceCheckout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             productTypes.add(ProductType.SERVICE.key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -903,12 +957,24 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public UserOrder makeOrderWithSpeed(Integer userId, UserOrderCheckout checkout){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<UserOrderCheckout> list = new ArrayList<UserOrderCheckout>(){{add(checkout);}}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<UserOrderCheckout> list = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        checkout.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        InitCheckout callback = initCheckoutCallback.get(ProductType.ValueOf(checkout.getProductType())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        checkout = callback.callback(checkout, list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (checkout == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new ParameterException("创建失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        list.add(checkout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         UserOrder order = preOrderWithCheckout(userId, list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         order.setIsSpeed(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         order = userOrderService.add(order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         checkout.setOrderId(order.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        userOrderCheckoutService.add(checkout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(checkout.getId() != null && checkout.getId() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userOrderCheckoutService.edit(checkout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            userOrderCheckoutService.add(checkout); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return order; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -968,6 +1034,7 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void giveInvite(Integer userId){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         UserOrderRecord record = UserOrderRecord.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .userId(userId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .productType(ProductType.SERVICE.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .service(ServiceKey.VIP.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .param(ServiceVipKey.DAY7.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .source(RecordSource.INVITE.key) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -986,6 +1053,7 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void givePrepare(Integer userId){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         UserOrderRecord record = UserOrderRecord.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .userId(userId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .productType(ProductType.SERVICE.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .service(ServiceKey.VIP.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .param(ServiceVipKey.DAY7.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .source(RecordSource.PREPARE.key) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1004,6 +1072,7 @@ public class OrderFlowService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void giveReal(Integer userId){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         UserOrderRecord record = UserOrderRecord.builder() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .userId(userId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .productType(ProductType.SERVICE.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .service(ServiceKey.VIP.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .param(ServiceVipKey.MONTH3.key) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .source(RecordSource.REAL.key) 
			 |