|
@@ -3,6 +3,12 @@ package com.ym.mec.biz.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.microsvc.toolkit.common.tools.ThreadPool;
|
|
|
+import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
|
|
|
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
|
|
|
+import com.microsvc.toolkit.middleware.payment.common.api.entity.*;
|
|
|
+import com.microsvc.toolkit.middleware.payment.common.api.enums.PaymentStatus;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
@@ -27,18 +33,15 @@ import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
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.yeepay.YeepayPaymentService;
|
|
|
import com.ym.mec.thirdparty.yqpay.*;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
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;
|
|
@@ -46,7 +49,6 @@ import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.*;
|
|
@@ -57,6 +59,7 @@ 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;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrder> implements StudentPaymentOrderService {
|
|
|
|
|
@@ -127,14 +130,10 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
@Resource
|
|
|
private ContractService contractService;
|
|
|
@Resource
|
|
|
- private HfMerchantConfigService hfMerchantConfigService;
|
|
|
- @Resource
|
|
|
private StudentDao studentDao;
|
|
|
@Resource
|
|
|
private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
|
@Resource
|
|
|
- private YeepayPaymentService yeepayPaymentService;
|
|
|
- @Resource
|
|
|
private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
|
|
|
@Resource
|
|
|
private StudentRepairDao studentRepairDao;
|
|
@@ -150,6 +149,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
private MusicGroupPaymentCalenderAddressService musicGroupPaymentCalenderAddressService;
|
|
|
@Resource
|
|
|
private MusicGroupPaymentCalenderMemberService musicGroupPaymentCalenderMemberService;
|
|
|
+ @Resource
|
|
|
+ private PaymentServiceContext paymentServiceContext;
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
@Override
|
|
@@ -157,8 +158,6 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
return studentPaymentOrderDao;
|
|
|
}
|
|
|
|
|
|
- private final static Logger LOGGER = LoggerFactory.getLogger(StudentPaymentOrderServiceImpl.class);
|
|
|
-
|
|
|
@Override
|
|
|
public StudentPaymentOrderDao getDao() {
|
|
|
return studentPaymentOrderDao;
|
|
@@ -356,16 +355,20 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
@Transactional
|
|
|
public OrderCancelModel updateOrderStatus(Date date, StudentPaymentOrder payingOrder) throws Exception {
|
|
|
|
|
|
- HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(payingOrder.getTenantId(), payingOrder.getPaymentChannel());
|
|
|
+ /*HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(payingOrder.getTenantId(), payingOrder.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
throw new BizException("机构[{}]汇付商户信息找不到", payingOrder.getTenantId());
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
- PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(payingOrder.getPaymentChannel());
|
|
|
+// PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(payingOrder.getPaymentChannel());
|
|
|
|
|
|
- OrderCancelModel model = new OrderCancelModel();
|
|
|
- Map<String, Object> payment = new HashMap<String, Object>();
|
|
|
-
|
|
|
+// Map<String, Object> payment = new HashMap<String, Object>();
|
|
|
+ PaymentResp paymentResp = paymentServiceContext.getPaymentService(payingOrder.getPaymentChannel() + "_" + payingOrder.getTenantId())
|
|
|
+ .query(payingOrder.getTransNo(), payingOrder.getOrderNo());
|
|
|
+ if (paymentResp == null) {
|
|
|
+ throw new BizException("订单支付状态获取异常,稍后请重试,transNo:{},orderNo:{},paymentChannel:{}", payingOrder.getTransNo(), payingOrder.getOrderNo(), payingOrder.getPaymentChannel());
|
|
|
+ }
|
|
|
+/*
|
|
|
if(paymentChannel == PaymentChannelEnum.ADAPAY) {
|
|
|
payment = Payment.queryPayment(payingOrder.getTransNo(), hfMerchantConfig.getMerKey());
|
|
|
}else if(paymentChannel == PaymentChannelEnum.YEEPAY) {
|
|
@@ -386,28 +389,33 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
throw new BizException("[{}]支付渠道不支持", payingOrder.getPaymentChannel());
|
|
|
}
|
|
|
|
|
|
- LOGGER.warn("订单[{}]交易主动查询接口返回:{}", payingOrder.getTransNo(), payment);
|
|
|
-
|
|
|
+ LOGGER.warn("订单[{}]交易主动查询接口返回:{}", payingOrder.getTransNo(), payment);*/
|
|
|
Map<String, String> rpMap = new HashMap<>();
|
|
|
rpMap.put("merOrderNo", payingOrder.getOrderNo());
|
|
|
rpMap.put("orderNo", payingOrder.getTransNo());
|
|
|
- rpMap.put("channelType", (String) payment.get("pay_channel"));
|
|
|
- model.setPayChannel((String) payment.get("pay_channel"));
|
|
|
- String status = (String) payment.get("status");
|
|
|
- if (payment.containsKey("error_msg")) {
|
|
|
- rpMap.put("remarks", (String) payment.get("error_msg"));
|
|
|
+ rpMap.put("channelType", paymentResp.getPaymentChannel());
|
|
|
+ OrderCancelModel model = new OrderCancelModel();
|
|
|
+ model.setPayChannel(paymentResp.getPaymentChannel());
|
|
|
+// String status = (String) payment.get("status");
|
|
|
+ if (paymentResp.getPaymentStatus() == PaymentStatus.FAILED || (DateUtil.minutesBetween(DateUtil.addHours(payingOrder.getUpdateTime(), 2),date) > 0)) {
|
|
|
+ rpMap.put("remarks", paymentResp.getMsg());
|
|
|
+ rpMap.put("tradeState", "0");
|
|
|
+ model.setStatus(false);
|
|
|
+ }else if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED) {
|
|
|
+ rpMap.put("tradeState", "1");
|
|
|
+ model.setStatus(true);
|
|
|
}
|
|
|
- if (status.equals("succeeded")) {
|
|
|
+ /*if (status.equals("succeeded")) {
|
|
|
rpMap.put("tradeState", "1");
|
|
|
model.setStatus(true);
|
|
|
} 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") || payingOrder.getCreateTime().before(DateUtil.addMinutes(new Date(), -35)))) {
|
|
|
+ if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED ||
|
|
|
+ (paymentResp.getPaymentStatus() == PaymentStatus.FAILED || payingOrder.getCreateTime().before(DateUtil.addMinutes(new Date(), -35)))) {
|
|
|
try {
|
|
|
updateOrder(rpMap); //更新订单
|
|
|
model.setSuccess(true);
|
|
@@ -501,21 +509,45 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
}
|
|
|
Date date = new Date();
|
|
|
|
|
|
- HfMerchantConfig hfMerchantConfig = null;
|
|
|
-
|
|
|
List<StudentPaymentRouteOrder> routeOrders = studentPaymentRouteOrderService.getDao().getRouteOrders(order.getOrderNo());
|
|
|
-
|
|
|
- PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(order.getPaymentChannel());
|
|
|
-
|
|
|
|
|
|
- if(hfMerchantConfig == null){
|
|
|
- hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
|
|
|
- }
|
|
|
+ /*HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
- throw new BizException("机构[{}][{}]商户信息找不到", order.getTenantId(), order.getPaymentChannel());
|
|
|
+ throw new BizException("机构[{}][{}]商户信息找不到", order.getTenantId(), order.getPaymentChannel());
|
|
|
+ }*/
|
|
|
+ BasePaymentService paymentService = paymentServiceContext.getPaymentService(order.getPaymentChannel() + "_" + order.getTenantId());
|
|
|
+ for (StudentPaymentRouteOrder routeOrder : routeOrders) {
|
|
|
+ if (routeOrder.getRouteAmount().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ routeOrder.setServiceFee(BigDecimal.ZERO);
|
|
|
+ routeOrder.setUpdateTime(date);
|
|
|
+ studentPaymentRouteOrderService.getDao().update(routeOrder);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 执行分账逻辑
|
|
|
+ DivideReq.DivMember divMember = DivideReq.DivMember.builder()
|
|
|
+ .memberId(routeOrder.getMerNo().equals(ConfigInit.merNo) ? "0" : routeOrder.getMerNo())
|
|
|
+ .amount(routeOrder.getRouteAmount().setScale(2, RoundingMode.HALF_UP))
|
|
|
+ .feeFlag("Y")
|
|
|
+ .build();
|
|
|
+ DivideReq divideReq = DivideReq.builder()
|
|
|
+ .transNo(order.getTransNo())
|
|
|
+ .orderNo(order.getOrderNo())
|
|
|
+ .divideOrderNo(idGeneratorService.generatorId("payment") + "")
|
|
|
+ .divideAmount(divMember.getAmount())
|
|
|
+ .divMembers(Lists.newArrayList(divMember))
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ DivideResp divide = paymentService.divide(divideReq);
|
|
|
+ log.info("分账信息返回:{}", divide);
|
|
|
+ routeOrder.setServiceFee(divide.getFeeAmount());
|
|
|
+ routeOrder.setUpdateTime(date);
|
|
|
+ studentPaymentRouteOrderService.getDao().update(routeOrder);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("分账失败 orderId:{}", order.getId(), e);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- StudentPaymentRouteOrder studentPaymentRouteOrder = null;
|
|
|
+
|
|
|
+ /*StudentPaymentRouteOrder studentPaymentRouteOrder = null;
|
|
|
|
|
|
if(paymentChannel == PaymentChannelEnum.ADAPAY) {
|
|
|
|
|
@@ -601,7 +633,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
|
|
|
studentPaymentRouteOrderService.getDao().update(spro);
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -886,12 +918,24 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
return PayStatus.FAILED;
|
|
|
}
|
|
|
|
|
|
- HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(studentPaymentOrder.getTenantId(), studentPaymentOrder.getPaymentChannel());
|
|
|
+ /*HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(studentPaymentOrder.getTenantId(), studentPaymentOrder.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
throw new BizException("机构[{}]汇付商户信息找不到", studentPaymentOrder.getTenantId());
|
|
|
+ }*/
|
|
|
+ PaymentResp paymentResp = paymentServiceContext.getPaymentService(paymentChannel + "_" + studentPaymentOrder.getTenantId())
|
|
|
+ .query(transNo, orderNo);
|
|
|
+ if (paymentResp == null) {
|
|
|
+ throw new BizException("订单支付状态获取异常,稍后请重试,transNo:{},orderNo:{},paymentChannel:{}", transNo, orderNo, paymentChannel);
|
|
|
+ }
|
|
|
+ if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED) {
|
|
|
+ return PayStatus.SUCCESSED;
|
|
|
+ } else if (paymentResp.getPaymentStatus() == PaymentStatus.PENDDING) {
|
|
|
+ return PayStatus.PAYING;
|
|
|
+ }else {
|
|
|
+ return PayStatus.FAILED;
|
|
|
}
|
|
|
-
|
|
|
- if (StringUtils.equals(paymentChannel, "ADAPAY")) {
|
|
|
+
|
|
|
+ /*if (StringUtils.equals(paymentChannel, "ADAPAY")) {
|
|
|
Map<String, Object> payment = Payment.queryPayment(transNo, hfMerchantConfig.getMerKey());
|
|
|
String status = (String) payment.get("status");
|
|
|
if (status.equals("succeeded")) {
|
|
@@ -945,7 +989,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
}
|
|
|
throw new BizException(result.get("message").toString());
|
|
|
}
|
|
|
- throw new BizException("支付渠道错误");
|
|
|
+ throw new BizException("支付渠道错误");*/
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -1071,7 +1115,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
Date nowDate = new Date();
|
|
|
//增加商品库存
|
|
|
List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(order.getId());
|
|
|
- String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
|
|
|
+ String goodsIds = studentPaymentOrderDetailList.stream().map(StudentPaymentOrderDetail::getMinuendStockGoodsIdList)
|
|
|
+ .filter(StringUtils::isNotBlank).collect(Collectors.joining(","));
|
|
|
if(StringUtils.isNotBlank(goodsIds)){
|
|
|
List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
|
|
|
Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
@@ -1091,7 +1136,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
|
|
|
batchUpdateGoodsMap.put(goods.getId(), goods);
|
|
|
}
|
|
|
- if(batchUpdateGoodsMap.size() > 0){
|
|
|
+ if(!batchUpdateGoodsMap.isEmpty()){
|
|
|
goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
|
|
|
}
|
|
|
}
|
|
@@ -1119,9 +1164,9 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
if (studentRegistration.getMusicGroupStatus() == StudentMusicGroupStatusEnum.APPLY) {
|
|
|
List<StudentPaymentOrder> oldStudentPaymentOrderList = this.queryByCondition(GroupType.MUSIC, musicGroupId, userId, SUCCESS, OrderTypeEnum.APPLY);
|
|
|
//判断是否有成功的订单,如果有,表示已经处理过人数
|
|
|
- if (oldStudentPaymentOrderList == null || oldStudentPaymentOrderList.size() == 0) {
|
|
|
+ if (CollectionUtils.isEmpty(oldStudentPaymentOrderList)) {
|
|
|
List<StudentPaymentOrderDetail> orderDetail = studentPaymentOrderDetailService.getOrderDetail(order.getId());
|
|
|
- if (orderDetail != null && orderDetail.size() > 0) {
|
|
|
+ if (CollectionUtils.isNotEmpty(orderDetail)) {
|
|
|
long count = orderDetail.stream().filter(e -> e.getType() == OrderDetailTypeEnum.MUSICAL || e.getType() == OrderDetailTypeEnum.CLOUD_TEACHER).count();
|
|
|
MusicGroup musicGroup = musicGroupService.get(musicGroupId);
|
|
|
//如果购买了乐器或者云教练,或者不是会员团,那么关闭订单时人数减一
|
|
@@ -1327,7 +1372,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
studentGoodsSell.setGoodsJson(model.getOrderInfo());
|
|
|
studentGoodsSell.setOrderNo(model.getOrderNo());
|
|
|
List<Integer> couponIdList = model.getCouponIdList();
|
|
|
- if (couponIdList != null && couponIdList.size() > 0) {
|
|
|
+ if (CollectionUtils.isNotEmpty(couponIdList)) {
|
|
|
studentGoodsSell.setCouponIds(StringUtils.join(couponIdList, ","));
|
|
|
}
|
|
|
studentGoodsSell.setTenantId(student.getTenantId());
|
|
@@ -1418,13 +1463,13 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
long count = goodsOrderItemVOS.stream().filter(e -> StringUtils.isEmpty(e.getOrderSn())).count();
|
|
|
//如果有空的商品货号,不处理
|
|
|
if(count == 0l){
|
|
|
- List<String> productSns = goodsOrderItemVOS.stream().map(e -> e.getProductSn()).distinct().collect(Collectors.toList());
|
|
|
+ List<String> productSns = goodsOrderItemVOS.stream().map(GoodsOrderItemVO::getProductSn).distinct().collect(Collectors.toList());
|
|
|
List<Goods> goodsList = goodsService.getGoodsDao().findBySns(productSns);
|
|
|
//如果有不匹配的商品货号,不处理
|
|
|
if(CollectionUtils.isEmpty(goodsList) || goodsList.size() < productSns.size()){
|
|
|
return;
|
|
|
}
|
|
|
- Map<String, Goods> goodsSnMap = goodsList.stream().collect(Collectors.groupingBy(e -> e.getSn(),
|
|
|
+ Map<String, Goods> goodsSnMap = goodsList.stream().collect(Collectors.groupingBy(Goods::getSn,
|
|
|
Collectors.collectingAndThen(Collectors.toList(), v -> v.get(0))));
|
|
|
List<StudentPaymentOrderDetail> orderDetails = new ArrayList<>();
|
|
|
List<SellOrder> sellOrders = new ArrayList<>();
|
|
@@ -1685,12 +1730,52 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public OrderCancelModel cancelOrder(StudentPaymentOrder order, String reason) {
|
|
|
OrderCancelModel model = new OrderCancelModel();
|
|
|
model.setSuccess(true);
|
|
|
try {
|
|
|
- HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
|
|
|
+ String errorMessage = null;
|
|
|
+ BasePaymentService paymentService = paymentServiceContext.getPaymentService(order.getPaymentChannel() + "_" + order.getTenantId());
|
|
|
+ if (paymentService == null) {
|
|
|
+ throw new BizException("支付渠道不支持:{}", order.getPaymentChannel());
|
|
|
+ }
|
|
|
+ PaymentResp paymentResp = paymentService.query(order.getTransNo(), order.getOrderNo());
|
|
|
+ if (paymentResp == null) {
|
|
|
+ throw new BizException("订单支付状态获取异常,稍后请重试,transNo:{},orderNo:{},paymentChannel:{}", order.getTransNo(), order.getOrderNo(), order.getPaymentChannel());
|
|
|
+ }
|
|
|
+ if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED) {
|
|
|
+ model.setStatus(true);
|
|
|
+ order.setStatus(SUCCESS);
|
|
|
+ } else if (paymentResp.getPaymentStatus() == PaymentStatus.PENDDING) {
|
|
|
+ // 执行关单操作
|
|
|
+ PaymentClose paymentClose = paymentService.close(order.getTransNo(), reason, order.getOrderNo());
|
|
|
+ model.setSuccess(false);
|
|
|
+ if (Objects.nonNull(paymentClose)) {
|
|
|
+ model.setMessage(paymentClose.getMsg());
|
|
|
+ errorMessage = paymentClose.getMsg();
|
|
|
+ // 订单取消,三方返回异常信息
|
|
|
+ if (StringUtils.isNotEmpty(errorMessage)) {
|
|
|
+ log.warn("cancelPayment orderNo={}, ex={}", order.getOrderNo(), errorMessage);
|
|
|
+ // 记录异常消息
|
|
|
+ ThreadPool.getExecutor().submit(() -> {
|
|
|
+ order.setMemo(paymentClose.getMsg());
|
|
|
+ // 更新订单关单异常信息
|
|
|
+ studentPaymentOrderDao.update(order);
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ model.setSuccess(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ model.setStatus(false);
|
|
|
+ order.setStatus(CLOSE);
|
|
|
+ }else {
|
|
|
+ model.setStatus(false);
|
|
|
+ order.setStatus(CLOSE);
|
|
|
+ order.setMemo(reason);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
throw new BizException("机构[{}]汇付商户信息找不到", order.getTenantId());
|
|
|
}
|
|
@@ -1738,7 +1823,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
order.setStatus(CLOSE);
|
|
|
model.setSuccess(success);
|
|
|
model.setMessage(closeInfo.get("msg"));
|
|
|
- }
|
|
|
+ }*/
|
|
|
if (model.getSuccess()) {
|
|
|
TenantContextHolder.setTenantId(order.getTenantId());
|
|
|
callOrderCallBack(order);
|
|
@@ -1753,23 +1838,43 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public BaseResult<Map<String, Object>> refund(String orderNo, String notifyUrl, String refundNo) {
|
|
|
|
|
|
- StudentPaymentOrder orderByOrderNo = this.findOrderByOrderNo(orderNo);
|
|
|
- if (orderByOrderNo == null) {
|
|
|
+ StudentPaymentOrder paymentOrder = this.findOrderByOrderNo(orderNo);
|
|
|
+ if (paymentOrder == null) {
|
|
|
throw new BizException("为找到订单");
|
|
|
}
|
|
|
- if (orderByOrderNo.getActualAmount().compareTo(BigDecimal.ZERO) ==0) {
|
|
|
+ if (paymentOrder.getActualAmount().compareTo(BigDecimal.ZERO) ==0) {
|
|
|
throw new BizException("0元订单");
|
|
|
}
|
|
|
-
|
|
|
+ BasePaymentService paymentService = paymentServiceContext.getPaymentService(paymentOrder.getPaymentChannel() + "_" + paymentOrder.getTenantId());
|
|
|
+ if (paymentService == null) {
|
|
|
+ throw new BizException("支付渠道不支持:{}", paymentOrder.getPaymentChannel());
|
|
|
+ }
|
|
|
+ RefundOrder refundOrder = new RefundOrder();
|
|
|
+ refundOrder.setUserId(paymentOrder.getUserId().toString());
|
|
|
+ refundOrder.setMerOrderNo(refundNo);
|
|
|
+ refundOrder.setRefundAmount(paymentOrder.getActualAmount());
|
|
|
+ refundOrder.setOrderAmount(paymentOrder.getActualAmount());
|
|
|
+ refundOrder.setTransNo(paymentOrder.getTransNo());
|
|
|
+ refundOrder.setPaymentOrderNo(paymentOrder.getOrderNo());
|
|
|
+ RefundResp refundResp = paymentService.refund(refundOrder);
|
|
|
+ // 申请请求失败
|
|
|
+ if (PaymentStatus.FAILED == refundResp.getPaymentStatus()) {
|
|
|
+ return BaseResult.failed(refundResp.getMsg());
|
|
|
+ } else {
|
|
|
+ Map<String,Object> param = new HashMap<>();
|
|
|
+ param.put("refundNo",refundNo);
|
|
|
+ return BaseResult.succeed(param);
|
|
|
+ }
|
|
|
+/*
|
|
|
HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(orderByOrderNo.getTenantId(), orderByOrderNo.getPaymentChannel());
|
|
|
if(hfMerchantConfig == null){
|
|
|
throw new BizException("请配置机构的汇付商户信息");
|
|
|
}
|
|
|
return Payment.reversePayment(orderByOrderNo.getTransNo(),hfMerchantConfig.getAppId(),refundNo,
|
|
|
- orderByOrderNo.getActualAmount().setScale(2,BigDecimal.ROUND_HALF_UP).toString(),notifyUrl);
|
|
|
+ orderByOrderNo.getActualAmount().setScale(2, RoundingMode.HALF_UP).toString(),notifyUrl);*/
|
|
|
}
|
|
|
|
|
|
@Override
|