|
@@ -1,33 +1,30 @@
|
|
package com.ym.mec.biz.service.impl;
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
-import com.ym.mec.biz.dal.dao.MusicGroupDao;
|
|
|
|
|
|
+import com.ym.mec.biz.dal.dao.HfMemberDao;
|
|
import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
|
|
import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
import com.ym.mec.biz.dal.dto.AmountChannelDto;
|
|
import com.ym.mec.biz.dal.dto.AmountChannelDto;
|
|
import com.ym.mec.biz.dal.dto.RouteScaleDto;
|
|
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.FeeTypeEnum;
|
|
import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
|
|
import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
|
|
-import com.ym.mec.biz.dal.enums.PaymentChannelTypeEnum;
|
|
|
|
import com.ym.mec.biz.service.*;
|
|
import com.ym.mec.biz.service.*;
|
|
import com.ym.mec.common.exception.BizException;
|
|
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.ConfigInit;
|
|
import com.ym.mec.thirdparty.adapay.Payment;
|
|
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.thirdparty.yqpay.YqPayUtil;
|
|
import com.ym.mec.util.date.DateUtil;
|
|
import com.ym.mec.util.date.DateUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
+import org.springframework.data.redis.core.ValueOperations;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -45,6 +42,10 @@ public class PayServiceImpl implements PayService {
|
|
private StudentPaymentRouteOrderDao studentPaymentRouteOrderDao;
|
|
private StudentPaymentRouteOrderDao studentPaymentRouteOrderDao;
|
|
@Autowired
|
|
@Autowired
|
|
private SellOrderService sellOrderService;
|
|
private SellOrderService sellOrderService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private HfMemberDao hfMemberDao;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisCache<String, Object> redisCache;
|
|
|
|
|
|
@Override
|
|
@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 {
|
|
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 +74,11 @@ public class PayServiceImpl implements PayService {
|
|
routeScaleDtos = getPaymentConfigChannel(organId, amount);
|
|
routeScaleDtos = getPaymentConfigChannel(organId, amount);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //验证最大收款金额
|
|
|
|
+ for (RouteScaleDto routeScaleDto : routeScaleDtos) {
|
|
|
|
+ checkMaxReceipt(routeScaleDto, routeScaleDto.getMerNo());
|
|
|
|
+ }
|
|
|
|
+
|
|
return getPayRoute(amount, balanceAmount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, routeScaleDtos);
|
|
return getPayRoute(amount, balanceAmount, orderNo, notifyUrl, returnUrl, orderSubject, orderBody, routeScaleDtos);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -290,6 +296,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 {
|
|
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> unionPay = new HashMap<>();
|
|
Map<String, Object> payMap = null;
|
|
Map<String, Object> payMap = null;
|
|
|
|
|
|
@@ -498,4 +522,56 @@ public class PayServiceImpl implements PayService {
|
|
}
|
|
}
|
|
return newRouteScaleDtos;
|
|
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);
|
|
|
|
+
|
|
|
|
+// String key = "month_max_receipt_"+routeScaleDto.getOrganId();
|
|
|
|
+// if(redisCache.exists(key)){
|
|
|
|
+// RedisTemplate<String, Object> redisTemplate = redisCache.getRedisTemplate();
|
|
|
|
+// try {
|
|
|
|
+// ValueOperations<String, Object> valueOper = redisTemplate.opsForValue();
|
|
|
|
+// Long index = valueOper.increment(key, 1);
|
|
|
|
+// } catch (Exception ex) {
|
|
|
|
+// log.error("分布式订单号生成失败异常。。。。。", ex);
|
|
|
|
+// } finally {
|
|
|
|
+// redisTemplate.expire(key, 600, TimeUnit.SECONDS);// 保留10分钟内的key
|
|
|
|
+// }
|
|
|
|
+// }else {
|
|
|
|
+ BigDecimal monthHasReceipt = studentPaymentRouteOrderDao.getRouteOrderAmount(routeScaleDto.getOrganId(), paymentChannelList, monthStartTime);
|
|
|
|
+ monthHasReceipt = monthHasReceipt == null ? BigDecimal.ZERO : monthHasReceipt;
|
|
|
|
+// monthHasReceipt.multiply(new BigDecimal(100));
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
}
|
|
}
|