学习培训订单支付业务逻辑修改

This commit is contained in:
纪寒 2023-12-01 13:38:48 +08:00
parent 8789793dd5
commit 8bc6eea4be
4 changed files with 55 additions and 37 deletions

View File

@ -83,7 +83,6 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
private RedisTemplate<String, Object> redisTemplate;
@Resource
private PatientCouponReceiveMapper patientCouponReceiveMapper;
@Resource
private TrainingOrderMapper trainingOrderMapper;
@ -327,7 +326,6 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
RedisAtomicLong redisAtomicLong = null;
try {
//处理学习培训订单退款信息
TrainingOrder trainingOrderInfo = trainingOrderMapper.getTrainingOrderInfoByOrderNo(refundNotifyVO.getOutTradeNo());
if (Objects.nonNull(trainingOrderInfo)) {
@ -463,6 +461,7 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
refundInfo.setOutRefundNo(StringUtils.isBlank(refundNotifyVO.getOutRefundNo()) ? "" : refundNotifyVO.getOutRefundNo());
return refundInfo;
}
/**
* 处理学习培训订单回调信息
*

View File

@ -110,7 +110,6 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
if (StringUtils.isNotBlank(refundDTO.getOrderType()) && StringUtils.equals(OrderTypeEnum.INTEGRAL_EXCHANGE.getInfo(), refundDTO.getOrderType())) {
return refundPointsRedemption(refundDTO);
}
//学习培训订单状态退款处理
if (StringUtils.isNotBlank(refundDTO.getTrainingOrderFlag()) && StringUtils.equals(BuySourceEnum.TRAINING.getInfo(), refundDTO.getTrainingOrderFlag())) {
return refundTrainingOrder(refundDTO);
@ -310,13 +309,8 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
if (Objects.nonNull(goodsOrderInfo) && Objects.isNull(appointmentOrderInfo)) {
amountMap.put("total", goodsOrderInfo.getTotalPrice().multiply(BigDecimal.valueOf(100)).intValue());
}
//学习培训订单使用医路优品账户
if (Objects.nonNull(trainingOrder) && Objects.isNull(goodsOrderInfo) && Objects.isNull(appointmentOrderInfo)) {
//退款回调地址
// paramMap.put("notify_url", ylypWeChatPaymentConfig.getYlypWeChatNotifyUrl() + YINLUYOUPIN_WE_CHAT_REFUND_URL);
//退款金额
amountMap.put("refund", refundDTO.getRefundPrice().multiply(BigDecimal.valueOf(100)).intValue());
//原始订单金额
amountMap.put("total", trainingOrder.getTrainingOrderAmount().multiply(BigDecimal.valueOf(100)).intValue());
}
amountMap.put("currency", "CNY");
@ -342,11 +336,10 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
String refundMerchantType = PaymentMerchantTypeEnum.XINYILU.getInfo();
//学习培训订单使用医路优品账户
Long nursePersonId = Objects.isNull(trainingOrderInfo.getNurseStationPersonId()) ? null : trainingOrderInfo.getNurseStationPersonId();
Long nursePersonId = null;
if (Objects.nonNull(trainingOrderInfo)) {
nursePersonId = Objects.isNull(trainingOrderInfo.getNurseStationPersonId()) ? null : trainingOrderInfo.getNurseStationPersonId();
}
try (CloseableHttpResponse response = xinYiLuWeChatPayClient.execute(httpPost)) {
if (Objects.isNull(response)) {
throw new ServiceException("获取httpclient对象失败");
@ -493,6 +486,7 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
paramMap.put("amount", amountMap);
return JSON.toJSONString(paramMap);
}
/**
* 学习培训订单退款处理
*
@ -505,7 +499,6 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
if (Objects.isNull(trainingOrderInfo)) {
return AjaxResult.error("当前订单信息不存在,无法进行退款!");
}
//判断订单状态是否为已支付只有支付的订单才能进行退款
if (StringUtils.isBlank(trainingOrderInfo.getTrainingOrderStatus())
|| !(StringUtils.equals(TrainingOrderStatusEnum.PAY.getInfo(), trainingOrderInfo.getTrainingOrderStatus()))) {
return AjaxResult.error("当前订单状态不正确,无法进行退款!");
@ -519,7 +512,6 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
log.info("零元购退款信息,无需走微信退款逻辑!");
return AjaxResult.success();
}
//校验订单时间和订单金额
AjaxResult checkResult = judgeRefundInfo(trainingOrderInfo.getTrainingOrderTime(), refundDTO.getRefundPrice(), trainingOrderInfo.getTrainingOrderAmount());
if (Objects.nonNull(checkResult)) {
return checkResult;

View File

@ -89,7 +89,6 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
LocalDateTime localDateTime = LocalDateTime.now().minusHours(2);
List<AppointOrderAndDetailsInfo> appointmentOrderList = appointmentOrderMapper.getWaitPayAppointmentOrderList(localDateTime);
List<GoodsOrderAndDetailsInfo> goodsOrderList = goodsOrderMapper.getWaitPayGoodsOrderList(localDateTime);
//查询学习培训订单信息
List<TrainingOrder> waitPayTrainingOrderList = trainingOrderMapper.getWaitPayTrainingOrderListByTime(localDateTime, TrainingOrderStatusEnum.WAIT_PAY.getInfo());
if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(goodsOrderList) && CollectionUtils.isEmpty(waitPayTrainingOrderList)) {
return;
@ -103,7 +102,6 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
if (CollectionUtils.isNotEmpty(goodsOrderList)) {
processGoodsOrderInfo(goodsOrderList);
}
//处理学习培训订单信息
if (CollectionUtils.isNotEmpty(waitPayTrainingOrderList)) {
handleWaitPayTrainingOrderInfo(waitPayTrainingOrderList);
}
@ -133,7 +131,6 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
public void automaticUpdateOrderStatusTask() throws Exception {
List<AppointmentOrder> appointmentOrderList = appointmentOrderMapper.getWaitPayStatusAppointmentOrderList(OrderStatusEnum.WAIT_PAY.getInfo());
List<GoodsOrder> goodsOrderList = goodsOrderMapper.getWaitPayStatusGoodsOrderList(GooodsOrderStatusEnum.WAIT_PAY.getInfo());
//查询未支付的学习培训订单信息
List<TrainingOrder> waitPayTrainingOrderList = trainingOrderMapper.getWaitPayTrainingOrderList(TrainingOrderStatusEnum.WAIT_PAY.getInfo(), null);
if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(goodsOrderList) && CollectionUtils.isEmpty(waitPayTrainingOrderList)) {
return;
@ -146,7 +143,6 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
if (CollectionUtils.isNotEmpty(goodsOrderList)) {
updateGoodsPaymentInfo(goodsOrderList);
}
//修改学习培训订单状态以及记录支付信息
if (CollectionUtils.isNotEmpty(waitPayTrainingOrderList)) {
handleWaitPayTrainingOrder(waitPayTrainingOrderList);
}
@ -426,9 +422,7 @@ public class PaymentInfoTaskServiceImpl implements PaymentInfoTaskService {
* @throws Exception 异常信息
*/
private void handleWaitPayTrainingOrderInfo(List<TrainingOrder> trainingOrderList) throws Exception {
//本地系统中超过两小时未支付的订单集合
List<String> orderList = Lists.newArrayList();
//微信系统已经关闭状态的订单集合
List<String> closedOrderList = Lists.newArrayList();
for (TrainingOrder trainingOrder : trainingOrderList) {
if (Objects.isNull(trainingOrder) || StringUtils.isBlank(trainingOrder.getTrainingOrderNo())) {

View File

@ -9,7 +9,9 @@ import com.xinelu.manage.mapper.appointmentorder.AppointmentOrderMapper;
import com.xinelu.manage.mapper.goodsOrder.GoodsOrderMapper;
import com.xinelu.manage.mapper.patientcouponreceive.PatientCouponReceiveMapper;
import com.xinelu.manage.mapper.refundinfo.RefundInfoMapper;
import com.xinelu.manage.mapper.trainingorder.TrainingOrderMapper;
import com.xinelu.manage.vo.RefundOrderInfoVO;
import com.xinelu.manage.vo.TrainingRefundOrderVO;
import com.xinelu.quartz.service.RefundInfoTaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
@ -55,6 +57,8 @@ public class RefundInfoTaskServiceImpl implements RefundInfoTaskService {
private RedisTemplate<String, Objects> redisTemplate;
@Resource
private PatientCouponReceiveMapper patientCouponReceiveMapper;
@Resource
private TrainingOrderMapper trainingOrderMapper;
/**
* 自动处理退款状态定时任务每15分钟执行一次
@ -64,7 +68,8 @@ public class RefundInfoTaskServiceImpl implements RefundInfoTaskService {
public void automaticProcessRefundInfo() {
List<RefundOrderInfoVO> appointmentOrderList = appointmentOrderMapper.getRefundAppointmentOrderInfo(OrderStatusEnum.WAIT_REFUND.getInfo(), RefundStatusEnum.PROCESSING.getInfo(), ConfirmRefundStatusEnum.CONFIRMED.getInfo());
List<RefundOrderInfoVO> refundGoodsOrderLit = goodsOrderMapper.getRefundGoodsOrderInfo(GooodsOrderStatusEnum.WAIT_REFUND.getInfo(), RefundStatusEnum.PROCESSING.getInfo(), ConfirmRefundStatusEnum.CONFIRMED.getInfo());
if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(refundGoodsOrderLit)) {
List<TrainingRefundOrderVO> trainingRefundOrderList = trainingOrderMapper.getTrainingRefundOrderList(TrainingOrderStatusEnum.PAY.getInfo(), RefundStatusEnum.PROCESSING.getInfo());
if (CollectionUtils.isEmpty(appointmentOrderList) && CollectionUtils.isEmpty(refundGoodsOrderLit) && CollectionUtils.isEmpty(trainingRefundOrderList)) {
return;
}
TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
@ -76,6 +81,9 @@ public class RefundInfoTaskServiceImpl implements RefundInfoTaskService {
if (CollectionUtils.isNotEmpty(refundGoodsOrderLit)) {
processGoodsRefundInfo(refundGoodsOrderLit);
}
if (CollectionUtils.isNotEmpty(trainingRefundOrderList)) {
handleRefundTrainingOrderInfo(trainingRefundOrderList);
}
transactionManager.commit(transactionStatus);
} catch (Exception e) {
transactionManager.rollback(transactionStatus);
@ -202,4 +210,29 @@ public class RefundInfoTaskServiceImpl implements RefundInfoTaskService {
goodsOrderMapper.updateBatchGoodsOrderStatus(orderNoList, OrderStatusEnum.REFUNDED.getInfo());
}
}
/**
* 处理退款成功的学习培训订单信息
*
* @param trainingRefundOrderList 学习培训订单集合
*/
private void handleRefundTrainingOrderInfo(List<TrainingRefundOrderVO> trainingRefundOrderList) {
List<String> orderNoList = Lists.newArrayList();
for (TrainingRefundOrderVO refundOrderVO : trainingRefundOrderList) {
if (StringUtils.isBlank(refundOrderVO.getTrainingOrderNo()) || StringUtils.isBlank(refundOrderVO.getOutRefundNo())) {
continue;
}
WeChatRefundInfoVO weChatRefundInfoVO = weChatRefundService.queryGoodsOrderRefundStatus(refundOrderVO.getOutRefundNo(), BuySourceEnum.TRAINING.getInfo());
if (StringUtils.isNotBlank(weChatRefundInfoVO.getStatus())
&& RefundStatusEnum.SUCCESS.getInfo().equals(weChatRefundInfoVO.getStatus())) {
orderNoList.add(refundOrderVO.getTrainingOrderNo());
}
log.info("修改学习培训订单微信退款状态和本地订单状态,订单编号=====> {}, 退款单号======> {}", refundOrderVO.getTrainingOrderNo(), refundOrderVO.getOutRefundNo());
LocalDateTime successTime = StringUtils.isBlank(weChatRefundInfoVO.getSuccessTime()) ? LocalDateTime.now() : LocalDateTime.parse(weChatRefundInfoVO.getSuccessTime(), DateTimeFormatter.ISO_DATE_TIME);
refundInfoMapper.updateBatchRefundStatus(refundOrderVO.getTrainingOrderNo(), successTime, weChatRefundInfoVO.getStatus());
}
if (CollectionUtils.isNotEmpty(orderNoList)) {
trainingOrderMapper.updateBatchTrainingOrderStatus(orderNoList, TrainingOrderStatusEnum.REFUNDED.getInfo());
}
}
}