查看订单详情时新增定订单状态校验
This commit is contained in:
parent
8248a31cf9
commit
1a5585d895
@ -5,6 +5,8 @@ import com.ebike.feign.component.FeignTokenInterceptor;
|
||||
import com.ebike.feign.config.ExampleFeignConfiguration;
|
||||
import com.ebike.feign.model.dto.FeignEbikeRefundDto;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@ -15,6 +17,19 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
@FeignClient(name = "ebike-payment", configuration = {ExampleFeignConfiguration.class, FeignTokenInterceptor.class})
|
||||
public interface PaymentFeignClient {
|
||||
|
||||
/**
|
||||
* 用户退款
|
||||
*
|
||||
* @param refundDto 用户退款请求参数
|
||||
*/
|
||||
@PostMapping("wxPayment/refund")
|
||||
JsonResult<?> refund(@RequestBody FeignEbikeRefundDto refundDto);
|
||||
|
||||
/**
|
||||
* 校验用户退款单状态为(退款中)时,是否与微信的订单状态一致
|
||||
*
|
||||
* @param refundId 退款id
|
||||
*/
|
||||
@GetMapping("wxPayment/checkRefundStatus/{refundId}")
|
||||
JsonResult<?> checkRefundStatus(@PathVariable(name = "refundId") Long refundId);
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -24,6 +26,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
@RequestMapping("/wxPayment/notify")
|
||||
public class EbikeWxPayNotifyController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(EbikeWxPayNotifyController.class);
|
||||
@Resource
|
||||
private EbikeWxPayService wxPayService;
|
||||
|
||||
@ -39,6 +42,7 @@ public class EbikeWxPayNotifyController {
|
||||
*/
|
||||
@PostMapping("/pay")
|
||||
public String payNotify(HttpServletRequest request, HttpServletResponse response) {
|
||||
log.info("成功调用微信支付回调,................");
|
||||
EbikeWxHandleNotifyVo r = wxPayService.handlePayNotify(request);
|
||||
if (!r.isSuccess()) {
|
||||
response.setStatus(500);
|
||||
@ -57,6 +61,7 @@ public class EbikeWxPayNotifyController {
|
||||
*/
|
||||
@PostMapping("/refund")
|
||||
public String refundNotify(HttpServletRequest request, HttpServletResponse response) {
|
||||
log.info("成功调用微信退款回调,................");
|
||||
EbikeWxHandleNotifyVo r = wxPayService.handleRefundNotify(request);
|
||||
if (!r.isSuccess()) {
|
||||
response.setStatus(500);
|
||||
|
||||
@ -68,9 +68,9 @@ public class EbikeWxPaymentController {
|
||||
* @param refundId 退款主键id
|
||||
* @return 退款状态信息
|
||||
*/
|
||||
@GetMapping("/queryRefundStatus/{refundId}")
|
||||
public JsonResult<?> queryRefundStatus(@PathVariable(name = "refundId") Long refundId) {
|
||||
EbikeWxHandleNotifyVo notifyVo = wxPayService.queryRefundStatusById(refundId);
|
||||
@GetMapping("/checkRefundStatus/{refundId}")
|
||||
public JsonResult<?> checkRefundStatus(@PathVariable(name = "refundId") Long refundId) {
|
||||
EbikeWxHandleNotifyVo notifyVo = wxPayService.checkRefundStatus(refundId);
|
||||
return JsonResult.success(notifyVo);
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ public interface EbikePaymentService extends IService<EbikePayment> {
|
||||
* @param duration 订单创建时间超过duration分钟,单位分钟
|
||||
* @return 未支付订单列表
|
||||
*/
|
||||
List<EbikePayment> getNoPayOrderByDuration(int duration);
|
||||
List<EbikePayment> getNoPayNotTimeOutOrder(int duration);
|
||||
|
||||
/**
|
||||
* 查询未支付订单, 超时的
|
||||
@ -31,7 +31,7 @@ public interface EbikePaymentService extends IService<EbikePayment> {
|
||||
* @param duration 订单创建时间超过duration分钟,单位分钟
|
||||
* @return 未支付订单列表
|
||||
*/
|
||||
List<EbikePayment> getExpireOrderByDuration(int duration);
|
||||
List<EbikePayment> getNoPayOvertimeOrder(int duration);
|
||||
|
||||
/**
|
||||
* 更新支付状态
|
||||
|
||||
@ -94,12 +94,12 @@ public interface EbikeWxPayService {
|
||||
Refund queryRefundByOutTradeNo(String outTradeNo);
|
||||
|
||||
/**
|
||||
* 通过退款记录主键id查询退款信息状态
|
||||
* 校验退款单状态为(退款时)微信的退款状态
|
||||
*
|
||||
* @param refundId 退款记录主键id
|
||||
* @return 退款状态信息
|
||||
*/
|
||||
EbikeWxHandleNotifyVo queryRefundStatusById(Long refundId);
|
||||
EbikeWxHandleNotifyVo checkRefundStatus(Long refundId);
|
||||
|
||||
/**
|
||||
* 处理支退款回调
|
||||
|
||||
@ -29,7 +29,6 @@ import static com.cdzy.payment.model.entity.table.EbikeOrderDetailTableDef.EBIKE
|
||||
import static com.cdzy.payment.model.entity.table.EbikeOrderTableDef.EBIKE_ORDER;
|
||||
import static com.cdzy.payment.model.entity.table.EbikePaymentTableDef.EBIKE_PAYMENT;
|
||||
import static com.cdzy.payment.model.entity.table.EbikeUserTableDef.EBIKE_USER;
|
||||
import static com.mybatisflex.core.constant.FuncName.*;
|
||||
|
||||
/**
|
||||
* 用户订单支付记录 服务层实现。
|
||||
@ -45,20 +44,20 @@ public class EbikePaymentServiceImpl extends ServiceImpl<EbikePaymentMapper, Ebi
|
||||
private EbikeOrderService ebikeOrderService;
|
||||
|
||||
@Override
|
||||
public List<EbikePayment> getNoPayOrderByDuration(int duration) {
|
||||
// trade_state为2(未支付状态), 并且创建时间超过duration分钟的订单
|
||||
public List<EbikePayment> getNoPayNotTimeOutOrder(int duration) {
|
||||
// 未支付状态(已超时),创建时间 >= 当前时间 - duration 分钟
|
||||
QueryWrapper query = QueryWrapper.create()
|
||||
.where(EBIKE_PAYMENT.TRADE_STATUS.eq(Transaction.TradeStateEnum.NOTPAY.ordinal()))
|
||||
.and(createTimeFilter(duration, "<"));
|
||||
.and(createTimeFilter(duration, ">="));
|
||||
return list(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EbikePayment> getExpireOrderByDuration(int duration) {
|
||||
// trade_state为2(未支付状态), 并且创建时间超过duration分钟的订单
|
||||
public List<EbikePayment> getNoPayOvertimeOrder(int duration) {
|
||||
// 未支付状态(未超时),创建时间 < 当前时间 - duration 分钟
|
||||
QueryWrapper query = QueryWrapper.create()
|
||||
.where(EBIKE_PAYMENT.TRADE_STATUS.eq(Transaction.TradeStateEnum.NOTPAY.ordinal()))
|
||||
.and(createTimeFilter(duration, ">="));
|
||||
.and(createTimeFilter(duration, "<"));
|
||||
return list(query);
|
||||
}
|
||||
|
||||
@ -182,12 +181,9 @@ public class EbikePaymentServiceImpl extends ServiceImpl<EbikePaymentMapper, Ebi
|
||||
* @param operator 比较运算符
|
||||
*/
|
||||
private String createTimeFilter(int duration, String operator) {
|
||||
return String.format("%s(%s, %s(%d)) %s %s()",
|
||||
ADDTIME,
|
||||
return String.format("%s %s CURRENT_TIMESTAMP - INTERVAL '%d minutes'",
|
||||
EBIKE_PAYMENT.CREATE_TIME.getName(),
|
||||
SEC_TO_TIME,
|
||||
duration * 60,
|
||||
operator,
|
||||
NOW);
|
||||
duration);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +74,7 @@ public class EbikeRefundServiceImpl extends ServiceImpl<EbikeRefundMapper, Ebike
|
||||
ebikeRefund.setRefund(refundAmount);
|
||||
}
|
||||
Long orderId = Long.valueOf(refund.getOutTradeNo());
|
||||
log.info("订单Id:{}, 订单状态:{}", orderId, refund.getStatus().ordinal());
|
||||
// 更新订单退款状态
|
||||
switch (refund.getStatus()) {
|
||||
case PROCESSING, CLOSED -> ebikeOrderService.refund(orderId);
|
||||
|
||||
@ -6,7 +6,6 @@ import com.cdzy.payment.enums.PaymentMethod;
|
||||
import com.cdzy.payment.model.entity.EbikePayment;
|
||||
import com.cdzy.payment.model.entity.EbikeRefund;
|
||||
import com.cdzy.payment.model.vo.*;
|
||||
import com.cdzy.payment.service.EbikeOrderService;
|
||||
import com.cdzy.payment.service.EbikePaymentService;
|
||||
import com.cdzy.payment.service.EbikeRefundService;
|
||||
import com.cdzy.payment.service.EbikeWxPayService;
|
||||
@ -82,9 +81,6 @@ public class EbikeWxPayServiceImpl implements EbikeWxPayService {
|
||||
@Resource
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Resource
|
||||
private EbikeOrderService ebikeOrderService;
|
||||
|
||||
@Override
|
||||
public boolean closeOrder(String outTradeNo) {
|
||||
try {
|
||||
@ -482,13 +478,13 @@ public class EbikeWxPayServiceImpl implements EbikeWxPayService {
|
||||
request.setOutRefundNo(outTradeNo);
|
||||
return wxRefundService.queryByOutRefundNo(request);
|
||||
} catch (Exception e) {
|
||||
logError("查询退款订单queryRefundByOutTradeNo", e);
|
||||
logError("查询微信退款订单异常,{}", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EbikeWxHandleNotifyVo queryRefundStatusById(Long refundId) {
|
||||
public EbikeWxHandleNotifyVo checkRefundStatus(Long refundId) {
|
||||
EbikeWxHandleNotifyVo result = new EbikeWxHandleNotifyVo();
|
||||
// 设置初始值
|
||||
result.setSuccess(false);
|
||||
@ -496,7 +492,7 @@ public class EbikeWxPayServiceImpl implements EbikeWxPayService {
|
||||
// 先查本地数据库,如果退款状态不为SUCCESS,需要查询微信支付
|
||||
EbikeRefund ebikeRefund = ebikeRefundService.getById(refundId);
|
||||
if (ebikeRefund == null) {
|
||||
log.error("{}退款订单不存在", refundId);
|
||||
log.error("退款订单{}不存在", refundId);
|
||||
result.setMessage(String.format("{%s}退款订单不存在", refundId));
|
||||
return result;
|
||||
}
|
||||
@ -513,7 +509,7 @@ public class EbikeWxPayServiceImpl implements EbikeWxPayService {
|
||||
if (refund != null && Status.SUCCESS.equals(refund.getStatus())) {
|
||||
result.setSuccess(true);
|
||||
result.setMessage(String.format("退款%s成功", ebikeRefund.getRefundId()));
|
||||
// 更新退款状态
|
||||
// 退款成功更新退款状态
|
||||
ebikeRefundService.updateRefundStatus(refund);
|
||||
return result;
|
||||
} else {
|
||||
|
||||
@ -42,8 +42,8 @@ public class WxPayTask {
|
||||
*/
|
||||
public void checkOrderStatus() {
|
||||
log.info("checkOrderStatus 执行......");
|
||||
// 1. 查询未支付的订单
|
||||
List<EbikePayment> ebikePaymentList = ebikePaymentService.getNoPayOrderByDuration(wxPayConfig.getExpireMinute());
|
||||
// 1. 查询未支付的未超时的订单
|
||||
List<EbikePayment> ebikePaymentList = ebikePaymentService.getNoPayNotTimeOutOrder(wxPayConfig.getExpireMinute());
|
||||
// 2. 遍历订单,查询支付状态
|
||||
for (EbikePayment ebikePayment : ebikePaymentList) {
|
||||
log.warn("未支付的订单号 ===> {}", ebikePayment.getOrderId());
|
||||
@ -62,7 +62,7 @@ public class WxPayTask {
|
||||
public void closeOrder() {
|
||||
log.info("closeOrder 执行......");
|
||||
// 1. 查询未支付的超时订单
|
||||
List<EbikePayment> ebikePaymentList = ebikePaymentService.getExpireOrderByDuration(wxPayConfig.getExpireMinute());
|
||||
List<EbikePayment> ebikePaymentList = ebikePaymentService.getNoPayOvertimeOrder(wxPayConfig.getExpireMinute());
|
||||
// 2. 遍历订单,关闭订单
|
||||
for (EbikePayment ebikePayment : ebikePaymentList) {
|
||||
log.warn("超时未支付的订单号 ===> {}", ebikePayment.getOrderId());
|
||||
|
||||
@ -64,6 +64,10 @@ public class EbikeRefundOrderDetailVo {
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 退款状态
|
||||
*/
|
||||
private Integer refundStatus;
|
||||
|
||||
/**
|
||||
* 起步费用
|
||||
|
||||
@ -213,6 +213,13 @@ public class EbikeRefundServiceImpl extends ServiceImpl<EbikeRefundMapper, Ebike
|
||||
log.error("{} 退款订单不存在", refundId);
|
||||
return null;
|
||||
}
|
||||
// 如果退款单的状态退款中,校验微信订单的退款状态
|
||||
if (detailVo.getRefundStatus() == EbikeRefundStatus.REFUNDING) {
|
||||
JsonResult<?> jsonResult = paymentFeignClient.checkRefundStatus(refundId);
|
||||
if (jsonResult.getCode() != Code.SUCCESS) {
|
||||
throw new EbikeException("获取微信订单退款状态失败");
|
||||
}
|
||||
}
|
||||
//查询订单
|
||||
List<EbikePaymentCostDetailVo> details = orderDetailService.getOrderDetailsByOrderId(detailVo.getOrderId());
|
||||
if (Objects.nonNull(details)) {
|
||||
@ -531,7 +538,8 @@ public class EbikeRefundServiceImpl extends ServiceImpl<EbikeRefundMapper, Ebike
|
||||
EBIKE_USER.NICKNAME.as("username"),
|
||||
EBIKE_USER.MOBILE,
|
||||
EBIKE_REFUND.PROCESS_STATUS,
|
||||
EBIKE_REFUND.REMARK
|
||||
EBIKE_REFUND.REMARK,
|
||||
EBIKE_REFUND.REFUND_STATUS
|
||||
)
|
||||
.leftJoin(EBIKE_PAYMENT).on(EBIKE_PAYMENT.ORDER_ID.eq(EbikeRefundTableDef.EBIKE_REFUND.ORDER_ID))
|
||||
.leftJoin(EBIKE_USER).on(EBIKE_USER.USER_ID.eq(EBIKE_PAYMENT.USER_ID))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user