|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|