处理学习培训订单

This commit is contained in:
HaoWang 2023-12-01 10:51:16 +08:00
parent feadb4510b
commit 8789793dd5
2 changed files with 134 additions and 14 deletions

View File

@ -20,12 +20,14 @@ import com.xinelu.manage.domain.appointmentorder.AppointmentOrder;
import com.xinelu.manage.domain.goodsOrder.GoodsOrder; import com.xinelu.manage.domain.goodsOrder.GoodsOrder;
import com.xinelu.manage.domain.paymentinfo.PaymentInfo; import com.xinelu.manage.domain.paymentinfo.PaymentInfo;
import com.xinelu.manage.domain.refundinfo.RefundInfo; import com.xinelu.manage.domain.refundinfo.RefundInfo;
import com.xinelu.manage.domain.trainingorder.TrainingOrder;
import com.xinelu.manage.mapper.appointmentorder.AppointmentOrderMapper; import com.xinelu.manage.mapper.appointmentorder.AppointmentOrderMapper;
import com.xinelu.manage.mapper.goodsAttributeDetails.GoodsAttributeDetailsMapper; import com.xinelu.manage.mapper.goodsAttributeDetails.GoodsAttributeDetailsMapper;
import com.xinelu.manage.mapper.goodsOrder.GoodsOrderMapper; import com.xinelu.manage.mapper.goodsOrder.GoodsOrderMapper;
import com.xinelu.manage.mapper.patientcouponreceive.PatientCouponReceiveMapper; import com.xinelu.manage.mapper.patientcouponreceive.PatientCouponReceiveMapper;
import com.xinelu.manage.mapper.paymentinfo.PaymentInfoMapper; import com.xinelu.manage.mapper.paymentinfo.PaymentInfoMapper;
import com.xinelu.manage.mapper.refundinfo.RefundInfoMapper; import com.xinelu.manage.mapper.refundinfo.RefundInfoMapper;
import com.xinelu.manage.mapper.trainingorder.TrainingOrderMapper;
import com.xinelu.manage.vo.AppointOrderAndDetailsInfo; import com.xinelu.manage.vo.AppointOrderAndDetailsInfo;
import com.xinelu.manage.vo.appointmentorder.AppointmentOrderInfoVO; import com.xinelu.manage.vo.appointmentorder.AppointmentOrderInfoVO;
import com.xinelu.manage.vo.goods.GoodsOrderAndDetailsInfo; import com.xinelu.manage.vo.goods.GoodsOrderAndDetailsInfo;
@ -82,6 +84,9 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
@Resource @Resource
private PatientCouponReceiveMapper patientCouponReceiveMapper; private PatientCouponReceiveMapper patientCouponReceiveMapper;
@Resource
private TrainingOrderMapper trainingOrderMapper;
/** /**
* 支付回调标识 * 支付回调标识
*/ */
@ -202,10 +207,22 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
} }
TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition()); TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
try { try {
//记录学习培训订单支付日志和修改订单状态
TrainingOrder trainingOrderInfo = trainingOrderMapper.getTrainingOrderInfoByOrderNo(notifyPlaintext.getOutTradeNo());
if (Objects.nonNull(trainingOrderInfo)) {
insertPaymentInfo(notifyPlaintext, null, null, trainingOrderInfo, plainText);
if (WeChatTradeStateEnum.SUCCESS.getInfo().equals(notifyPlaintext.getTradeState())) {
trainingOrderMapper.updateTrainingOrderStatus(TrainingOrderStatusEnum.PAY.getInfo(), trainingOrderInfo.getTrainingOrderNo());
} else {
log.info("学习培训微信订单状态异常,订单状态为 ====> {}", notifyPlaintext.getTradeState());
}
transactionManager.commit(transactionStatus);
return;
}
//商品订单信息 //商品订单信息
GoodsOrder goodsOrderInfo = goodsOrderMapper.getGoodsOrderByOrderNo(notifyPlaintext.getOutTradeNo()); GoodsOrder goodsOrderInfo = goodsOrderMapper.getGoodsOrderByOrderNo(notifyPlaintext.getOutTradeNo());
if (Objects.nonNull(goodsOrderInfo)) { if (Objects.nonNull(goodsOrderInfo)) {
insertPaymentInfo(notifyPlaintext, goodsOrderInfo, null, plainText); insertPaymentInfo(notifyPlaintext, goodsOrderInfo, null,null, plainText);
if (WeChatTradeStateEnum.SUCCESS.getInfo().equals(notifyPlaintext.getTradeState())) { if (WeChatTradeStateEnum.SUCCESS.getInfo().equals(notifyPlaintext.getTradeState())) {
goodsOrderMapper.updateGoodsOrderStatus(GooodsOrderStatusEnum.WAIT_RECEIVED_GOODS.getInfo(), goodsOrderInfo.getOrderNo()); goodsOrderMapper.updateGoodsOrderStatus(GooodsOrderStatusEnum.WAIT_RECEIVED_GOODS.getInfo(), goodsOrderInfo.getOrderNo());
} else { } else {
@ -219,7 +236,7 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
return; return;
} }
//预约服务订单信息 //预约服务订单信息
insertPaymentInfo(notifyPlaintext, null, appointmentOrderInfo, plainText); insertPaymentInfo(notifyPlaintext, null, appointmentOrderInfo,null, plainText);
if (WeChatTradeStateEnum.SUCCESS.getInfo().equals(notifyPlaintext.getTradeState())) { if (WeChatTradeStateEnum.SUCCESS.getInfo().equals(notifyPlaintext.getTradeState())) {
appointmentOrderMapper.updateAppointmentOrderStatus(OrderStatusEnum.WAIT_DISPATCH.getInfo(), appointmentOrderInfo.getOrderNo()); appointmentOrderMapper.updateAppointmentOrderStatus(OrderStatusEnum.WAIT_DISPATCH.getInfo(), appointmentOrderInfo.getOrderNo());
} else { } else {
@ -245,10 +262,10 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
* @param plainText 回调明文 * @param plainText 回调明文
*/ */
private void insertPaymentInfo(WeChatPayNotifyPlaintextVO notifyPlaintext, GoodsOrder goodsOrderInfo, private void insertPaymentInfo(WeChatPayNotifyPlaintextVO notifyPlaintext, GoodsOrder goodsOrderInfo,
AppointmentOrder appointmentOrder, String plainText) { AppointmentOrder appointmentOrder,TrainingOrder trainingOrderInfo, String plainText) {
int paymentInfoCount = paymentInfoMapper.getPaymentInfoByOrderNo(notifyPlaintext.getOutTradeNo()); int paymentInfoCount = paymentInfoMapper.getPaymentInfoByOrderNo(notifyPlaintext.getOutTradeNo());
if (paymentInfoCount <= 0) { if (paymentInfoCount <= 0) {
PaymentInfo paymentInfo = buildPaymentInfo(notifyPlaintext, goodsOrderInfo, appointmentOrder, plainText); PaymentInfo paymentInfo = buildPaymentInfo(notifyPlaintext, goodsOrderInfo, appointmentOrder,trainingOrderInfo, plainText);
int insertCount = paymentInfoMapper.insertPaymentInfo(paymentInfo); int insertCount = paymentInfoMapper.insertPaymentInfo(paymentInfo);
if (insertCount <= 0) { if (insertCount <= 0) {
log.error("记录支付日志出错,参数为 ====> [{}]", paymentInfo); log.error("记录支付日志出错,参数为 ====> [{}]", paymentInfo);
@ -265,7 +282,7 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
* @param appointmentOrderInfo 预约订单信息 * @param appointmentOrderInfo 预约订单信息
*/ */
private PaymentInfo buildPaymentInfo(WeChatPayNotifyPlaintextVO notifyPlaintext, GoodsOrder goodsOrderInfo, private PaymentInfo buildPaymentInfo(WeChatPayNotifyPlaintextVO notifyPlaintext, GoodsOrder goodsOrderInfo,
AppointmentOrder appointmentOrderInfo, String plainText) { AppointmentOrder appointmentOrderInfo,TrainingOrder trainingOrder, String plainText) {
PaymentInfo paymentInfo = new PaymentInfo(); PaymentInfo paymentInfo = new PaymentInfo();
if (Objects.nonNull(goodsOrderInfo)) { if (Objects.nonNull(goodsOrderInfo)) {
paymentInfo.setPatientId(Objects.isNull(goodsOrderInfo.getPatientId()) ? null : goodsOrderInfo.getPatientId()); paymentInfo.setPatientId(Objects.isNull(goodsOrderInfo.getPatientId()) ? null : goodsOrderInfo.getPatientId());
@ -275,6 +292,10 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
paymentInfo.setPatientId(Objects.isNull(appointmentOrderInfo.getPatientId()) ? null : appointmentOrderInfo.getPatientId()); paymentInfo.setPatientId(Objects.isNull(appointmentOrderInfo.getPatientId()) ? null : appointmentOrderInfo.getPatientId());
paymentInfo.setOrderNo(StringUtils.isBlank(appointmentOrderInfo.getOrderNo()) ? "" : appointmentOrderInfo.getOrderNo()); paymentInfo.setOrderNo(StringUtils.isBlank(appointmentOrderInfo.getOrderNo()) ? "" : appointmentOrderInfo.getOrderNo());
paymentInfo.setPayChannel(StringUtils.isBlank(appointmentOrderInfo.getOrderChannel()) ? "" : appointmentOrderInfo.getOrderChannel()); paymentInfo.setPayChannel(StringUtils.isBlank(appointmentOrderInfo.getOrderChannel()) ? "" : appointmentOrderInfo.getOrderChannel());
} else if (Objects.nonNull(trainingOrder)) {
paymentInfo.setNurseStationPersonId(Objects.isNull(trainingOrder.getNurseStationPersonId()) ? null : trainingOrder.getNurseStationPersonId());
paymentInfo.setOrderNo(StringUtils.isBlank(trainingOrder.getTrainingOrderNo()) ? "" : trainingOrder.getTrainingOrderNo());
paymentInfo.setPayChannel(StringUtils.isBlank(trainingOrder.getTrainingOrderChannel()) ? "" : trainingOrder.getTrainingOrderChannel());
} }
paymentInfo.setTransactionNo(StringUtils.isBlank(notifyPlaintext.getTransactionId()) ? "" : notifyPlaintext.getTransactionId()); paymentInfo.setTransactionNo(StringUtils.isBlank(notifyPlaintext.getTransactionId()) ? "" : notifyPlaintext.getTransactionId());
paymentInfo.setPayPrice(BigDecimal.valueOf(Objects.isNull(notifyPlaintext.getAmount().getPayerTotal()) ? 0 : notifyPlaintext.getAmount().getPayerTotal()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN)); paymentInfo.setPayPrice(BigDecimal.valueOf(Objects.isNull(notifyPlaintext.getAmount().getPayerTotal()) ? 0 : notifyPlaintext.getAmount().getPayerTotal()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_DOWN));
@ -306,6 +327,14 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition()); TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
RedisAtomicLong redisAtomicLong = null; RedisAtomicLong redisAtomicLong = null;
try { try {
//处理学习培训订单退款信息
TrainingOrder trainingOrderInfo = trainingOrderMapper.getTrainingOrderInfoByOrderNo(refundNotifyVO.getOutTradeNo());
if (Objects.nonNull(trainingOrderInfo)) {
handleRefundTrainingOrderNo(trainingOrderInfo, plainText, refundNotifyVO);
transactionManager.commit(transactionStatus);
return;
}
GoodsOrderAndDetailsInfo detailsOrderInfo = goodsOrderMapper.getGoodsAndDetailsOrderInfo(refundNotifyVO.getOutTradeNo()); GoodsOrderAndDetailsInfo detailsOrderInfo = goodsOrderMapper.getGoodsAndDetailsOrderInfo(refundNotifyVO.getOutTradeNo());
AppointOrderAndDetailsInfo appointmentOrderInfo = appointmentOrderMapper.getAppointOrderAndDetailsInfo(refundNotifyVO.getOutTradeNo()); AppointOrderAndDetailsInfo appointmentOrderInfo = appointmentOrderMapper.getAppointOrderAndDetailsInfo(refundNotifyVO.getOutTradeNo());
if (Objects.isNull(detailsOrderInfo) && Objects.isNull(appointmentOrderInfo)) { if (Objects.isNull(detailsOrderInfo) && Objects.isNull(appointmentOrderInfo)) {
@ -434,4 +463,33 @@ public class WeChatPayNotifyServiceImpl implements WeChatPayNotifyService {
refundInfo.setOutRefundNo(StringUtils.isBlank(refundNotifyVO.getOutRefundNo()) ? "" : refundNotifyVO.getOutRefundNo()); refundInfo.setOutRefundNo(StringUtils.isBlank(refundNotifyVO.getOutRefundNo()) ? "" : refundNotifyVO.getOutRefundNo());
return refundInfo; return refundInfo;
} }
/**
* 处理学习培训订单回调信息
*
* @param trainingOrder 学习培训订单信息
* @param plainText 明文
* @param refundNotifyVO 退款回调信息
*/
private void handleRefundTrainingOrderNo(TrainingOrder trainingOrder, String plainText, WeChatRefundNotifyVO refundNotifyVO) {
if (RefundStatusEnum.SUCCESS.getInfo().equals(refundNotifyVO.getRefundStatus())
&& StringUtils.isNotBlank(trainingOrder.getTrainingOrderStatus())
&& !(TrainingOrderStatusEnum.REFUNDED.getInfo().equals(trainingOrder.getTrainingOrderStatus()))) {
int updateCount = trainingOrderMapper.updateTrainingOrderStatus(TrainingOrderStatusEnum.REFUNDED.getInfo(), trainingOrder.getTrainingOrderNo());
if (updateCount < 1) {
log.info("微信退款通知,修改学习培训订单状态失败,订单编号 =====> {}", refundNotifyVO.getOutTradeNo());
}
//修改退款信息
RefundInfo refundInfo = buildRefundInfo(plainText, refundNotifyVO);
int refundCount = refundInfoMapper.updateRefundInfoByNo(refundInfo);
if (refundCount < 1) {
log.info("微信退款通知,记录学习培训微信退款单信息失败,订单编号 =====> {}", refundNotifyVO.getOutTradeNo());
}
}
if (RefundStatusEnum.CLOSED.getInfo().equals(refundNotifyVO.getRefundStatus())) {
log.info("当前学习培训退款单已经关闭,订单号 ====> {}, 退款单号 =====> {}", refundNotifyVO.getOutTradeNo(), refundNotifyVO.getOutRefundNo());
}
if (RefundStatusEnum.ABNORMAL.getInfo().equals(refundNotifyVO.getRefundStatus())) {
log.info("学习培训订单退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往【商户平台—>交易中心】,手动处理此笔退款,订单号 ====> {}, 退款单号 =====> {}", refundNotifyVO.getOutTradeNo(), refundNotifyVO.getOutRefundNo());
}
}
} }

View File

@ -17,12 +17,14 @@ import com.xinelu.manage.domain.goodsOrder.GoodsOrder;
import com.xinelu.manage.domain.patientintegralchange.PatientIntegralChange; import com.xinelu.manage.domain.patientintegralchange.PatientIntegralChange;
import com.xinelu.manage.domain.refundinfo.RefundInfo; import com.xinelu.manage.domain.refundinfo.RefundInfo;
import com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail; import com.xinelu.manage.domain.scheduleplandetail.SchedulePlanDetail;
import com.xinelu.manage.domain.trainingorder.TrainingOrder;
import com.xinelu.manage.dto.consultationInfo.ConsultationInfoDTO; import com.xinelu.manage.dto.consultationInfo.ConsultationInfoDTO;
import com.xinelu.manage.mapper.appointmentorder.AppointmentOrderMapper; import com.xinelu.manage.mapper.appointmentorder.AppointmentOrderMapper;
import com.xinelu.manage.mapper.goodsOrder.GoodsOrderMapper; import com.xinelu.manage.mapper.goodsOrder.GoodsOrderMapper;
import com.xinelu.manage.mapper.patientinfo.PatientInfoMapper; import com.xinelu.manage.mapper.patientinfo.PatientInfoMapper;
import com.xinelu.manage.mapper.patientintegralchange.PatientIntegralChangeMapper; import com.xinelu.manage.mapper.patientintegralchange.PatientIntegralChangeMapper;
import com.xinelu.manage.mapper.refundinfo.RefundInfoMapper; import com.xinelu.manage.mapper.refundinfo.RefundInfoMapper;
import com.xinelu.manage.mapper.trainingorder.TrainingOrderMapper;
import com.xinelu.manage.service.consultationInfo.IConsultationInfoService; import com.xinelu.manage.service.consultationInfo.IConsultationInfoService;
import com.xinelu.manage.service.scheduleplandetail.ISchedulePlanDetailService; import com.xinelu.manage.service.scheduleplandetail.ISchedulePlanDetailService;
import com.xinelu.manage.vo.goodsorder.GoodsInfoRedemptionVO; import com.xinelu.manage.vo.goodsorder.GoodsInfoRedemptionVO;
@ -78,6 +80,8 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
private IConsultationInfoService consultationInfoService; private IConsultationInfoService consultationInfoService;
@Resource @Resource
private ISchedulePlanDetailService planDetailService; private ISchedulePlanDetailService planDetailService;
@Resource
private TrainingOrderMapper trainingOrderMapper;
/** /**
* 成功状态码 * 成功状态码
@ -106,6 +110,11 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
if (StringUtils.isNotBlank(refundDTO.getOrderType()) && StringUtils.equals(OrderTypeEnum.INTEGRAL_EXCHANGE.getInfo(), refundDTO.getOrderType())) { if (StringUtils.isNotBlank(refundDTO.getOrderType()) && StringUtils.equals(OrderTypeEnum.INTEGRAL_EXCHANGE.getInfo(), refundDTO.getOrderType())) {
return refundPointsRedemption(refundDTO); return refundPointsRedemption(refundDTO);
} }
//学习培训订单状态退款处理
if (StringUtils.isNotBlank(refundDTO.getTrainingOrderFlag()) && StringUtils.equals(BuySourceEnum.TRAINING.getInfo(), refundDTO.getTrainingOrderFlag())) {
return refundTrainingOrder(refundDTO);
}
AppointmentOrder appointmentOrderInfo = appointmentOrderMapper.getAppointmentOrderByOrderNo(refundDTO.getOrderNo()); AppointmentOrder appointmentOrderInfo = appointmentOrderMapper.getAppointmentOrderByOrderNo(refundDTO.getOrderNo());
if (Objects.nonNull(appointmentOrderInfo)) { if (Objects.nonNull(appointmentOrderInfo)) {
AjaxResult ajaxResult = judgeRefundInfo(appointmentOrderInfo.getCreateTime(), refundDTO.getRefundPrice(), appointmentOrderInfo.getTotalPrice()); AjaxResult ajaxResult = judgeRefundInfo(appointmentOrderInfo.getCreateTime(), refundDTO.getRefundPrice(), appointmentOrderInfo.getTotalPrice());
@ -123,9 +132,9 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
} }
Long patientId = Objects.isNull(appointmentOrderInfo.getPatientId()) ? 0 : appointmentOrderInfo.getPatientId(); Long patientId = Objects.isNull(appointmentOrderInfo.getPatientId()) ? 0 : appointmentOrderInfo.getPatientId();
String outRefundNo = com.xinelu.common.utils.StringUtils.fillZeroByPatientId(patientId, 5) + System.nanoTime(); String outRefundNo = com.xinelu.common.utils.StringUtils.fillZeroByPatientId(patientId, 5) + System.nanoTime();
String refundParam = buildRefundParam(null, appointmentOrderInfo, refundDTO, outRefundNo); String refundParam = buildRefundParam(null, appointmentOrderInfo,null, refundDTO, outRefundNo);
String refundReason = StringUtils.isBlank(refundDTO.getRefundReason()) ? "" : refundDTO.getRefundReason(); String refundReason = StringUtils.isBlank(refundDTO.getRefundReason()) ? "" : refundDTO.getRefundReason();
this.applyWeRefund(refundParam, appointmentOrderInfo, null, patientId, refundReason); this.applyWeRefund(refundParam, appointmentOrderInfo, null,null, patientId, refundReason);
return AjaxResult.success(); return AjaxResult.success();
} }
GoodsOrder goodsOrderInfo = goodsOrderMapper.getGoodsOrderByOrderNo(refundDTO.getOrderNo()); GoodsOrder goodsOrderInfo = goodsOrderMapper.getGoodsOrderByOrderNo(refundDTO.getOrderNo());
@ -145,9 +154,9 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
} }
Long patientId = Objects.isNull(goodsOrderInfo.getPatientId()) ? 0 : goodsOrderInfo.getPatientId(); Long patientId = Objects.isNull(goodsOrderInfo.getPatientId()) ? 0 : goodsOrderInfo.getPatientId();
String outRefundNo = com.xinelu.common.utils.StringUtils.fillZeroByPatientId(patientId, 5) + System.nanoTime(); String outRefundNo = com.xinelu.common.utils.StringUtils.fillZeroByPatientId(patientId, 5) + System.nanoTime();
String refundParam = buildRefundParam(goodsOrderInfo, null, refundDTO, outRefundNo); String refundParam = buildRefundParam(goodsOrderInfo, null,null, refundDTO, outRefundNo);
String refundReason = StringUtils.isBlank(refundDTO.getRefundReason()) ? "" : refundDTO.getRefundReason(); String refundReason = StringUtils.isBlank(refundDTO.getRefundReason()) ? "" : refundDTO.getRefundReason();
this.applyWeRefund(refundParam, null, goodsOrderInfo, patientId, refundReason); this.applyWeRefund(refundParam, null, goodsOrderInfo,null, patientId, refundReason);
return AjaxResult.success(); return AjaxResult.success();
} }
return AjaxResult.success(); return AjaxResult.success();
@ -245,7 +254,7 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
String outRefundNo = com.xinelu.common.utils.StringUtils.fillZeroByPatientId(patientId, 5) + System.nanoTime(); String outRefundNo = com.xinelu.common.utils.StringUtils.fillZeroByPatientId(patientId, 5) + System.nanoTime();
String refundParam = this.buildHealthConsultationRefundParam(goodsOrderInfo, outRefundNo); String refundParam = this.buildHealthConsultationRefundParam(goodsOrderInfo, outRefundNo);
String refundReason = StringUtils.isBlank(closeOrderDTO.getRemark()) ? "" : closeOrderDTO.getRemark(); String refundReason = StringUtils.isBlank(closeOrderDTO.getRemark()) ? "" : closeOrderDTO.getRemark();
this.applyWeRefund(refundParam, null, goodsOrderInfo, patientId, refundReason); this.applyWeRefund(refundParam, null, goodsOrderInfo,null, patientId, refundReason);
// 查询是否为专家咨询订单修改时间段的可预约状态 // 查询是否为专家咨询订单修改时间段的可预约状态
if (goodsOrderInfo.getConsultationInfoId() != null) { if (goodsOrderInfo.getConsultationInfoId() != null) {
ConsultationInfoDTO consultationInfo = consultationInfoService.selectConsultationInfoById(goodsOrderInfo.getConsultationInfoId()); ConsultationInfoDTO consultationInfo = consultationInfoService.selectConsultationInfoById(goodsOrderInfo.getConsultationInfoId());
@ -287,7 +296,7 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
* @param refundDTO 退款参数信息 * @param refundDTO 退款参数信息
* @return 退款申请Json串 * @return 退款申请Json串
*/ */
private String buildRefundParam(GoodsOrder goodsOrderInfo, AppointmentOrder appointmentOrderInfo, private String buildRefundParam(GoodsOrder goodsOrderInfo, AppointmentOrder appointmentOrderInfo,TrainingOrder trainingOrder,
RefundDTO refundDTO, String outRefundNo) { RefundDTO refundDTO, String outRefundNo) {
Map<String, Object> paramMap = new LinkedHashMap<>(); Map<String, Object> paramMap = new LinkedHashMap<>();
paramMap.put("out_trade_no", refundDTO.getOrderNo()); paramMap.put("out_trade_no", refundDTO.getOrderNo());
@ -301,6 +310,15 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
if (Objects.nonNull(goodsOrderInfo) && Objects.isNull(appointmentOrderInfo)) { if (Objects.nonNull(goodsOrderInfo) && Objects.isNull(appointmentOrderInfo)) {
amountMap.put("total", goodsOrderInfo.getTotalPrice().multiply(BigDecimal.valueOf(100)).intValue()); 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"); amountMap.put("currency", "CNY");
paramMap.put("amount", amountMap); paramMap.put("amount", amountMap);
return JSON.toJSONString(paramMap); return JSON.toJSONString(paramMap);
@ -316,7 +334,7 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
* @param refundReason 退款原因 * @param refundReason 退款原因
*/ */
public void applyWeRefund(String refundParam, AppointmentOrder appointmentOrderInfo, public void applyWeRefund(String refundParam, AppointmentOrder appointmentOrderInfo,
GoodsOrder goodsOrderInfo, Long patientId, String refundReason) { GoodsOrder goodsOrderInfo,TrainingOrder trainingOrderInfo, Long patientId, String refundReason) {
String requestUrl = weChatPaymentUrlConfig.getRefundApplyUrl(); String requestUrl = weChatPaymentUrlConfig.getRefundApplyUrl();
HttpPost httpPost = new HttpPost(requestUrl); HttpPost httpPost = new HttpPost(requestUrl);
StringEntity entity = new StringEntity(refundParam, "utf-8"); StringEntity entity = new StringEntity(refundParam, "utf-8");
@ -324,6 +342,11 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
httpPost.setEntity(entity); httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Accept", "application/json");
String refundMerchantType = PaymentMerchantTypeEnum.XINYILU.getInfo(); String refundMerchantType = PaymentMerchantTypeEnum.XINYILU.getInfo();
//学习培训订单使用医路优品账户
Long nursePersonId = Objects.isNull(trainingOrderInfo.getNurseStationPersonId()) ? null : trainingOrderInfo.getNurseStationPersonId();
try (CloseableHttpResponse response = xinYiLuWeChatPayClient.execute(httpPost)) { try (CloseableHttpResponse response = xinYiLuWeChatPayClient.execute(httpPost)) {
if (Objects.isNull(response)) { if (Objects.isNull(response)) {
throw new ServiceException("获取httpclient对象失败"); throw new ServiceException("获取httpclient对象失败");
@ -342,7 +365,7 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
WeChatRefundInfoVO weChatRefundInfoVO = JSONObject.parseObject(body, WeChatRefundInfoVO.class); WeChatRefundInfoVO weChatRefundInfoVO = JSONObject.parseObject(body, WeChatRefundInfoVO.class);
int refundInfoCount = refundInfoMapper.getRefundInfoByOrderNo(weChatRefundInfoVO.getOutTradeNo()); int refundInfoCount = refundInfoMapper.getRefundInfoByOrderNo(weChatRefundInfoVO.getOutTradeNo());
if (refundInfoCount <= 0) { if (refundInfoCount <= 0) {
RefundInfo refundInfo = buildRefundInfo(patientId, weChatRefundInfoVO, refundReason, body, refundMerchantType); RefundInfo refundInfo = buildRefundInfo(patientId, weChatRefundInfoVO, refundReason, body, refundMerchantType,nursePersonId);
int insertCunt = refundInfoMapper.insertRefundInfo(refundInfo); int insertCunt = refundInfoMapper.insertRefundInfo(refundInfo);
if (insertCunt <= 0) { if (insertCunt <= 0) {
throw new ServiceException("记录退款信息失败,请联系管理员!"); throw new ServiceException("记录退款信息失败,请联系管理员!");
@ -363,9 +386,10 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
* @param refundMerchantType 退款账户类型新医路或者医路优品 * @param refundMerchantType 退款账户类型新医路或者医路优品
*/ */
private RefundInfo buildRefundInfo(Long patientId, WeChatRefundInfoVO refundInfoVO, private RefundInfo buildRefundInfo(Long patientId, WeChatRefundInfoVO refundInfoVO,
String refundReason, String refundBody, String refundMerchantType) { String refundReason, String refundBody, String refundMerchantType,Long nursePersonId) {
RefundInfo refundInfo = new RefundInfo(); RefundInfo refundInfo = new RefundInfo();
refundInfo.setPatientId(patientId); refundInfo.setPatientId(patientId);
refundInfo.setNurseStationPersonId(nursePersonId);
refundInfo.setOrderNo(refundInfoVO.getOutTradeNo()); refundInfo.setOrderNo(refundInfoVO.getOutTradeNo());
refundInfo.setRefundNo(refundInfoVO.getRefundId()); refundInfo.setRefundNo(refundInfoVO.getRefundId());
refundInfo.setOutRefundNo(refundInfoVO.getOutRefundNo()); refundInfo.setOutRefundNo(refundInfoVO.getOutRefundNo());
@ -469,4 +493,42 @@ public class WeChatRefundServiceImpl implements WeChatRefundService {
paramMap.put("amount", amountMap); paramMap.put("amount", amountMap);
return JSON.toJSONString(paramMap); return JSON.toJSONString(paramMap);
} }
/**
* 学习培训订单退款处理
*
* @param refundDTO 退款信息
* @return 退款结果
*/
public AjaxResult refundTrainingOrder(RefundDTO refundDTO){
//查询学习培训订单信息
TrainingOrder trainingOrderInfo = trainingOrderMapper.getTrainingOrderInfoByOrderNo(refundDTO.getOrderNo());
if (Objects.isNull(trainingOrderInfo)) {
return AjaxResult.error("当前订单信息不存在,无法进行退款!");
}
//判断订单状态是否为已支付只有支付的订单才能进行退款
if (StringUtils.isBlank(trainingOrderInfo.getTrainingOrderStatus())
|| !(StringUtils.equals(TrainingOrderStatusEnum.PAY.getInfo(), trainingOrderInfo.getTrainingOrderStatus()))) {
return AjaxResult.error("当前订单状态不正确,无法进行退款!");
}
if (Objects.isNull(trainingOrderInfo.getTrainingOrderAmount())) {
return AjaxResult.error("当前订单金额不存在,无法进行退款!");
}
//订单金额为0说明是0元购直接修改修改成订单状态为已退款
if (Objects.nonNull(trainingOrderInfo.getTrainingOrderAmount()) && trainingOrderInfo.getTrainingOrderAmount().compareTo(BigDecimal.ZERO) == 0) {
trainingOrderMapper.updateTrainingOrderStatus(TrainingOrderStatusEnum.REFUNDED.getInfo(), refundDTO.getOrderNo());
log.info("零元购退款信息,无需走微信退款逻辑!");
return AjaxResult.success();
}
//校验订单时间和订单金额
AjaxResult checkResult = judgeRefundInfo(trainingOrderInfo.getTrainingOrderTime(), refundDTO.getRefundPrice(), trainingOrderInfo.getTrainingOrderAmount());
if (Objects.nonNull(checkResult)) {
return checkResult;
}
//调用微信申请退款接口发起退款申请
Long nursePersonId = Objects.isNull(trainingOrderInfo.getNurseStationPersonId()) ? 0 : trainingOrderInfo.getNurseStationPersonId();
String outRefundNo = com.xinelu.common.utils.StringUtils.fillZeroByPatientId(nursePersonId, 5) + System.nanoTime();
String refundParam = buildRefundParam(null, null, trainingOrderInfo, refundDTO, outRefundNo);
this.applyWeRefund(refundParam, null, null, trainingOrderInfo, null, refundDTO.getRefundReason());
return AjaxResult.success();
}
} }