yonge 3 éve
szülő
commit
9c9e242390

+ 33 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/PayService.java

@@ -1,26 +1,44 @@
 package com.ym.mec.biz.service;
 
-
 import java.math.BigDecimal;
 import java.util.Map;
 
+import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
+
 /**
  * 支付服务类
  */
 
 public interface PayService {
-    /**
-     *
-     * @param amount 支付金额
-     * @param orderNo 订单编号
-     * @param notifyUrl 回调地址
-     * @param returnUrl 返回地址
-     * @param orderSubject 订单主题
-     * @param orderBody 订单内容
-     * @param organId 分部编号
-     * @param receiver 指定接收
-     * @return
-     * @throws Exception
-     */
-    Map<String, Object> getPayMap(BigDecimal amount,BigDecimal balanceAmount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody,Integer organId,String receiver) throws Exception;
+	/**
+	*
+	* @param amount 支付金额
+	* @param orderNo 订单编号
+	* @param notifyUrl 回调地址
+	* @param returnUrl 返回地址
+	* @param orderSubject 订单主题
+	* @param orderBody 订单内容
+	* @param organId 分部编号
+	* @param receiver 指定接收
+	* @return
+	* @throws Exception
+	*/
+	Map<String, Object> getPayMap(BigDecimal amount, BigDecimal balanceAmount, String orderNo, String notifyUrl, String returnUrl, String orderSubject,
+			String orderBody, Integer organId, String receiver) throws Exception;
+
+	/**
+	 *
+	 * @param paymentChannel 支付渠道
+	 * @param payeeMerNo 收款商户号
+	 * @param amount 支付金额
+	 * @param orderNo 订单编号
+	 * @param notifyUrl 回调地址
+	 * @param returnUrl 返回地址
+	 * @param orderSubject 订单主题
+	 * @param orderBody 订单内容
+	 * @return
+	 * @throws Exception
+	 */
+	Map<String, Object> getPayToPlatformMap(PaymentChannelEnum paymentChannel, String payeeMerNo, BigDecimal amount, BigDecimal balanceAmount, String orderNo,
+			String notifyUrl, String returnUrl, String orderSubject, String orderBody) throws Exception;
 }

+ 21 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ContractServiceImpl.java

@@ -111,6 +111,9 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
     
     @Autowired
     private TenantInfoService tenantInfoService;
+    
+    @Autowired
+    private TenantConfigService tenantConfigService;
 
     @Value("${contract.baseDir:/var/pdf}")
     private String contractBaseDir;
@@ -914,8 +917,13 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 			throw new BizException("机构信息不存在");
 		}
 		
+		TenantConfig tenantConfig = tenantConfigService.queryByTenantId(studentInfo.getTenantId());
+		if(tenantConfig == null){
+			throw new BizException("机构配置信息查询失败");
+		}
+		
 		params.put("compayName", tenantInfo.getName());
-		params.put("sealPicture", "");
+		params.put("sealPicture", tenantConfig.getCorporateChops());
         
 		if (studentInfo.getTenantId() == 1) {
 			if (OwnershipType.OWN.name().equals(params.get("ownershipType"))) {
@@ -1035,8 +1043,13 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 			throw new BizException("机构信息不存在");
 		}
 		
+		TenantConfig tenantConfig = tenantConfigService.queryByTenantId(studentInfo.getTenantId());
+		if(tenantConfig == null){
+			throw new BizException("机构配置信息查询失败");
+		}
+		
 		params.put("compayName", tenantInfo.getName());
-		params.put("sealPicture", "");
+		params.put("sealPicture", tenantConfig.getCorporateChops());
         
 		if (studentInfo.getTenantId() == 1) {
 			if (OwnershipType.OWN.name().equals(params.get("ownershipType"))) {
@@ -1124,8 +1137,13 @@ public class ContractServiceImpl implements ContractService, InitializingBean {
 			throw new BizException("机构信息不存在");
 		}
 		
+		TenantConfig tenantConfig = tenantConfigService.queryByTenantId(studentInfo.getTenantId());
+		if(tenantConfig == null){
+			throw new BizException("机构配置信息查询失败");
+		}
+		
 		params.put("compayName", tenantInfo.getName());
-		params.put("sealPicture", "");
+		params.put("sealPicture", tenantConfig.getCorporateChops());
         
 		if (studentInfo.getTenantId() == 1) {
 			if (OwnershipType.OWN.name().equals(params.get("ownershipType"))) {

+ 35 - 13
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrderPayOpsServiceImpl.java

@@ -3,6 +3,8 @@ package com.ym.mec.biz.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.entity.SysConfig;
+import com.ym.mec.biz.dal.entity.SysPaymentConfig;
 import com.ym.mec.biz.dal.entity.TenantConfig;
 import com.ym.mec.biz.dal.entity.TenantOrderRecord;
 import com.ym.mec.biz.dal.entity.TenantPaymentOrder;
@@ -15,6 +17,8 @@ import com.ym.mec.thirdparty.adapay.Payment;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
 import com.ym.mec.util.json.JsonUtil;
+
+import org.apache.commons.lang3.StringUtils;
 import org.redisson.api.RBucket;
 import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
@@ -53,6 +57,12 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
     private CloudTeacherOrderService cloudTeacherOrderService;
     @Autowired
     private TenantConfigService tenantConfigService;
+    
+    @Autowired
+    private SysConfigService sysConfigService;
+    
+    @Autowired
+    private SysPaymentConfigService sysPaymentConfigService;
 
     //支付类型
     private static final Map<String, Function<PaymentParam, Map<String, Object>>> checkOrderType = new HashMap<>();
@@ -295,33 +305,45 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
                 StudentPaymentOrder st = (StudentPaymentOrder) clazz;
                 merNos = st.getMerNos();
                 amount = amountTo.apply(st.getActualAmount());
-
+		        
+				List<Map<String, Object>> divMemberList = new ArrayList<>();
                 // 实时分账
     			if (amount.doubleValue() > 0) {
-    				List<Map<String, Object>> divMemberList = new ArrayList<>();
+    				
+    				SysConfig config = sysConfigService.findByParamName("platform_collection_organ");
+    		        if (Objects.isNull(config)) {
+    		            throw new BizException("平台收款账户没有设置[platform_collection_organ]");
+    		        }
+    	        	
+    	        	SysPaymentConfig sysPaymentConfig = sysPaymentConfigService.findPaymentConfigByOrganId(Integer.parseInt(config.getParanValue()));
+    	        	
+    	        	if(sysPaymentConfig == null || StringUtils.isBlank(sysPaymentConfig.getHfMerNo())){
+    	        		throw new BizException("分部[{}]没有设置收款账号", config.getParanValue());
+    	        	}
+    	        	
     				Map<String, Object> divMember = new HashMap<>();
-    				divMember.put("member_id", merNos);
+    				divMember.put("member_id", sysPaymentConfig.getHfMerNo());
     				divMember.put("amount", amount);
     				divMember.put("fee_flag", "Y");
     				divMemberList.add(divMember);
-
-    				Map<String, Object> divMember1 = new HashMap<>();
-    				divMember1.put("member_id", merNos);
-    				divMember1.put("amount", payParam.getAmount().subtract(amount));
-    				divMember1.put("fee_flag", "N");
-    				divMemberList.add(divMember1);
-    				
-    				paymentParams.put("div_members", JsonUtil.toJSONString(divMemberList));
     			}
+
+				Map<String, Object> divMember1 = new HashMap<>();
+				divMember1.put("member_id", merNos);
+				divMember1.put("amount", payParam.getAmount().subtract(amount));
+				divMember1.put("fee_flag", "N");
+				divMemberList.add(divMember1);
+				
+				paymentParams.put("div_members", JsonUtil.toJSONString(divMemberList));
+				
             } else if (clazz instanceof TenantOrderRecord) {//向平台支付,不分账
                 TenantOrderRecord tor = (TenantOrderRecord) clazz;
                 merNos = tor.getMerNos();
-                amount = amountTo.apply(tor.getActualAmount());
                 
                 List<Map<String, Object>> divMemberList = new ArrayList<>();
 				Map<String, Object> divMember = new HashMap<>();
 				divMember.put("member_id", merNos);
-				divMember.put("amount", amount);
+				divMember.put("amount", tor.getActualAmount());
 				divMember.put("fee_flag", "Y");
 				divMemberList.add(divMember);
 

+ 92 - 14
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java

@@ -1,31 +1,42 @@
 package com.ym.mec.biz.service.impl;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
 import com.alibaba.fastjson.JSON;
 import com.ym.mec.biz.dal.dao.HfMemberDao;
 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.*;
+import com.ym.mec.biz.dal.entity.HfMember;
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
+import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
+import com.ym.mec.biz.dal.entity.SysPaymentConfig;
 import com.ym.mec.biz.dal.enums.FeeTypeEnum;
 import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
-import com.ym.mec.biz.service.*;
+import com.ym.mec.biz.service.PayService;
+import com.ym.mec.biz.service.SellOrderService;
+import com.ym.mec.biz.service.StudentPaymentOrderService;
+import com.ym.mec.biz.service.SysPaymentConfigService;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.redis.service.RedisCache;
 import com.ym.mec.thirdparty.adapay.ConfigInit;
 import com.ym.mec.thirdparty.adapay.Payment;
 import com.ym.mec.thirdparty.yqpay.YqPayUtil;
 import com.ym.mec.util.date.DateUtil;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.core.ValueOperations;
-import org.springframework.stereotype.Service;
-
-import java.math.BigDecimal;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 /**
  * 支付服务类
@@ -49,6 +60,52 @@ public class PayServiceImpl implements PayService {
 
     @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 {
+
+        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(orderNo);
+        
+        if(studentPaymentOrder == null){
+        	throw new BizException("订单[{}]查询失败", orderNo);
+        }
+        
+        Integer tenantId = studentPaymentOrder.getTenantId();
+        
+        if(tenantId != 1){//非大雅机构
+        	
+        	SysPaymentConfig sysPaymentConfig = sysPaymentConfigService.findPaymentConfigByOrganId(organId);
+        	
+        	if(sysPaymentConfig == null || StringUtils.isBlank(sysPaymentConfig.getHfMerNo())){
+        		throw new BizException("分部[{}]没有设置收款账号", organId);
+        	}
+        	
+        	Date date = new Date();
+        	
+        	String merNo = sysPaymentConfig.getHfMerNo();
+        	
+        	StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
+            studentPaymentRouteOrder.setOrderNo(orderNo);
+            studentPaymentRouteOrder.setRouteOrganId(organId);
+            studentPaymentRouteOrder.setFeeFlag("Y");
+            studentPaymentRouteOrder.setRouteAmount(amount);
+            studentPaymentRouteOrder.setRouteBalanceAmount(balanceAmount);
+            studentPaymentRouteOrder.setMerNo(merNo);
+            studentPaymentRouteOrder.setSaleAmount(BigDecimal.ZERO);
+            studentPaymentRouteOrder.setServiceAmount(amount);
+            studentPaymentRouteOrder.setCreateTime(date);
+            studentPaymentRouteOrder.setUpdateTime(date);
+            studentPaymentRouteOrderDao.insert(studentPaymentRouteOrder);
+            
+            Map<String, Object> unionPay = new HashMap<>();
+            Map<String, Object> payMap = Payment.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody);
+            
+            PaymentChannelEnum payType = PaymentChannelEnum.ADAPAY;
+
+            unionPay.put("orderNo", orderNo);
+            unionPay.put("type", payType.getCode());
+            unionPay.put("payMap", payMap);
+            unionPay.put("routingMerNos", merNo);
+            return unionPay;
+        }
+        
         String usePaymentConfig = sysConfigDao.findConfigValue("use_payment_config");// 是否用收费配置(1:使用 0:不使用)
         List<RouteScaleDto> routeScaleDtos = null;
         //使用配置开关
@@ -82,7 +139,28 @@ public class PayServiceImpl implements PayService {
         return getPayRoute(amount, balanceAmount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, routeScaleDtos);
     }
 
-    private List<RouteScaleDto> noUsePaymentConfig(BigDecimal amount) {
+    @Override
+	public Map<String, Object> getPayToPlatformMap(PaymentChannelEnum paymentChannel, String payeeMerNo, BigDecimal amount, BigDecimal balanceAmount, String orderNo, String notifyUrl, String returnUrl,
+			String orderSubject, String orderBody) throws Exception {
+    	
+        Map<String, Object> payMap = null;
+        
+    	if (paymentChannel.equals(PaymentChannelEnum.YQPAY)) {
+            payMap = YqPayUtil.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, YqPayUtil.merNo, payeeMerNo);
+        } else {
+            payMap = Payment.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody);
+        }
+        
+        Map<String, Object> unionPay = new HashMap<>();
+        unionPay.put("orderNo", orderNo);
+        unionPay.put("type", paymentChannel.getCode());
+        unionPay.put("payMap", payMap);
+        unionPay.put("routingMerNos", payeeMerNo);
+        
+		return unionPay;
+	}
+
+	private List<RouteScaleDto> noUsePaymentConfig(BigDecimal amount) {
         String paymentChannel = sysConfigDao.findConfigValue("payment_channel");
         List<RouteScaleDto> routeScaleDtos = new ArrayList<>();
         RouteScaleDto routeScaleDto = new RouteScaleDto();
@@ -399,7 +477,7 @@ public class PayServiceImpl implements PayService {
             }
             payMap = YqPayUtil.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, YqPayUtil.merNo, tempRoutingList);
         } else {
-            payMap = Payment.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, ConfigInit.merNo, tempRoutingList);
+            payMap = Payment.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody);
         }
         String routingMerNos = String.join(",", routingMerNoSet);
 

+ 1 - 1
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/Payment.java

@@ -144,7 +144,7 @@ public class Payment {
     }
 
 
-    public static Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, String sellerNo, List<Map<String, Object>> tempRoutingList) throws Exception {
+    public static Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody) throws Exception {
         Map<String, Object> paymentParams = new LinkedHashMap<>();
         paymentParams.put("appId", ConfigInit.appId);
         paymentParams.put("amount", amount.setScale(2, BigDecimal.ROUND_HALF_UP));