|
@@ -4,9 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
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.PayChannelDto;
|
|
|
import com.ym.mec.biz.dal.dto.RouteScaleDto;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
|
|
|
import com.ym.mec.biz.dal.entity.SysAccount;
|
|
|
import com.ym.mec.biz.dal.entity.SysPaymentConfig;
|
|
@@ -19,13 +17,9 @@ import com.ym.mec.thirdparty.adapay.Payment;
|
|
|
import com.ym.mec.thirdparty.union.UnionPay;
|
|
|
import com.ym.mec.thirdparty.union.UnionPayFeignService;
|
|
|
import com.ym.mec.thirdparty.yqpay.YqPayUtil;
|
|
|
-import com.ym.mec.util.http.HttpUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.boot.SpringApplication;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.data.redis.support.atomic.RedisAtomicDouble;
|
|
|
-import org.springframework.data.redis.support.atomic.RedisAtomicLong;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
@@ -62,6 +56,7 @@ public class PayServiceImpl implements PayService {
|
|
|
try {
|
|
|
Map<String, Object> payMap = new PayServiceImpl().getPayMap(
|
|
|
BigDecimal.TEN,
|
|
|
+ BigDecimal.ONE,
|
|
|
"5435253245",
|
|
|
baseApiUrl + "/api-student/studentOrder/notify",
|
|
|
baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=5435253245",
|
|
@@ -247,43 +242,40 @@ public class PayServiceImpl implements PayService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> getPayMap(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, Integer organId, String receiver) throws Exception {
|
|
|
+ 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 {
|
|
|
//根据金额获取分润
|
|
|
- PayChannelDto payChannelDto = getAmountChannel(amount);
|
|
|
+ List<RouteScaleDto> routeScaleDtos = getAmountChannel(amount);
|
|
|
//零星支付,收到指定
|
|
|
- if (payChannelDto == null && receiver != null && receiver.equals("")) {
|
|
|
- payChannelDto = getSporadicChannel(amount);
|
|
|
+ if (routeScaleDtos == null && receiver != null && receiver.equals("")) {
|
|
|
+ routeScaleDtos = getSporadicChannel(amount);
|
|
|
}
|
|
|
//比例或者笔数分佣
|
|
|
- if (payChannelDto == null) {
|
|
|
- payChannelDto = getPaymentConfigChannel(organId, amount);
|
|
|
+ if (routeScaleDtos == null) {
|
|
|
+ routeScaleDtos = getPaymentConfigChannel(organId, amount);
|
|
|
}
|
|
|
|
|
|
- return getPayRoute(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, payChannelDto);
|
|
|
+ return getPayRoute(amount, balanceAmount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, routeScaleDtos);
|
|
|
}
|
|
|
|
|
|
- private PayChannelDto getPaymentConfigChannel(Integer organId, BigDecimal amount) {
|
|
|
- PayChannelDto payChannelDto = new PayChannelDto();
|
|
|
- List<Map<String, Object>> tempRoutingList = new ArrayList<>();
|
|
|
- Map<String, Object> routingList = new HashMap<>();
|
|
|
+ private List<RouteScaleDto> getPaymentConfigChannel(Integer organId, BigDecimal amount) {
|
|
|
SysPaymentConfig paymentConfig = sysPaymentConfigService.findPaymentConfigByOrganId(organId);
|
|
|
if (paymentConfig == null || StringUtils.isBlank(paymentConfig.getRouteScale())) {
|
|
|
String paymentChannel = sysConfigDao.findConfigValue("payment_channel");
|
|
|
+ List<RouteScaleDto> routeScaleDtos = new ArrayList<>();
|
|
|
+ RouteScaleDto routeScaleDto = new RouteScaleDto();
|
|
|
+ routeScaleDto.setAmount(amount);
|
|
|
+ routeScaleDto.setOrganId(organId);
|
|
|
+ routeScaleDto.setScale(100);
|
|
|
if (paymentChannel.equals("YQPAY")) {
|
|
|
- routingList.put("organId", organId);
|
|
|
- routingList.put("routingMerNo", YqPayUtil.merNo);//分佣账户
|
|
|
- routingList.put("routingFee", amount.subtract((amount.multiply(new BigDecimal("0.28")).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)))); //分佣金额
|
|
|
- payChannelDto.setPayType(PaymentChannelEnum.YQPAY);
|
|
|
+ routeScaleDto.setMerNo(YqPayUtil.merNo);
|
|
|
+ routeScaleDto.setPayType(PaymentChannelEnum.YQPAY);
|
|
|
} else {
|
|
|
- routingList.put("organId", organId);
|
|
|
- routingList.put("member_id", ConfigInit.merNo);//分佣账户
|
|
|
- routingList.put("amount", amount);//分佣金额
|
|
|
- routingList.put("fee_flag", "Y"); //承担手续费
|
|
|
- payChannelDto.setPayType(PaymentChannelEnum.ADAPAY);
|
|
|
+ routeScaleDto.setMerNo(ConfigInit.merNo);
|
|
|
+ routeScaleDto.setPayType(PaymentChannelEnum.ADAPAY);
|
|
|
+ routeScaleDto.setFeeFlag("Y");
|
|
|
}
|
|
|
- tempRoutingList.add(routingList);
|
|
|
- payChannelDto.setTempRoutingList(tempRoutingList);
|
|
|
- return payChannelDto;
|
|
|
+ routeScaleDtos.add(routeScaleDto);
|
|
|
+ return routeScaleDtos;
|
|
|
}
|
|
|
|
|
|
String routeScale = paymentConfig.getRouteScale();
|
|
@@ -322,44 +314,7 @@ public class PayServiceImpl implements PayService {
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
- BigDecimal routingAmount = amount.subtract((amount.multiply(new BigDecimal("0.28")).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)));
|
|
|
- int i = 0;
|
|
|
- BigDecimal hasRouteAmount = BigDecimal.ZERO;
|
|
|
- for (RouteScaleDto routeScaleDto : routeScaleDtos) {
|
|
|
- routingList = new HashMap<>();
|
|
|
- i++;
|
|
|
- if (routeScaleDto.getPayType().equals(PaymentChannelEnum.YQPAY)) {
|
|
|
- BigDecimal routingFee = routingAmount.multiply(new BigDecimal(routeScaleDto.getScale())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- if (i == routeScaleDtos.size()) {
|
|
|
- routingFee = routingAmount.subtract(hasRouteAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- }
|
|
|
- hasRouteAmount = hasRouteAmount.add(routingFee);
|
|
|
- if (routingFee.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- routingList.put("organId", routeScaleDto.getOrganId());
|
|
|
- routingList.put("routingMerNo", routeScaleDto.getMerNo());//分佣账户
|
|
|
- routingList.put("routingFee", routingFee); //分佣金额
|
|
|
- } else if (paymentConfig.getPayType().equals(PaymentChannelEnum.ADAPAY)) {
|
|
|
- BigDecimal routingFee = amount.multiply(new BigDecimal(routeScaleDto.getScale())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
- if (i == routeScaleDtos.size()) {
|
|
|
- routingFee = amount.subtract(hasRouteAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- }
|
|
|
- hasRouteAmount = hasRouteAmount.add(routingFee);
|
|
|
- if (routingFee.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- routingList.put("organId", routeScaleDto.getOrganId());
|
|
|
- routingList.put("member_id", routeScaleDto.getMerNo());//分佣账户
|
|
|
- routingList.put("amount", routingFee);//分佣金额
|
|
|
- routingList.put("fee_flag", routeScaleDto.getFeeFlag()); //承担手续费
|
|
|
- }
|
|
|
- tempRoutingList.add(routingList);
|
|
|
- }
|
|
|
-
|
|
|
- payChannelDto.setPayType(paymentConfig.getPayType());
|
|
|
- payChannelDto.setTempRoutingList(tempRoutingList);
|
|
|
- return payChannelDto;
|
|
|
+ return routeScaleDtos;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -368,13 +323,12 @@ public class PayServiceImpl implements PayService {
|
|
|
*
|
|
|
* @param amount 金额
|
|
|
*/
|
|
|
- private PayChannelDto getAmountChannel(BigDecimal amount) {
|
|
|
+ private List<RouteScaleDto> getAmountChannel(BigDecimal amount) {
|
|
|
String amountChannel = sysConfigDao.findConfigValue("amount_channel");
|
|
|
if (StringUtils.isBlank(amountChannel)) {
|
|
|
return null;
|
|
|
}
|
|
|
Integer organId = null;
|
|
|
- List<Map<String, Object>> tempRoutingList = new ArrayList<>();
|
|
|
Map<String, Integer> channel = (Map<String, Integer>) JSON.parseObject(amountChannel, Map.class);
|
|
|
for (Map.Entry<String, Integer> amountStr : channel.entrySet()) {
|
|
|
if (new BigDecimal(amountStr.getKey()).compareTo(amount) == 0) {
|
|
@@ -385,23 +339,22 @@ public class PayServiceImpl implements PayService {
|
|
|
if (organId == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- PayChannelDto payChannelDto = new PayChannelDto();
|
|
|
+
|
|
|
SysPaymentConfig paymentConfig = sysPaymentConfigService.findPaymentConfigByOrganId(organId);
|
|
|
- Map<String, Object> routingList = new HashMap<>();
|
|
|
+ RouteScaleDto routeScaleDto = new RouteScaleDto();
|
|
|
+ List<RouteScaleDto> routeScaleDtos = new ArrayList<>();
|
|
|
+ routeScaleDto.setAmount(amount);
|
|
|
+ routeScaleDto.setOrganId(paymentConfig.getOrganId());
|
|
|
+ routeScaleDto.setPayType(paymentConfig.getPayType());
|
|
|
+ routeScaleDto.setScale(100);
|
|
|
if (paymentConfig.getPayType().equals(PaymentChannelEnum.YQPAY)) {
|
|
|
- routingList.put("organId", paymentConfig.getOrganId());
|
|
|
- routingList.put("routingMerNo", paymentConfig.getYqMerNo());//分佣账户
|
|
|
- routingList.put("routingFee", amount.subtract((amount.multiply(new BigDecimal("0.28")).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)))); //分佣金额
|
|
|
- } else if (paymentConfig.getPayType().equals(PaymentChannelEnum.ADAPAY)) {
|
|
|
- routingList.put("organId", paymentConfig.getOrganId());
|
|
|
- routingList.put("member_id", paymentConfig.getHfMerNo());//分佣账户
|
|
|
- routingList.put("amount", amount);//分佣金额
|
|
|
- routingList.put("fee_flag", "Y"); //承担手续费
|
|
|
- }
|
|
|
- tempRoutingList.add(routingList);
|
|
|
- payChannelDto.setPayType(paymentConfig.getPayType());
|
|
|
- payChannelDto.setTempRoutingList(tempRoutingList);
|
|
|
- return payChannelDto;
|
|
|
+ routeScaleDto.setMerNo(paymentConfig.getYqMerNo());
|
|
|
+ } else {
|
|
|
+ routeScaleDto.setMerNo(paymentConfig.getHfMerNo());
|
|
|
+ routeScaleDto.setFeeFlag("Y");
|
|
|
+ }
|
|
|
+ routeScaleDtos.add(routeScaleDto);
|
|
|
+ return routeScaleDtos;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -410,13 +363,12 @@ public class PayServiceImpl implements PayService {
|
|
|
* @param amount
|
|
|
* @return
|
|
|
*/
|
|
|
- private PayChannelDto getSporadicChannel(BigDecimal amount) {
|
|
|
+ private List<RouteScaleDto> getSporadicChannel(BigDecimal amount) {
|
|
|
String SporadicChannel = sysConfigDao.findConfigValue("sporadic_channel");
|
|
|
if (StringUtils.isBlank(SporadicChannel)) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- List<Map<String, Object>> tempRoutingList = new ArrayList<>();
|
|
|
Map<String, String> channel = (Map<String, String>) JSON.parseObject(SporadicChannel, Map.class);
|
|
|
Integer organId = Integer.parseInt(channel.get("organId"));
|
|
|
BigDecimal maxReceipt = new BigDecimal(channel.get("maxReceipt"));
|
|
@@ -431,73 +383,93 @@ public class PayServiceImpl implements PayService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- PayChannelDto payChannelDto = new PayChannelDto();
|
|
|
SysPaymentConfig paymentConfig = sysPaymentConfigService.findPaymentConfigByOrganId(organId);
|
|
|
- Map<String, Object> routingList = new HashMap<>();
|
|
|
+
|
|
|
+ RouteScaleDto routeScaleDto = new RouteScaleDto();
|
|
|
+ List<RouteScaleDto> routeScaleDtos = new ArrayList<>();
|
|
|
+ routeScaleDto.setAmount(amount);
|
|
|
+ routeScaleDto.setOrganId(paymentConfig.getOrganId());
|
|
|
+ routeScaleDto.setPayType(paymentConfig.getPayType());
|
|
|
+ routeScaleDto.setScale(100);
|
|
|
if (paymentConfig.getPayType().equals(PaymentChannelEnum.YQPAY)) {
|
|
|
- routingList.put("organId", paymentConfig.getOrganId());
|
|
|
- routingList.put("routingMerNo", paymentConfig.getYqMerNo());//分佣账户
|
|
|
- routingList.put("routingFee", amount.subtract((amount.multiply(new BigDecimal("0.28")).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)))); //分佣金额
|
|
|
- } else if (paymentConfig.getPayType().equals(PaymentChannelEnum.ADAPAY)) {
|
|
|
- routingList.put("organId", paymentConfig.getOrganId());
|
|
|
- routingList.put("member_id", paymentConfig.getHfMerNo());//分佣账户
|
|
|
- routingList.put("amount", amount);//分佣金额
|
|
|
- routingList.put("fee_flag", "Y"); //承担手续费
|
|
|
- }
|
|
|
- tempRoutingList.add(routingList);
|
|
|
- payChannelDto.setPayType(paymentConfig.getPayType());
|
|
|
- payChannelDto.setTempRoutingList(tempRoutingList);
|
|
|
- return payChannelDto;
|
|
|
+ routeScaleDto.setMerNo(paymentConfig.getYqMerNo());
|
|
|
+ } else {
|
|
|
+ routeScaleDto.setMerNo(paymentConfig.getHfMerNo());
|
|
|
+ routeScaleDto.setFeeFlag("Y");
|
|
|
+ }
|
|
|
+ routeScaleDtos.add(routeScaleDto);
|
|
|
+ return routeScaleDtos;
|
|
|
}
|
|
|
|
|
|
- private Map<String, Object> getPayRoute(BigDecimal amount, String orderNo, String notifyUrl, String returnUrl, String orderSubject, String orderBody, PayChannelDto payChannelDto) throws Exception {
|
|
|
+ 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, Object> unionPay = new HashMap<>();
|
|
|
Map<String, Object> payMap = null;
|
|
|
- String type;
|
|
|
String routingMerNos;
|
|
|
|
|
|
- List<Map<String, Object>> tempRoutingList = payChannelDto.getTempRoutingList();
|
|
|
List<StudentPaymentRouteOrder> RouteOrders = new ArrayList<>();
|
|
|
- StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(orderNo);
|
|
|
- for (Map<String, Object> routing : tempRoutingList) {
|
|
|
+
|
|
|
+ BigDecimal yqAmount = amount.subtract((amount.multiply(new BigDecimal("0.28")).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)));
|
|
|
+ int i = 0;
|
|
|
+ BigDecimal hasRouteAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal hasRouteBalanceAmount = BigDecimal.ZERO;
|
|
|
+ List<Map<String, Object>> tempRoutingList = new ArrayList<>();
|
|
|
+
|
|
|
+ PaymentChannelEnum patType = null;
|
|
|
+ for (RouteScaleDto routeScaleDto : routeScaleDtos) {
|
|
|
+ patType = routeScaleDto.getPayType();
|
|
|
+ Map<String, Object> routingList = new HashMap<>();
|
|
|
+ i++;
|
|
|
+
|
|
|
+ BigDecimal routingAmount = amount;
|
|
|
+ if (routeScaleDto.getPayType().equals(PaymentChannelEnum.YQPAY)) {
|
|
|
+ routingAmount = yqAmount;
|
|
|
+ }
|
|
|
+ BigDecimal routingFee = routingAmount.multiply(new BigDecimal(routeScaleDto.getScale())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal routeBalanceAmount = balanceAmount.multiply(new BigDecimal(routeScaleDto.getScale())).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (i == routeScaleDtos.size()) {
|
|
|
+ routingFee = routingAmount.subtract(hasRouteAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ routeBalanceAmount = balanceAmount.subtract(hasRouteBalanceAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ hasRouteAmount = hasRouteAmount.add(routingFee);
|
|
|
+ hasRouteBalanceAmount = hasRouteBalanceAmount.add(routeBalanceAmount);
|
|
|
+
|
|
|
+ if (routingFee.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ routingList.put("organId", routeScaleDto.getOrganId());
|
|
|
+ routingList.put("routingMerNo", routeScaleDto.getMerNo());//分佣账户
|
|
|
+ routingList.put("routingFee", routingFee); //分佣金额
|
|
|
+
|
|
|
+ tempRoutingList.add(routingList);
|
|
|
+
|
|
|
StudentPaymentRouteOrder studentPaymentRouteOrder = new StudentPaymentRouteOrder();
|
|
|
studentPaymentRouteOrder.setOrderNo(orderNo);
|
|
|
- studentPaymentRouteOrder.setRoutingOrganId((Integer) routing.get("organId"));
|
|
|
- BigDecimal routeAmount;
|
|
|
- String merNo;
|
|
|
- if (payChannelDto.getPayType().equals(PaymentChannelEnum.YQPAY)) {
|
|
|
- routeAmount = (BigDecimal) routing.get("routingFee");
|
|
|
- merNo = (String) routing.get("routingMerNo");
|
|
|
- } else {
|
|
|
- routeAmount = (BigDecimal) routing.get("amount");
|
|
|
- merNo = (String) routing.get("member_id");
|
|
|
- studentPaymentRouteOrder.setFeeFlag((String) routing.get("fee_flag"));
|
|
|
- }
|
|
|
- studentPaymentRouteOrder.setRouteAmount(routeAmount);
|
|
|
- studentPaymentRouteOrder.setMerNo(merNo);
|
|
|
+ studentPaymentRouteOrder.setRouteOrganId(routeScaleDto.getOrganId());
|
|
|
+ studentPaymentRouteOrder.setFeeFlag(routeScaleDto.getFeeFlag());
|
|
|
+ studentPaymentRouteOrder.setRouteAmount(routingFee);
|
|
|
+ studentPaymentRouteOrder.setRouteBalanceAmount(routeBalanceAmount);
|
|
|
+ studentPaymentRouteOrder.setMerNo(routeScaleDto.getMerNo());
|
|
|
RouteOrders.add(studentPaymentRouteOrder);
|
|
|
}
|
|
|
+
|
|
|
if (studentPaymentRouteOrderDao.batchAdd(RouteOrders) <= 0) {
|
|
|
throw new BizException("调用支付接口失败");
|
|
|
}
|
|
|
|
|
|
- if (payChannelDto.getPayType().equals(PaymentChannelEnum.YQPAY)) {
|
|
|
+ if (patType.equals(PaymentChannelEnum.YQPAY)) {
|
|
|
if (tempRoutingList.size() == 1 && YqPayUtil.merNo.equals(tempRoutingList.get(0).get("routingMerNo").toString())) {
|
|
|
tempRoutingList = null;
|
|
|
}
|
|
|
payMap = YqPayUtil.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, YqPayUtil.merNo, tempRoutingList);
|
|
|
- type = "YQPAY";
|
|
|
- routingMerNos = payChannelDto.getTempRoutingList().stream().map(e -> e.get("routingMerNo").toString()).collect(Collectors.joining(","));
|
|
|
} else {
|
|
|
payMap = Payment.getPayMap(amount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, ConfigInit.merNo, tempRoutingList);
|
|
|
- type = "ADAPAY";
|
|
|
- routingMerNos = payChannelDto.getTempRoutingList().stream().map(e -> e.get("member_id").toString()).collect(Collectors.joining(","));
|
|
|
}
|
|
|
+ routingMerNos = routeScaleDtos.stream().map(RouteScaleDto::getMerNo).collect(Collectors.joining(","));
|
|
|
+
|
|
|
unionPay.put("orderNo", orderNo);
|
|
|
- unionPay.put("type", type);
|
|
|
+ unionPay.put("type", patType.getCode());
|
|
|
unionPay.put("payMap", payMap);
|
|
|
unionPay.put("routingMerNos", routingMerNos);
|
|
|
- unionPay.put("routingList", payChannelDto.getTempRoutingList());
|
|
|
return unionPay;
|
|
|
}
|
|
|
|