|  | @@ -9,7 +9,6 @@ import java.util.HashSet;
 | 
	
		
			
				|  |  |  import java.util.Iterator;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  |  import java.util.Map;
 | 
	
		
			
				|  |  | -import java.util.Objects;
 | 
	
		
			
				|  |  |  import java.util.Set;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -23,16 +22,20 @@ import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.SysConfigDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.AmountChannelDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.RouteScaleDto;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.Goods;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.HfMember;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.SysConfig;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.SysPaymentConfig;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.FeeTypeEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.service.GoodsService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.PayService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.SellOrderService;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.StudentPaymentOrderService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.SysConfigService;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.SysPaymentConfigService;
 | 
	
	
		
			
				|  | @@ -50,6 +53,13 @@ import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  |  public class PayServiceImpl implements PayService {
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private StudentPaymentOrderService studentPaymentOrderService;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private GoodsService goodsService;
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysConfigDao sysConfigDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
	
		
			
				|  | @@ -111,6 +121,8 @@ public class PayServiceImpl implements PayService {
 | 
	
		
			
				|  |  |              return unionPay;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | +		Date date = new Date();
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  |          //如果当前是买的小课/网管课
 | 
	
		
			
				|  |  |  		if (studentPaymentOrder != null && studentPaymentOrder.getType() == OrderTypeEnum.SMALL_CLASS_TO_BUY || studentPaymentOrder.getType() == OrderTypeEnum.PRACTICE_GROUP_BUY
 | 
	
		
			
				|  |  |  				|| studentPaymentOrder.getType() == OrderTypeEnum.PRACTICE_GROUP_RENEW) {
 | 
	
	
		
			
				|  | @@ -122,7 +134,6 @@ public class PayServiceImpl implements PayService {
 | 
	
		
			
				|  |  |  			String isPlatformCollection = sysConfigDao.findConfigValue(SysConfigService.IS_OPEN_SMALL_CLASS_INCOME_TO_PLATFORM);
 | 
	
		
			
				|  |  |  			
 | 
	
		
			
				|  |  |  			if (StringUtils.equals("1", isPlatformCollection) && !ignoreOrganList.contains(organId)) {
 | 
	
		
			
				|  |  | -				Date date = new Date();
 | 
	
		
			
				|  |  |  	        	
 | 
	
		
			
				|  |  |  	        	String merNo = sysConfigDao.findConfigValue(SysConfigService.PLATFORM_PAYEE_ACCOUNT);
 | 
	
		
			
				|  |  |  	        	
 | 
	
	
		
			
				|  | @@ -158,12 +169,125 @@ public class PayServiceImpl implements PayService {
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  			
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		BigDecimal subBalance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +		
 | 
	
		
			
				|  |  | +		BigDecimal subCashAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +    	//忽略的分部
 | 
	
		
			
				|  |  | +		List<Integer> ignoreOrganList = Arrays.asList(4, 55, 59);
 | 
	
		
			
				|  |  | +		
 | 
	
		
			
				|  |  | +		//查询商品收款账户配置
 | 
	
		
			
				|  |  | +        String goodsSellReceiptMerNo = sysConfigDao.findConfigValue("goodsSellReceiptMerNo");
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        if(!ignoreOrganList.contains(organId) && StringUtils.isNotBlank(goodsSellReceiptMerNo)){
 | 
	
		
			
				|  |  | +			
 | 
	
		
			
				|  |  | +        	//根据商户号查询对应分部
 | 
	
		
			
				|  |  | +        	SysPaymentConfig sysPaymentConfig = sysPaymentConfigService.findPaymentConfigByMerNo(StringUtils.trim(goodsSellReceiptMerNo));
 | 
	
		
			
				|  |  | +        	
 | 
	
		
			
				|  |  | +        	if(sysPaymentConfig != null){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    			List<StudentPaymentOrderDetail> batchUpdateList = new ArrayList<StudentPaymentOrderDetail>();
 | 
	
		
			
				|  |  | +        		
 | 
	
		
			
				|  |  | +        		// 如果买了商品或组合商品,商品有内部库存,则将钱转入指定账户已云教练的方式作为收费项目(杭州、齐齐哈尔除外)
 | 
	
		
			
				|  |  | +        		// 1.查询商品订单明细
 | 
	
		
			
				|  |  | +        		List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
 | 
	
		
			
				|  |  | +        		if (studentPaymentOrderDetailList != null && studentPaymentOrderDetailList.size() > 0) {
 | 
	
		
			
				|  |  | +        			
 | 
	
		
			
				|  |  | +        			String goodIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getGoodsIdList())).map(StudentPaymentOrderDetail :: getGoodsIdList).collect(Collectors.joining(","));
 | 
	
		
			
				|  |  | +        			if(StringUtils.isNotBlank(goodIds)){
 | 
	
		
			
				|  |  | +        				List<Goods> goodsList = goodsService.findGoodsByIds(goodIds);
 | 
	
		
			
				|  |  | +        				
 | 
	
		
			
				|  |  | +        				Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
 | 
	
		
			
				|  |  | +        				Goods goods = null;
 | 
	
		
			
				|  |  | +        				BigDecimal totalAmout = studentPaymentOrder.getExpectAmount();
 | 
	
		
			
				|  |  | +        				
 | 
	
		
			
				|  |  | +        				for(StudentPaymentOrderDetail spod : studentPaymentOrderDetailList){
 | 
	
		
			
				|  |  | +        					
 | 
	
		
			
				|  |  | +        					if(StringUtils.isBlank(spod.getGoodsIdList())){
 | 
	
		
			
				|  |  | +        						continue;
 | 
	
		
			
				|  |  | +        					}
 | 
	
		
			
				|  |  | +        					BigDecimal tempBalance = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +        					
 | 
	
		
			
				|  |  | +        					BigDecimal tempCashAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +        					
 | 
	
		
			
				|  |  | +        					BigDecimal totalGroupPurchaseAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +        					
 | 
	
		
			
				|  |  | +        					BigDecimal groupPurchaseAmount = BigDecimal.ZERO;
 | 
	
		
			
				|  |  | +        					
 | 
	
		
			
				|  |  | +        					for(String goodsIdStr : spod.getGoodsIdList().split(",")){
 | 
	
		
			
				|  |  | +        						if(StringUtils.isBlank(goodsIdStr)){
 | 
	
		
			
				|  |  | +        							continue;
 | 
	
		
			
				|  |  | +        						}
 | 
	
		
			
				|  |  | +        						goods = goodsMap.get(Integer.parseInt(goodsIdStr));
 | 
	
		
			
				|  |  | +        						
 | 
	
		
			
				|  |  | +        						if(goods != null){
 | 
	
		
			
				|  |  | +        							// 是否是组合商品
 | 
	
		
			
				|  |  | +        							if(StringUtils.isNotBlank(goods.getComplementGoodsIdList())){
 | 
	
		
			
				|  |  | +        								goodsList = goodsService.findGoodsByIds(goods.getComplementGoodsIdList());
 | 
	
		
			
				|  |  | +        								totalGroupPurchaseAmount =  totalGroupPurchaseAmount.add(goodsList.stream().map(Goods :: getGroupPurchasePrice).reduce(BigDecimal.ZERO,BigDecimal :: add));
 | 
	
		
			
				|  |  | +        								
 | 
	
		
			
				|  |  | +        								for(Goods subGoods : goodsList){
 | 
	
		
			
				|  |  | +        									//判断是否有内部库存
 | 
	
		
			
				|  |  | +        									if(subGoods.getStockCount() > 0){
 | 
	
		
			
				|  |  | +        										groupPurchaseAmount = groupPurchaseAmount.add(subGoods.getGroupPurchasePrice());
 | 
	
		
			
				|  |  | +        									}
 | 
	
		
			
				|  |  | +        								}
 | 
	
		
			
				|  |  | +        							}else{
 | 
	
		
			
				|  |  | +    									totalGroupPurchaseAmount = totalGroupPurchaseAmount.add(goods.getGroupPurchasePrice());
 | 
	
		
			
				|  |  | +        								//判断是否有内部库存
 | 
	
		
			
				|  |  | +        								if(goods.getStockCount() > 0){
 | 
	
		
			
				|  |  | +    										groupPurchaseAmount = groupPurchaseAmount.add(goods.getGroupPurchasePrice());
 | 
	
		
			
				|  |  | +        								}
 | 
	
		
			
				|  |  | +        							}
 | 
	
		
			
				|  |  | +        						}
 | 
	
		
			
				|  |  | +        					}
 | 
	
		
			
				|  |  | +        					
 | 
	
		
			
				|  |  | +							if (groupPurchaseAmount.doubleValue() > 0) {
 | 
	
		
			
				|  |  | +	        					// 3.是否使用余额
 | 
	
		
			
				|  |  | +								if (balanceAmount.doubleValue() > 0) {
 | 
	
		
			
				|  |  | +									tempBalance = balanceAmount.multiply(spod.getPrice()).divide(totalAmout).multiply(groupPurchaseAmount)
 | 
	
		
			
				|  |  | +											.divide(totalGroupPurchaseAmount);
 | 
	
		
			
				|  |  | +									subBalance = subBalance.add(tempBalance);
 | 
	
		
			
				|  |  | +								}
 | 
	
		
			
				|  |  | +								tempCashAmount = spod.getPrice().subtract(tempBalance).multiply(groupPurchaseAmount).divide(totalGroupPurchaseAmount);
 | 
	
		
			
				|  |  | +								subCashAmount = subCashAmount.add(spod.getPrice().subtract(tempBalance).subtract(tempCashAmount));
 | 
	
		
			
				|  |  | +								spod.setIncomeItem(OrderDetailTypeEnum.CLOUD_TEACHER.name());
 | 
	
		
			
				|  |  | +								spod.setIncome(tempCashAmount);
 | 
	
		
			
				|  |  | +								batchUpdateList.add(spod);
 | 
	
		
			
				|  |  | +							}
 | 
	
		
			
				|  |  | +        				}
 | 
	
		
			
				|  |  | +        			}
 | 
	
		
			
				|  |  | +        		}
 | 
	
		
			
				|  |  | +        		
 | 
	
		
			
				|  |  | +        		if(batchUpdateList.size() > 0){
 | 
	
		
			
				|  |  | +        			studentPaymentOrderDetailService.batchUpdate(batchUpdateList);
 | 
	
		
			
				|  |  | +        		}
 | 
	
		
			
				|  |  | +        		
 | 
	
		
			
				|  |  | +        		if(subCashAmount.doubleValue() > 0){
 | 
	
		
			
				|  |  | +        			StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setRouteOrganId(sysPaymentConfig.getOrganId());
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setFeeFlag("Y");
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setRouteAmount(subCashAmount);
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setRouteBalanceAmount(subBalance);
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setMerNo(goodsSellReceiptMerNo);
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setSaleAmount(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setServiceAmount(amount);
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setCreateTime(date);
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrder.setUpdateTime(date);
 | 
	
		
			
				|  |  | +    	            studentPaymentRouteOrderDao.insert(studentPaymentRouteOrder);
 | 
	
		
			
				|  |  | +        		}
 | 
	
		
			
				|  |  | +        	}
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +		
 | 
	
		
			
				|  |  | +		amount = amount.subtract(subCashAmount);
 | 
	
		
			
				|  |  | +		balanceAmount = balanceAmount.subtract(subBalance);
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          String usePaymentConfig = sysConfigDao.findConfigValue("use_payment_config");// 是否用收费配置(1:使用 0:不使用)
 | 
	
		
			
				|  |  |          List<RouteScaleDto> routeScaleDtos = null;
 | 
	
		
			
				|  |  |          //使用配置开关
 | 
	
		
			
				|  |  |          if (usePaymentConfig.equals("0")) {
 | 
	
		
			
				|  |  | -            routeScaleDtos = noUsePaymentConfig(amount);
 | 
	
		
			
				|  |  | +            routeScaleDtos = noUsePaymentConfig(amount); //款项都收到平台商户
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //根据费用类型
 |