|  | @@ -1,15 +1,13 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dao.HfMemberDao;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.MusicGroupDao;
 | 
	
		
			
				|  |  |  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.Group;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.SysAccount;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.dal.entity.SysPaymentConfig;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.entity.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.FeeTypeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.PaymentChannelTypeEnum;
 | 
	
	
		
			
				|  | @@ -45,6 +43,8 @@ public class PayServiceImpl implements PayService {
 | 
	
		
			
				|  |  |      private StudentPaymentRouteOrderDao studentPaymentRouteOrderDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SellOrderService sellOrderService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private HfMemberDao hfMemberDao;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public Map<String, Object> getPayMap(BigDecimal amount, BigDecimal balanceAmount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer organId, String receiver) throws Exception {
 | 
	
	
		
			
				|  | @@ -73,6 +73,11 @@ public class PayServiceImpl implements PayService {
 | 
	
		
			
				|  |  |              routeScaleDtos = getPaymentConfigChannel(organId, amount);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        //验证最大收款金额
 | 
	
		
			
				|  |  | +        for (RouteScaleDto routeScaleDto : routeScaleDtos) {
 | 
	
		
			
				|  |  | +            checkMaxReceipt(routeScaleDto, routeScaleDto.getMerNo());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return getPayRoute(amount, balanceAmount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, routeScaleDtos);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -290,6 +295,24 @@ public class PayServiceImpl implements PayService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private Map<String, Object> getPayRoute(BigDecimal amount, BigDecimal balanceAmount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, List<RouteScaleDto> routeScaleDtos) throws Exception {
 | 
	
		
			
				|  |  | +        Map<String, List<RouteScaleDto>> routeScaleDtosMap = routeScaleDtos.stream().collect(Collectors.groupingBy(RouteScaleDto::getMerNo));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //合并同账号的数据
 | 
	
		
			
				|  |  | +        List<RouteScaleDto> newRouteScaleDtos = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (Map.Entry<String, List<RouteScaleDto>> groupRouteScaleDtos : routeScaleDtosMap.entrySet()) {
 | 
	
		
			
				|  |  | +            RouteScaleDto routeScaleDto = null;
 | 
	
		
			
				|  |  | +            for (RouteScaleDto scaleDto : groupRouteScaleDtos.getValue()) {
 | 
	
		
			
				|  |  | +                if (routeScaleDto == null) {
 | 
	
		
			
				|  |  | +                    routeScaleDto = scaleDto;
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    routeScaleDto.setAmount(routeScaleDto.getAmount().add(scaleDto.getAmount()));
 | 
	
		
			
				|  |  | +                    routeScaleDto.setBalance(routeScaleDto.getBalance().add(scaleDto.getBalance()));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            newRouteScaleDtos.add(routeScaleDto);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        routeScaleDtos = newRouteScaleDtos;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          Map<String, Object> unionPay = new HashMap<>();
 | 
	
		
			
				|  |  |          Map<String, Object> payMap = null;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -498,4 +521,38 @@ public class PayServiceImpl implements PayService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return newRouteScaleDtos;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 收款已满转到其他收款账户
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param routeScaleDto
 | 
	
		
			
				|  |  | +     * @param merNo
 | 
	
		
			
				|  |  | +     * @return
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private RouteScaleDto checkMaxReceipt(RouteScaleDto routeScaleDto, String merNo) {
 | 
	
		
			
				|  |  | +        HfMember hfmember = hfMemberDao.getByMemberId(routeScaleDto.getMerNo());
 | 
	
		
			
				|  |  | +        if (hfmember == null || hfmember.getMonthMaxReceipt().compareTo(BigDecimal.ZERO) <= 0) {
 | 
	
		
			
				|  |  | +            return routeScaleDto;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        BigDecimal monthMaxReceipt = hfmember.getMonthMaxReceipt(); //每月限定金额
 | 
	
		
			
				|  |  | +        Date monthStartTime = DateUtil.getFirstDayOfMonth(new Date());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //已收金额
 | 
	
		
			
				|  |  | +        List<PaymentChannelEnum> paymentChannelList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        paymentChannelList.add(PaymentChannelEnum.ADAPAY);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        BigDecimal monthHasReceipt = studentPaymentRouteOrderDao.getRouteOrderAmount(routeScaleDto.getOrganId(), paymentChannelList, monthStartTime);
 | 
	
		
			
				|  |  | +        monthHasReceipt = monthHasReceipt == null ? BigDecimal.ZERO : monthHasReceipt;
 | 
	
		
			
				|  |  | +        if (routeScaleDto.getAmount().add(monthHasReceipt).compareTo(monthMaxReceipt) > 0) {
 | 
	
		
			
				|  |  | +            routeScaleDto.setMerNo(hfmember.getRouteMemberId());
 | 
	
		
			
				|  |  | +            routeScaleDto.setOrganId(hfmember.getRouteOrganId());
 | 
	
		
			
				|  |  | +            if (routeScaleDto.getMerNo().equals(merNo)) {
 | 
	
		
			
				|  |  | +                return routeScaleDto;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return checkMaxReceipt(routeScaleDto, merNo);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return routeScaleDto;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |