浏览代码

add 福袋活动指定账户收款

周箭河 5 年之前
父节点
当前提交
cf3ade11c4

+ 29 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/PayService.java

@@ -35,8 +35,37 @@ public interface PayService {
     Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer userId) throws Exception;
 
 
+    /**
+     *
+     * @param amount BigDecimal 支付金额
+     * @param orderNo String 订单号
+     * @param notifyUrl String 异步通知地址
+     * @param returnUrl string 支付返回地址
+     * @param orderSubject String 订单标题
+     * @param orderBody String 订单内容
+     * @param userId int 用户id
+     * @param fee 各种费用
+     * @param organId 机构id
+     * @return
+     * @throws Exception
+     */
     Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer userId,Map<String,BigDecimal> fee,Integer organId) throws Exception;
 
+    /**
+     *
+     * @param amount BigDecimal 支付金额
+     * @param orderNo String 订单号
+     * @param notifyUrl String 异步通知地址
+     * @param returnUrl string 支付返回地址
+     * @param orderSubject String 订单标题
+     * @param orderBody String 订单内容
+     * @param userId int 用户id
+     * @param fee Map 各种费用
+     * @param organId int 机构id
+     * @return
+     * @throws Exception
+     */
+    Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer userId,Map<String,BigDecimal> fee,Integer organId,String receiver) throws Exception;
 
     Map query(String orderNo) throws Exception;
 

+ 4 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -273,8 +273,10 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
 
         OrderTypeEnum type = OrderTypeEnum.SPORADIC;
+        String receiver = null;
         if(chargeInfo.getChargeType().equals("6")){
             type = OrderTypeEnum.LUCK;
+            receiver =  "PER";
         }
 
         Integer userId = sporadicPayDto.getUserId();
@@ -340,7 +342,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 chargeInfo.getTitle(),
                 userId,
                 classFee,
-                chargeInfo.getOrganId()
+                chargeInfo.getOrganId(),
+                receiver
         );
 
         Map<String, BigDecimal> routingFee = (Map<String, BigDecimal>) payMap.get("routingFee");

+ 101 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java

@@ -140,6 +140,53 @@ public class PayServiceImpl implements PayService {
     }
 
     @Override
+    public Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer userId, Map<String, BigDecimal> fee, Integer organId, String receiver) throws Exception {
+        String company = "daya";
+        if (userId != null) {
+            MusicGroup musicGroup = musicGroupDao.findUserMusicGroup(userId);
+            if (musicGroup != null && musicGroup.getOwnershipType() != null && musicGroup.getOwnershipType().equals(CooperationOrgan.OwnershipType.COOPERATION)) {
+                company = "yadie";
+            }
+        }
+
+        //支付通道决策
+        Map unionPay = new HashMap();
+        Map<String, BigDecimal> routingFee = getRoutingFee(company, amount, fee, organId,receiver);
+        List<SysAccount> accounts = getRoutingAccount(routingFee, company);
+        SysAccount routingAccount = accounts.get(0);
+
+        Map payMap = null;
+        String type = null;
+        if (routingAccount.getChannel().equals("YQPAY")) {
+            List<Map> tempRoutingList = new ArrayList();
+            for (SysAccount account : accounts) {
+                Map<String, Object> routingList = new HashMap<>();
+                routingList.put("routingMerNo", account.getRoutingMerNo());//分佣账户
+                routingList.put("routingFee", account.getRoutingFee().subtract((account.getRoutingFee().multiply(new BigDecimal("0.28")).divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_HALF_UP))); //分佣金额
+                tempRoutingList.add(routingList);
+            }
+            if(accounts.size() ==1 && routingAccount.getMerNo().equals(routingAccount.getRoutingMerNo())){
+                tempRoutingList = null;
+            }
+
+            payMap = YqPayUtil.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, routingAccount.getMerNo(), tempRoutingList);
+            type = "YQPAY";
+        } else {
+            payMap = new Pay().getPayMap(amount, orderNo, notifyUrl, orderSubject, orderBody);
+            type = "ADAPAY";
+        }
+
+        String routingMerNos = accounts.stream().map(sysAccount -> sysAccount.getRoutingMerNo()).collect(Collectors.joining(","));
+
+        unionPay.put("orderNo", orderNo);
+        unionPay.put("type", type);
+        unionPay.put("payMap", payMap);
+        unionPay.put("routingFee",routingFee);
+        unionPay.put("routingMerNos",routingMerNos);
+        return unionPay;
+    }
+
+    @Override
     public Map<String, Object> query(String orderNo) throws Exception {
         return new UnionPay(unionPayFeignService).query(orderNo);
     }
@@ -265,4 +312,58 @@ public class PayServiceImpl implements PayService {
     }
 
 
+    private Map<String, BigDecimal> getRoutingFee(String company, BigDecimal amount, Map<String, BigDecimal> fee, Integer organId,String receiver) {
+        Map<String, BigDecimal> routingFee = new HashMap<>(2);
+        routingFee.put("COM", BigDecimal.ZERO);
+        routingFee.put("PER", BigDecimal.ZERO);
+        if (company.equals("yadie")) {
+            routingFee.put("PER", amount);
+            return routingFee;
+        }
+
+        if(receiver != null){
+            routingFee.put(receiver, amount);
+            return routingFee;
+        }
+
+        SysPaymentConfig paymentConfig = sysPaymentConfigService.findPaymentConfigByOrganId(organId);
+
+        int payOrderNums = studentPaymentOrderService.findPayOrderNum(); //获取支付中和成功的订单数
+        //前几笔收入私户
+        Integer nums = Integer.parseInt(sysConfigDao.findConfigValue("per_account_nums"));
+        if (paymentConfig != null && paymentConfig.getType().equals(1)) {
+            nums = paymentConfig.getPerScale();
+        }
+
+        String type = null;
+        int rem = (payOrderNums + 1) % 10;
+        if (rem > 0 && rem <= nums) { //私人账户
+            type = "PER";
+        } else {
+            type = "COM";
+        }
+        routingFee.put(type, amount);
+
+        if (paymentConfig == null || !paymentConfig.getType().equals(2)) {
+            return routingFee;
+        }
+        routingFee.put(type, BigDecimal.ZERO);
+        for (Map.Entry<String, BigDecimal> feeEntry : fee.entrySet()) {
+            if (feeEntry.getKey().equals("course")) {
+                BigDecimal RoutingFee = routingFee.get(paymentConfig.getCourseFee()).add(feeEntry.getValue());
+                routingFee.put(paymentConfig.getCourseFee(), RoutingFee);
+            } else if (feeEntry.getKey().equals("instrument")) {
+                BigDecimal RoutingFee = routingFee.get(paymentConfig.getInstrumentFee()).add(feeEntry.getValue());
+                routingFee.put(paymentConfig.getInstrumentFee(), RoutingFee);
+            } else if (feeEntry.getKey().equals("accessories")) {
+                BigDecimal RoutingFee = routingFee.get(paymentConfig.getAccessoriesFee()).add(feeEntry.getValue());
+                routingFee.put(paymentConfig.getAccessoriesFee(), RoutingFee);
+            } else if (feeEntry.getKey().equals("other")) {
+                BigDecimal RoutingFee = routingFee.get(paymentConfig.getOtherFee()).add(feeEntry.getValue());
+                routingFee.put(paymentConfig.getOtherFee(), RoutingFee);
+            }
+        }
+        return routingFee;
+    }
+
 }