|
@@ -1,18 +1,121 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.CLOSE;
|
|
|
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
-import com.ym.mec.biz.dal.dao.*;
|
|
|
-import com.ym.mec.biz.dal.dto.*;
|
|
|
-import com.ym.mec.biz.dal.entity.*;
|
|
|
-import com.ym.mec.biz.dal.enums.*;
|
|
|
+import com.ym.mec.biz.dal.dao.CourseScheduleStudentPaymentDao;
|
|
|
+import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
+import com.ym.mec.biz.dal.dao.GoodsProcurementDao;
|
|
|
+import com.ym.mec.biz.dal.dao.MusicGroupDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SellOrderDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentGoodsSellDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentPaymentRouteOrderDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentRepairDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
|
|
|
+import com.ym.mec.biz.dal.dto.GoodsOrderItemVO;
|
|
|
+import com.ym.mec.biz.dal.dto.OperatingTotalIncomeDto;
|
|
|
+import com.ym.mec.biz.dal.dto.PageInfoOrder;
|
|
|
+import com.ym.mec.biz.dal.dto.SporadicChargeInfoDto;
|
|
|
+import com.ym.mec.biz.dal.dto.StudentGoodsSellDto;
|
|
|
+import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
|
|
|
+import com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto;
|
|
|
+import com.ym.mec.biz.dal.entity.ActivityUserMapper;
|
|
|
+import com.ym.mec.biz.dal.entity.CloudTeacherOrder;
|
|
|
+import com.ym.mec.biz.dal.entity.Goods;
|
|
|
+import com.ym.mec.biz.dal.entity.GoodsProcurement;
|
|
|
+import com.ym.mec.biz.dal.entity.MusicGroup;
|
|
|
+import com.ym.mec.biz.dal.entity.MusicGroupSubjectPlan;
|
|
|
+import com.ym.mec.biz.dal.entity.SellOrder;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentGoodsSell;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentPaymentRouteOrder;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentRegistration;
|
|
|
+import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
+import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
|
|
|
+import com.ym.mec.biz.dal.entity.VipGroupActivity;
|
|
|
+import com.ym.mec.biz.dal.enums.AccountType;
|
|
|
+import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.GoodsType;
|
|
|
+import com.ym.mec.biz.dal.enums.GroupType;
|
|
|
+import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.PayStatus;
|
|
|
+import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.SellStatus;
|
|
|
+import com.ym.mec.biz.dal.enums.SellTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.SporadicChargeTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.StockType;
|
|
|
+import com.ym.mec.biz.dal.enums.StudentMusicGroupStatusEnum;
|
|
|
import com.ym.mec.biz.dal.page.SporadicOrderQueryInfo;
|
|
|
import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
|
|
|
import com.ym.mec.biz.dal.vo.StudentPaymentOrderVo;
|
|
|
-import com.ym.mec.biz.service.*;
|
|
|
+import com.ym.mec.biz.service.ActivityUserMapperService;
|
|
|
+import com.ym.mec.biz.service.ChildrenDayReserveService;
|
|
|
+import com.ym.mec.biz.service.CloudTeacherOrderService;
|
|
|
+import com.ym.mec.biz.service.ContractService;
|
|
|
+import com.ym.mec.biz.service.DegreeRegistrationService;
|
|
|
+import com.ym.mec.biz.service.GoodsService;
|
|
|
+import com.ym.mec.biz.service.HfMerchantConfigService;
|
|
|
+import com.ym.mec.biz.service.MemberRankSettingService;
|
|
|
+import com.ym.mec.biz.service.MusicGroupService;
|
|
|
+import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
|
|
|
+import com.ym.mec.biz.service.PayService;
|
|
|
+import com.ym.mec.biz.service.PracticeGroupService;
|
|
|
+import com.ym.mec.biz.service.ReplacementInstrumentActivityService;
|
|
|
+import com.ym.mec.biz.service.SporadicChargeInfoService;
|
|
|
+import com.ym.mec.biz.service.StudentInstrumentService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentOrderService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
|
|
|
+import com.ym.mec.biz.service.StudentRegistrationService;
|
|
|
+import com.ym.mec.biz.service.StudentRepairService;
|
|
|
+import com.ym.mec.biz.service.SubjectChangeService;
|
|
|
+import com.ym.mec.biz.service.SysCouponCodeService;
|
|
|
+import com.ym.mec.biz.service.SysPaymentConfigService;
|
|
|
+import com.ym.mec.biz.service.SysUserCashAccountDetailService;
|
|
|
+import com.ym.mec.biz.service.SysUserCashAccountService;
|
|
|
+import com.ym.mec.biz.service.TenantConfigService;
|
|
|
+import com.ym.mec.biz.service.VipGroupActivityService;
|
|
|
+import com.ym.mec.biz.service.VipGroupService;
|
|
|
import com.ym.mec.common.controller.BaseController;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.entity.HttpResponseResult;
|
|
@@ -29,29 +132,15 @@ import com.ym.mec.thirdparty.adapay.ConfigInit;
|
|
|
import com.ym.mec.thirdparty.adapay.Payment;
|
|
|
import com.ym.mec.thirdparty.adapay.entity.BaseResult;
|
|
|
import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
|
|
|
-import com.ym.mec.thirdparty.yqpay.*;
|
|
|
+import com.ym.mec.thirdparty.yeepay.YeepayPaymentService;
|
|
|
+import com.ym.mec.thirdparty.yqpay.DateUtils;
|
|
|
+import com.ym.mec.thirdparty.yqpay.Msg;
|
|
|
+import com.ym.mec.thirdparty.yqpay.RsqMsg;
|
|
|
+import com.ym.mec.thirdparty.yqpay.YqPayFeignService;
|
|
|
+import com.ym.mec.thirdparty.yqpay.YqPayUtil;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Lazy;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Propagation;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.atomic.AtomicInteger;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import static com.ym.mec.biz.dal.enums.DealStatusEnum.CLOSE;
|
|
|
-import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
|
|
|
-
|
|
|
@Service
|
|
|
public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrder> implements StudentPaymentOrderService {
|
|
|
|
|
@@ -133,6 +222,9 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
private StudentDao studentDao;
|
|
|
@Autowired
|
|
|
private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private YeepayPaymentService yeepayPaymentService;
|
|
|
@Autowired
|
|
|
private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
|
|
|
|
|
@@ -201,7 +293,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
return notifyMap;
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> payMap = payService.getPayMap(cashAmount, balance, studentPaymentOrder.getOrderNo(), baseApiUrl + "/api-student/studentOrder/callback", baseApiUrl
|
|
|
+ Map<String, Object> payMap = payService.getPayMap(cashAmount, balance, studentPaymentOrder.getOrderNo(),
|
|
|
+ baseApiUrl + "/api-student/studentOrder/callback/" + studentPaymentOrder.getOrderNo(), baseApiUrl
|
|
|
+ "/api-student/studentOrder/paymentResult?orderNo=" + studentPaymentOrder.getOrderNo(), studentPaymentOrder.getMemo(), studentPaymentOrder.getMemo(), studentPaymentOrder.getOrganId(), payReceiver);
|
|
|
|
|
|
studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
@@ -237,8 +330,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<StudentPaymentOrder> findOrdersByStatus(DealStatusEnum status, String paymentChannel) {
|
|
|
- return studentPaymentOrderDao.findOrdersByStatus(status, paymentChannel);
|
|
|
+ public List<StudentPaymentOrder> findOrdersByStatus(DealStatusEnum status) {
|
|
|
+ return studentPaymentOrderDao.findOrdersByStatus(status);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -247,15 +340,16 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
public void queryOrderStatus() throws Exception {
|
|
|
- yqPayQuery(null);
|
|
|
+ //yqPayQuery(null);
|
|
|
adaPayQuery(null);
|
|
|
- reConfirmOrder(null, null);
|
|
|
+ //reConfirmOrder(null, null);
|
|
|
}
|
|
|
|
|
|
private void yqPayQuery(List<StudentPaymentOrder> payingOrders) throws Exception {
|
|
|
if (payingOrders == null) {
|
|
|
- payingOrders = findOrdersByStatus(DealStatusEnum.ING, "YQPAY");
|
|
|
+ payingOrders = findOrdersByStatus(DealStatusEnum.ING);
|
|
|
}
|
|
|
if (payingOrders.size() == 0) {
|
|
|
return;
|
|
@@ -301,7 +395,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
|
|
|
private void adaPayQuery(List<StudentPaymentOrder> payingOrders) throws Exception {
|
|
|
if (payingOrders == null) {
|
|
|
- payingOrders = findOrdersByStatus(DealStatusEnum.ING, "ADAPAY");
|
|
|
+ payingOrders = findOrdersByStatus(DealStatusEnum.ING);
|
|
|
}
|
|
|
|
|
|
Date date = new Date();
|
|
@@ -310,9 +404,6 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- Map<Integer,HfMerchantConfig> payConfigMap = new HashMap<Integer, HfMerchantConfig>();
|
|
|
- HfMerchantConfig hfMerchantConfig = null;
|
|
|
-
|
|
|
List<String> orderNoList = new ArrayList<String>();
|
|
|
|
|
|
for (StudentPaymentOrder payingOrder : payingOrders) {
|
|
@@ -328,30 +419,49 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
if (DateUtil.minutesBetween(payingOrder.getCreateTime(), date) < 10) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- updateOrderStatus(date, payConfigMap, payingOrder,true);
|
|
|
+ try {
|
|
|
+ updateOrderStatus(date, payingOrder);
|
|
|
+ }catch (Exception e) {
|
|
|
+ logger.error("执行[订单状态查询]任务失败", e);
|
|
|
+ }
|
|
|
}
|
|
|
closeOrders(orderNoList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public OrderCancelModel updateOrderStatus(Date date, Map<Integer, HfMerchantConfig> payConfigMap, StudentPaymentOrder payingOrder, Boolean checkTime) throws Exception {
|
|
|
- if (payConfigMap == null) {
|
|
|
- throw new BizException("payConfigMap 不能为空");
|
|
|
- }
|
|
|
- HfMerchantConfig hfMerchantConfig;
|
|
|
- hfMerchantConfig = payConfigMap.get(payingOrder.getTenantId());
|
|
|
+ public OrderCancelModel updateOrderStatus(Date date, StudentPaymentOrder payingOrder) throws Exception {
|
|
|
+
|
|
|
+ HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(payingOrder.getTenantId(), payingOrder.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
- hfMerchantConfig = hfMerchantConfigService.queryByTenantId(payingOrder.getTenantId());
|
|
|
- if(hfMerchantConfig == null){
|
|
|
- throw new BizException("机构[{}]汇付商户信息找不到", payingOrder.getTenantId());
|
|
|
- }
|
|
|
- payConfigMap.put(payingOrder.getTenantId(), hfMerchantConfig);
|
|
|
+ throw new BizException("机构[{}]汇付商户信息找不到", payingOrder.getTenantId());
|
|
|
}
|
|
|
+
|
|
|
+ PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(payingOrder.getPaymentChannel());
|
|
|
+
|
|
|
OrderCancelModel model = new OrderCancelModel();
|
|
|
+ Map<String, Object> payment = new HashMap<String, Object>();
|
|
|
|
|
|
- Map<String, Object> payment = Payment.queryPayment(payingOrder.getTransNo(), hfMerchantConfig.getMerKey());
|
|
|
+ if(paymentChannel == PaymentChannelEnum.ADAPAY) {
|
|
|
+ payment = Payment.queryPayment(payingOrder.getTransNo(), hfMerchantConfig.getMerKey());
|
|
|
+ }else if(paymentChannel == PaymentChannelEnum.YEEPAY) {
|
|
|
+ Map<String, Object> orderInfo = yeepayPaymentService.queryOrder(hfMerchantConfig, payingOrder.getMerNos(), payingOrder.getOrderNo());
|
|
|
+ payment.put("pay_channel", orderInfo.get("channel"));
|
|
|
+
|
|
|
+ String respStatus = orderInfo.get("status").toString();
|
|
|
+
|
|
|
+ if(StringUtils.equals("SUCCESS", respStatus)) {
|
|
|
+ payment.put("status", "succeeded");
|
|
|
+ }else if(StringUtils.equals("FAIL", respStatus) || StringUtils.equals("TIME_OUT", respStatus) || StringUtils.equals("CLOSE", respStatus)) {
|
|
|
+ payment.put("status", "failed");
|
|
|
+ }else {
|
|
|
+ payment.put("status", "pending");
|
|
|
+ }
|
|
|
+ payment.put("error_msg", orderInfo.get("failReason"));
|
|
|
+ }else {
|
|
|
+ throw new BizException("[{}]支付渠道不支持", payingOrder.getPaymentChannel());
|
|
|
+ }
|
|
|
+
|
|
|
LOGGER.warn("订单[{}]交易主动查询接口返回:{}", payingOrder.getTransNo(), payment);
|
|
|
|
|
|
Map<String, String> rpMap = new HashMap<>();
|
|
@@ -366,14 +476,14 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
if (status.equals("succeeded")) {
|
|
|
rpMap.put("tradeState", "1");
|
|
|
model.setStatus(true);
|
|
|
- } else if (status.equals("failed") || !checkTime
|
|
|
+ } else if (status.equals("failed")
|
|
|
|| (DateUtil.minutesBetween(DateUtil.addHours(payingOrder.getUpdateTime(), 2),date) > 0)) {
|
|
|
rpMap.put("tradeState", "0");
|
|
|
model.setStatus(false);
|
|
|
}
|
|
|
|
|
|
if (status.equals("succeeded") ||
|
|
|
- (status.equals("failed") || !checkTime || payingOrder.getCreateTime().before(DateUtil.addMinutes(new Date(), -35)))) {
|
|
|
+ (status.equals("failed") || payingOrder.getCreateTime().before(DateUtil.addMinutes(new Date(), -35)))) {
|
|
|
try {
|
|
|
updateOrder(rpMap); //更新订单
|
|
|
model.setSuccess(true);
|
|
@@ -401,7 +511,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateOrder(Map<String, String> rpMap) throws Exception {
|
|
|
- DealStatusEnum status = rpMap.get("tradeState").equals("1") ? DealStatusEnum.SUCCESS : DealStatusEnum.FAILED;
|
|
|
+ DealStatusEnum status = "1".equals(rpMap.get("tradeState")) ? DealStatusEnum.SUCCESS : DealStatusEnum.FAILED;
|
|
|
StudentPaymentOrder order = findOrderByOrderNo(rpMap.get("merOrderNo"));
|
|
|
//关闭或失败的订单查询订单成功,订单改成成功,钱退到余额
|
|
|
if (order != null && (order.getStatus().equals(DealStatusEnum.CLOSE) || order.getStatus().equals(DealStatusEnum.FAILED)) && status.equals(DealStatusEnum.SUCCESS)) {
|
|
@@ -421,7 +531,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
PlatformCashAccountDetailTypeEnum.REFUNDS, order.getMemo() + ",订单号:" + order.getOrderNo());
|
|
|
|
|
|
if (StringUtils.isNotBlank(order.getPaymentChannel())
|
|
|
- && order.getPaymentChannel().equals("ADAPAY")
|
|
|
+ && (order.getPaymentChannel().equals(PaymentChannelEnum.ADAPAY.getCode()) || order.getPaymentChannel().equals(PaymentChannelEnum.YEEPAY.getCode()))
|
|
|
&& !rpMap.containsKey("simulation")) {
|
|
|
confirmOrder(order);
|
|
|
}
|
|
@@ -452,14 +562,15 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
|
|
|
if (status.equals(DealStatusEnum.SUCCESS)
|
|
|
&& StringUtils.isNotBlank(order.getPaymentChannel())
|
|
|
- && order.getPaymentChannel().equals("ADAPAY")
|
|
|
+ && (order.getPaymentChannel().equals(PaymentChannelEnum.ADAPAY.getCode()) || order.getPaymentChannel().equals(PaymentChannelEnum.YEEPAY.getCode()))
|
|
|
&& !rpMap.containsKey("simulation")) {
|
|
|
confirmOrder(order);
|
|
|
}
|
|
|
TenantContextHolder.clearTenantId();
|
|
|
}
|
|
|
|
|
|
- private Boolean confirmOrder(StudentPaymentOrder order) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean confirmOrder(StudentPaymentOrder order) {
|
|
|
// 只有大雅延迟分账,其他实时分账
|
|
|
if (order.getTenantId() != 1) {
|
|
|
return true;
|
|
@@ -469,39 +580,104 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
HfMerchantConfig hfMerchantConfig = null;
|
|
|
|
|
|
List<StudentPaymentRouteOrder> routeOrders = studentPaymentRouteOrderDao.getRouteOrders(order.getOrderNo());
|
|
|
- for (StudentPaymentRouteOrder routeOrder : routeOrders) {
|
|
|
- if(hfMerchantConfig == null){
|
|
|
- hfMerchantConfig = hfMerchantConfigService.queryByTenantId(routeOrder.getTenantId());
|
|
|
- }
|
|
|
- if(hfMerchantConfig == null){
|
|
|
- throw new BizException("机构[{}]汇付商户信息找不到", routeOrder.getTenantId());
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> divMember = new HashMap<>();
|
|
|
- divMember.put("member_id", routeOrder.getMerNo());//分佣账户
|
|
|
- divMember.put("amount", routeOrder.getRouteAmount().setScale(2, BigDecimal.ROUND_HALF_UP));//分佣金额
|
|
|
- divMember.put("fee_flag", "Y");
|
|
|
- if (routeOrder.getMerNo().equals(ConfigInit.merNo)) {
|
|
|
- divMember.put("member_id", 0);
|
|
|
- }
|
|
|
- List<Map<String, Object>> divMembers = new ArrayList<>();
|
|
|
- divMembers.add(divMember);
|
|
|
-
|
|
|
- Map<String, Object> confirm = new HashMap<>();
|
|
|
- confirm.put("payment_id", order.getTransNo());
|
|
|
- confirm.put("order_no", idGeneratorService.generatorId("payment"));
|
|
|
- confirm.put("confirm_amt", routeOrder.getRouteAmount());
|
|
|
- confirm.put("div_members", divMembers);
|
|
|
- try {
|
|
|
- Map<String, Object> map = Payment.createConfirm(confirm, hfMerchantConfig.getMerKey());
|
|
|
- LOGGER.info("分账信息返回:{}", map);
|
|
|
- routeOrder.setServiceFee(new BigDecimal(map.get("fee_amt").toString()));
|
|
|
- routeOrder.setUpdateTime(date);
|
|
|
- studentPaymentRouteOrderDao.update(routeOrder);
|
|
|
- } catch (Exception e) {
|
|
|
- continue;
|
|
|
- }
|
|
|
+
|
|
|
+ PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(order.getPaymentChannel());
|
|
|
+
|
|
|
+
|
|
|
+ if(hfMerchantConfig == null){
|
|
|
+ hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
|
|
|
+ }
|
|
|
+ if(hfMerchantConfig == null){
|
|
|
+ throw new BizException("机构[{}][{}]商户信息找不到", order.getTenantId(), order.getPaymentChannel());
|
|
|
}
|
|
|
+
|
|
|
+ StudentPaymentRouteOrder studentPaymentRouteOrder = null;
|
|
|
+
|
|
|
+ if(paymentChannel == PaymentChannelEnum.ADAPAY) {
|
|
|
+
|
|
|
+ for (StudentPaymentRouteOrder routeOrder : routeOrders) {
|
|
|
+
|
|
|
+ Map<String, Object> divMember = new HashMap<>();
|
|
|
+ divMember.put("member_id", routeOrder.getMerNo());//分佣账户
|
|
|
+ divMember.put("amount", routeOrder.getRouteAmount().setScale(2, BigDecimal.ROUND_HALF_UP));//分佣金额
|
|
|
+ divMember.put("fee_flag", "Y");
|
|
|
+ if (routeOrder.getMerNo().equals(ConfigInit.merNo)) {
|
|
|
+ divMember.put("member_id", 0);
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> divMembers = new ArrayList<>();
|
|
|
+ divMembers.add(divMember);
|
|
|
+
|
|
|
+ Map<String, Object> confirm = new HashMap<>();
|
|
|
+ confirm.put("payment_id", order.getTransNo());
|
|
|
+ confirm.put("order_no", idGeneratorService.generatorId("payment"));
|
|
|
+ confirm.put("confirm_amt", routeOrder.getRouteAmount());
|
|
|
+ confirm.put("div_members", divMembers);
|
|
|
+ try {
|
|
|
+ Map<String, Object> map = Payment.createConfirm(confirm, hfMerchantConfig.getMerKey());
|
|
|
+ LOGGER.info("分账信息返回:{}", map);
|
|
|
+ routeOrder.setServiceFee(new BigDecimal(map.get("fee_amt").toString()));
|
|
|
+ routeOrder.setUpdateTime(date);
|
|
|
+ studentPaymentRouteOrderDao.update(routeOrder);
|
|
|
+ } catch (Exception e) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (paymentChannel == PaymentChannelEnum.YEEPAY) {
|
|
|
+ try {
|
|
|
+ Map<String, Object> params = new HashMap<String, Object>();
|
|
|
+ params.put("parentMerchantNo", hfMerchantConfig.getPlatformPayeeMemberId());
|
|
|
+ params.put("merchantNo", hfMerchantConfig.getPlatformPayeeMemberId());
|
|
|
+ params.put("orderId", order.getOrderNo());
|
|
|
+ params.put("uniqueOrderNo", order.getTransNo());
|
|
|
+ params.put("divideRequestId", idGeneratorService.generatorId("payment") + "");
|
|
|
+
|
|
|
+ Map<String, Object> orderInfo = yeepayPaymentService.queryOrder(hfMerchantConfig, order.getMerNos(), order.getOrderNo());
|
|
|
+ if (orderInfo == null) {
|
|
|
+ throw new BizException("[{}][{}]订单查询失败", paymentChannel, order.getOrderNo());
|
|
|
+ }
|
|
|
+ BigDecimal splitAmount = new BigDecimal(orderInfo.get("unSplitAmount").toString());
|
|
|
+
|
|
|
+ BigDecimal divideAmount = BigDecimal.ZERO;
|
|
|
+ BigDecimal dividedAmount = BigDecimal.ZERO;
|
|
|
+ List<Map<String,String>> divides = new ArrayList<Map<String,String>>();
|
|
|
+ for (int i = 0; i < routeOrders.size(); i++) {
|
|
|
+
|
|
|
+ studentPaymentRouteOrder = routeOrders.get(i);
|
|
|
+
|
|
|
+ Map<String, String> divide = new HashMap<String, String>();
|
|
|
+
|
|
|
+ divide.put("ledgerNo", studentPaymentRouteOrder.getMerNo());
|
|
|
+
|
|
|
+ if (i + 1 == routeOrders.size()) {
|
|
|
+ divideAmount = splitAmount.subtract(dividedAmount);
|
|
|
+ divide.put("amount", divideAmount.toPlainString());
|
|
|
+ } else {
|
|
|
+ divideAmount = studentPaymentRouteOrder.getRouteAmount().multiply(splitAmount).divide(order.getActualAmount(), 2,
|
|
|
+ BigDecimal.ROUND_HALF_UP);
|
|
|
+ divide.put("amount", divideAmount.toPlainString());
|
|
|
+ }
|
|
|
+ dividedAmount = dividedAmount.add(divideAmount);
|
|
|
+
|
|
|
+ studentPaymentRouteOrder.setServiceFee(studentPaymentRouteOrder.getRouteAmount().subtract(divideAmount));
|
|
|
+ studentPaymentRouteOrder.setUpdateTime(date);
|
|
|
+
|
|
|
+ divides.add(divide);
|
|
|
+ }
|
|
|
+ params.put("divideDetail", JSON.toJSONString(divides));
|
|
|
+
|
|
|
+ Map<String, Object> result = yeepayPaymentService.divide(hfMerchantConfig, params);
|
|
|
+ LOGGER.info("分账信息返回:{}", JSON.toJSONString(result));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new BizException("调用易宝接口报错", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (StudentPaymentRouteOrder spro : routeOrders) {
|
|
|
+
|
|
|
+ studentPaymentRouteOrderDao.update(spro);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -701,7 +877,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(id);
|
|
|
List<StudentPaymentOrder> orderList = new ArrayList<>();
|
|
|
orderList.add(studentPaymentOrder);
|
|
|
- if (studentPaymentOrder.getPaymentChannel().equals("ADAPAY")) {
|
|
|
+ if (studentPaymentOrder.getPaymentChannel().equals(PaymentChannelEnum.ADAPAY.getCode()) || studentPaymentOrder.getPaymentChannel().equals(PaymentChannelEnum.YEEPAY.getCode())) {
|
|
|
adaPayQuery(orderList);
|
|
|
} else if (studentPaymentOrder.getPaymentChannel().equals("YQPAY")) {
|
|
|
yqPayQuery(orderList);
|
|
@@ -813,11 +989,13 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
if (StringUtils.isBlank(transNo)) {
|
|
|
return PayStatus.FAILED;
|
|
|
}
|
|
|
+
|
|
|
+ HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(studentPaymentOrder.getTenantId(), studentPaymentOrder.getPaymentChannel());
|
|
|
+ if(hfMerchantConfig == null){
|
|
|
+ throw new BizException("机构[{}]汇付商户信息找不到", studentPaymentOrder.getTenantId());
|
|
|
+ }
|
|
|
+
|
|
|
if (StringUtils.equals(paymentChannel, "ADAPAY")) {
|
|
|
- HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(studentPaymentOrder.getTenantId());
|
|
|
- if(hfMerchantConfig == null){
|
|
|
- throw new BizException("机构[{}]汇付商户信息找不到", studentPaymentOrder.getTenantId());
|
|
|
- }
|
|
|
Map<String, Object> payment = Payment.queryPayment(transNo, hfMerchantConfig.getMerKey());
|
|
|
String status = (String) payment.get("status");
|
|
|
if (status.equals("succeeded")) {
|
|
@@ -852,6 +1030,24 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }else if (StringUtils.equals(paymentChannel, "YEEPAY")) {
|
|
|
+ Map<String, Object> result = yeepayPaymentService.queryOrder(hfMerchantConfig, studentPaymentOrder.getMerNos(), orderNo);
|
|
|
+
|
|
|
+ if("OPR00000".equals(result.get("code").toString())) {
|
|
|
+
|
|
|
+ String status = result.get("status").toString();
|
|
|
+ if (status.equals("SUCCESS")) {
|
|
|
+ return PayStatus.SUCCESSED;
|
|
|
+ } else if (status.equals("TIME_OUT") || status.equals("FAIL") || status.equals("CLOSE")) {
|
|
|
+ return PayStatus.FAILED;
|
|
|
+ } else {
|
|
|
+ return PayStatus.PAYING;
|
|
|
+ }
|
|
|
+ }else if("OPR12002".equals(result.get("code").toString())) {
|
|
|
+ //订单不存在
|
|
|
+ return PayStatus.FAILED;
|
|
|
+ }
|
|
|
+ throw new BizException(result.get("message").toString());
|
|
|
}
|
|
|
throw new BizException("支付渠道错误");
|
|
|
}
|
|
@@ -1613,7 +1809,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
public OrderCancelModel cancelOrder(StudentPaymentOrder order, String reason) {
|
|
|
OrderCancelModel model = new OrderCancelModel();
|
|
|
try {
|
|
|
- HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId());
|
|
|
+ HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
throw new BizException("机构[{}]汇付商户信息找不到", order.getTenantId());
|
|
|
}
|
|
@@ -1653,7 +1849,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
throw new BizException("0元订单");
|
|
|
}
|
|
|
|
|
|
- HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(orderByOrderNo.getTenantId());
|
|
|
+ HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(orderByOrderNo.getTenantId(), orderByOrderNo.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
throw new BizException("请配置机构的汇付商户信息");
|
|
|
}
|