修改查询订单状态封装
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.hutool.core.io.IoUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.PayCst;
|
||||
import com.czg.PolyPayUtils;
|
||||
import com.czg.constant.PayChannelCst;
|
||||
import com.czg.constants.PayTypeConstants;
|
||||
import com.czg.dto.req.WechatNotifyReqDto;
|
||||
import com.czg.dto.req.WechatPayNotifyDataDto;
|
||||
@@ -77,7 +78,7 @@ public class NotifyController {
|
||||
|
||||
WechatPayNotifyDataDto dataDto = JSONObject.parseObject(decrypted, WechatPayNotifyDataDto.class);
|
||||
PayNotifyRespDTO respDTO = dataDto.convertToPayNotifyRespDTO();
|
||||
orderInfoCustomService.payCallBackOrder(respDTO.getMchOrderNo(), respDTO, 0);
|
||||
orderInfoCustomService.payCallBackOrder(respDTO.getMchOrderNo(), respDTO, PayChannelCst.NATIVE, 0);
|
||||
return "success";
|
||||
} else if (PayCst.Platform.ALIPAY.equalsIgnoreCase(platform)) {
|
||||
// 支付宝
|
||||
@@ -112,7 +113,7 @@ public class NotifyController {
|
||||
PayNotifyRespDTO respDTO = PolyPayUtils.getNotifyResp(respParams);
|
||||
AssertUtil.isNull(respDTO, "支付回调数据为空");
|
||||
log.info("支付回调数据为:{}", respDTO);
|
||||
orderInfoCustomService.payCallBackOrder(respDTO.getMchOrderNo(), respDTO, 0);
|
||||
orderInfoCustomService.payCallBackOrder(respDTO.getMchOrderNo(), respDTO, PayChannelCst.POLY, 0);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.czg.controller.pay;
|
||||
|
||||
import com.czg.annotation.Debounce;
|
||||
import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.pay.QueryOrderRespDTO;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.dto.VipMemberPayParamDTO;
|
||||
import com.czg.service.order.dto.VipPayParamDTO;
|
||||
@@ -10,6 +12,7 @@ import com.czg.service.order.service.PayService;
|
||||
import com.czg.service.order.service.ShopUserPayService;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.czg.utils.ServletUtil;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -32,6 +35,9 @@ public class VipPayController {
|
||||
@Resource
|
||||
private ShopUserPayService shopUserPayService;
|
||||
|
||||
@Resource
|
||||
private OrderPaymentService orderPaymentService;
|
||||
|
||||
/**
|
||||
* 现金充值
|
||||
* 如果shop_info的 is_member_in_pwd=1 则pwd必填 店铺操作密码
|
||||
@@ -168,10 +174,16 @@ public class VipPayController {
|
||||
public CzgResult<String> queryOrderStatus(Long shopId, String payOrderNo) {
|
||||
AssertUtil.isNull(shopId, "店铺id不能为空");
|
||||
AssertUtil.isBlank(payOrderNo, "支付单号不能为空");
|
||||
|
||||
OrderPayment payment = orderPaymentService.getOne(QueryWrapper.create().eq(OrderPayment::getOrderNo, payOrderNo));
|
||||
if (payment == null) {
|
||||
return CzgResult.failure("支付单号不存在");
|
||||
}
|
||||
|
||||
CzgResult<String> result = CzgResult.success();
|
||||
CzgResult<CzgBaseResp> queryPayOrder = payService.queryPayOrder(shopId, null, payOrderNo);
|
||||
if (queryPayOrder.getCode() == 200 && queryPayOrder.getData() != null) {
|
||||
String state = queryPayOrder.getData().getState();
|
||||
CzgResult<QueryOrderRespDTO> queryPayOrder = payService.queryPayOrder(shopId, null, payOrderNo, payment.getPlatformType());
|
||||
if (queryPayOrder.isSuccess() && queryPayOrder.getData() != null) {
|
||||
String state = queryPayOrder.getData().getStatus();
|
||||
result.setData(state);
|
||||
switch (state) {
|
||||
case "TRADE_AWAIT" -> result.setMsg("等待用户付款");
|
||||
|
||||
@@ -44,7 +44,7 @@ public interface OrderInfoCustomService {
|
||||
|
||||
CzgResult<Object> mergeOrder(MergeOrderDTO param);
|
||||
|
||||
void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, int retryCount);
|
||||
void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, String channel, int retryCount);
|
||||
|
||||
void refundCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.czg.pay;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 查询订单响应参数
|
||||
* @author yjjie
|
||||
* @date 2026/1/15 13:56
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class QueryOrderRespDTO {
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 金额
|
||||
*/
|
||||
private Long amount;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 原始响应数据
|
||||
*/
|
||||
private String originResp;
|
||||
}
|
||||
@@ -2,10 +2,7 @@ package com.czg;
|
||||
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.NativeMerchantDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.third.alipay.AlipayIsvPayManager;
|
||||
import com.czg.third.wechat.WechatPayManager;
|
||||
|
||||
@@ -52,11 +49,11 @@ public class PayManager {
|
||||
/**
|
||||
* 查询订单状态
|
||||
*/
|
||||
public static Map<String, Object> queryOrderStatus(String platform, String orderNo, String subMerchantId) {
|
||||
public static QueryOrderRespDTO queryOrderStatus(String platform, String orderNo, NativeMerchantDTO merchantDTO) {
|
||||
if (SystemConstants.PayType.WECHAT.equals(platform)) {
|
||||
return WechatPayManager.queryOrder(null, orderNo, subMerchantId);
|
||||
return WechatPayManager.queryOrder(null, orderNo, merchantDTO);
|
||||
} else if (SystemConstants.PayType.ALIPAY.equals(platform)) {
|
||||
return AlipayIsvPayManager.queryOrder(null, orderNo, subMerchantId);
|
||||
return AlipayIsvPayManager.queryOrder(null, orderNo, merchantDTO);
|
||||
} else {
|
||||
throw new CzgException("不支持的支付平台");
|
||||
}
|
||||
|
||||
@@ -10,10 +10,7 @@ import com.alipay.v3.model.ExtendParams;
|
||||
import com.alipay.v3.util.model.CustomizedParams;
|
||||
import com.czg.PayCst;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.NativeMerchantDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.third.alipay.dto.config.AlipayConfigDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -104,8 +101,8 @@ public class AlipayIsvPayManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Object> queryOrder(AlipayConfigDto configDto, String orderNo, String subMerchantId) {
|
||||
return new HashMap<>();
|
||||
public static QueryOrderRespDTO queryOrder(AlipayConfigDto configDto, String orderNo, NativeMerchantDTO merchantDTO) {
|
||||
return new QueryOrderRespDTO();
|
||||
}
|
||||
|
||||
public static RefundRespDTO refundOrder(AlipayConfigDto configDto, CzgRefundReq paramsDto, String notifyUrl, NativeMerchantDTO merchantDTO) {
|
||||
|
||||
@@ -6,10 +6,7 @@ import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.PayCst;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.NativeMerchantDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.third.wechat.dto.config.WechatPayConfigDto;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.cipher.Signer;
|
||||
@@ -205,7 +202,7 @@ public class WechatPayManager {
|
||||
*
|
||||
* @param configDto 配置
|
||||
* @param orderNo 订单号
|
||||
* @param subMerchantId 子商户号
|
||||
* @param merchantDTO 支付商户信息
|
||||
* SUCCESS:支付成功
|
||||
* REFUND:转入退款
|
||||
* NOTPAY:未支付
|
||||
@@ -214,34 +211,35 @@ public class WechatPayManager {
|
||||
* USERPAYING:用户支付中(仅付款码支付会返回)
|
||||
* PAYERROR:支付失败(仅付款码支付会返回)
|
||||
*/
|
||||
public static Map<String, Object> queryOrder(WechatPayConfigDto configDto, String orderNo, String subMerchantId) {
|
||||
public static QueryOrderRespDTO queryOrder(WechatPayConfigDto configDto, String orderNo, NativeMerchantDTO merchantDTO) {
|
||||
try {
|
||||
if (configDto == null) {
|
||||
configDto = WechatPayConfigDto.getDefaultConfig();
|
||||
}
|
||||
|
||||
String resp = WechatReqUtils.getReq(configDto, "/v3/pay/partner/transactions/out-trade-no/" + orderNo,
|
||||
Map.of("sp_mchid", configDto.getMerchantId(), "sub_mchid", subMerchantId));
|
||||
Map.of("sp_mchid", configDto.getMerchantId(), "sub_mchid", merchantDTO.getWechatMerchantId()));
|
||||
log.info("微信查询订单,订单号:{}, 响应:{}", orderNo, resp);
|
||||
|
||||
JSONObject res = new JSONObject();
|
||||
res.put("orderNo", orderNo);
|
||||
QueryOrderRespDTO queryOrderRespDTO = new QueryOrderRespDTO()
|
||||
.setOrderNo(orderNo)
|
||||
.setOriginResp(resp);
|
||||
|
||||
JSONObject object = JSONObject.parseObject(resp);
|
||||
String tradeState = object.getString("trade_state");
|
||||
res.put("message", object.getString("trade_state_desc"));
|
||||
queryOrderRespDTO.setErrorMsg(object.getString("trade_state_desc"));
|
||||
if (PAY_SUCCESS.equals(tradeState)) {
|
||||
res.put("status", "TRADE_SUCCESS");
|
||||
return res;
|
||||
queryOrderRespDTO.setStatus("TRADE_SUCCESS");
|
||||
return queryOrderRespDTO;
|
||||
}
|
||||
|
||||
if ("USERPAYING".equals(tradeState)) {
|
||||
res.put("status", "TRADE_AWAIT");
|
||||
return res;
|
||||
queryOrderRespDTO.setStatus("TRADE_AWAIT");
|
||||
return queryOrderRespDTO;
|
||||
}
|
||||
|
||||
res.put("status", "TRADE_FAIL");
|
||||
return res;
|
||||
queryOrderRespDTO.setStatus("TRADE_FAIL");
|
||||
return queryOrderRespDTO;
|
||||
} catch (Exception e) {
|
||||
log.error("微信查询订单异常: orderNo = {}, e = {}", orderNo, e.getMessage());
|
||||
throw new CzgException("微信查询订单异常");
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.czg.service.order.service;
|
||||
|
||||
import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.enums.CzgPayEnum;
|
||||
import com.czg.order.dto.LtPayOtherDTO;
|
||||
import com.czg.order.entity.OrderPayment;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.QueryOrderRespDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.resp.CzgResult;
|
||||
import lombok.NonNull;
|
||||
@@ -67,7 +67,7 @@ public interface PayService {
|
||||
* @param payOrderId 平台订单号
|
||||
* @param mchOrderNo 商户订单号
|
||||
*/
|
||||
CzgResult<CzgBaseResp> queryPayOrder(Long shopId, String payOrderId, String mchOrderNo);
|
||||
CzgResult<QueryOrderRespDTO> queryPayOrder(Long shopId, String payOrderId, String mchOrderNo, String platform);
|
||||
|
||||
/**
|
||||
* 退款查询
|
||||
|
||||
@@ -1030,12 +1030,12 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, int retryCount) {
|
||||
public void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, String channel, int retryCount) {
|
||||
OrderPayment payment = paymentService.getOne(new QueryWrapper().eq(OrderPayment::getOrderNo, orderNo));
|
||||
if (payment == null) {
|
||||
if (retryCount < MAX_RETRIES) {
|
||||
log.info("支付记录不存在,第 {} 次重试,将在 {} 秒后进行", retryCount + 1, DELAY);
|
||||
executorService.schedule(() -> payCallBackOrder(orderNo, notifyRespDTO, retryCount + 1), DELAY, TimeUnit.SECONDS);
|
||||
executorService.schedule(() -> payCallBackOrder(orderNo, notifyRespDTO, channel, retryCount + 1), DELAY, TimeUnit.SECONDS);
|
||||
} else {
|
||||
log.error("订单支付回调失败, 达到最大重试次数, 支付记录不存在, orderNo: {}", orderNo);
|
||||
}
|
||||
@@ -1049,6 +1049,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
|
||||
payment.setRespJson(notifyRespDTO.getOriginalData());
|
||||
payment.setPayStatus(PayTypeConstants.PayStatus.FAIL);
|
||||
payment.setPlatformType(notifyRespDTO.getPlatform());
|
||||
payment.setChannel(channel);
|
||||
if ("TRADE_SUCCESS".equals(notifyRespDTO.getStatus())) {
|
||||
payment.setPayStatus(PayTypeConstants.PayStatus.SUCCESS);
|
||||
if (PayTypeConstants.SourceType.ORDER.equals(payment.getSourceType())) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.czg.constant.PayChannelCst;
|
||||
import com.czg.constants.ParamCodeCst;
|
||||
import com.czg.constants.PayTypeConstants;
|
||||
import com.czg.constants.SystemConstants;
|
||||
import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.enums.CzgPayEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.order.dto.LtPayOtherDTO;
|
||||
@@ -20,6 +19,7 @@ import com.czg.order.service.OrderPaymentService;
|
||||
import com.czg.order.service.ShopMerchantService;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.QueryOrderRespDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.service.order.mapper.OrderPaymentMapper;
|
||||
@@ -146,7 +146,7 @@ public class PayServiceImpl implements PayService {
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {
|
||||
public CzgResult<QueryOrderRespDTO> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo, String platform) {
|
||||
ShopMerchant shopMerchant = getMerchant(shopId);
|
||||
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
|
||||
String payData = null;
|
||||
@@ -155,7 +155,7 @@ public class PayServiceImpl implements PayService {
|
||||
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
|
||||
payData = shopMerchant.getPolyPayJson();
|
||||
}
|
||||
return adapter.queryPayOrder(getDomain(), payData, payOrderId, mchOrderNo);
|
||||
return adapter.queryPayOrder(getDomain(), payData, payOrderId, mchOrderNo, platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.czg;
|
||||
|
||||
import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.enums.CzgPayEnum;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.resp.CzgResult;
|
||||
@@ -39,7 +38,7 @@ public interface PayAdapter {
|
||||
|
||||
CzgResult<RefundRespDTO> refund(@NotBlank String domain, @NotBlank String payData, String notifyUrl, CzgRefundReq bizData);
|
||||
|
||||
CzgResult<CzgBaseResp> queryPayOrder(@NotBlank String domain, @NotBlank String payData, String payOrderId, String mchOrderNo);
|
||||
CzgResult<QueryOrderRespDTO> queryPayOrder(@NotBlank String domain, @NotBlank String payData, String payOrderId, String mchOrderNo, String platform);
|
||||
|
||||
CzgResult<RefundRespDTO> queryRefund(@NotBlank String domain, @NotBlank String payData, String mchRefundNo, String refundOrderId);
|
||||
|
||||
|
||||
@@ -4,13 +4,9 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.PayAdapter;
|
||||
import com.czg.PayManager;
|
||||
import com.czg.constant.PayChannelCst;
|
||||
import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.enums.CzgPayEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.NativeMerchantDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.resp.CzgResult;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -61,8 +57,10 @@ public class NativePayAdapter implements PayAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<CzgBaseResp> queryPayOrder(String domain, String payData, String payOrderId, String mchOrderNo) {
|
||||
return null;
|
||||
public CzgResult<QueryOrderRespDTO> queryPayOrder(String domain, String payData, String payOrderId, String mchOrderNo, String platform) {
|
||||
NativeMerchantDTO merchantDTO = getMerchantDTO(payData);
|
||||
QueryOrderRespDTO respDTO = PayManager.queryOrderStatus(platform, mchOrderNo, merchantDTO);
|
||||
return CzgResult.success(respDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,10 +9,7 @@ import com.czg.entity.resp.CzgBaseResp;
|
||||
import com.czg.entity.resp.CzgRefundResp;
|
||||
import com.czg.enums.CzgPayEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.pay.CzgPayBaseReq;
|
||||
import com.czg.pay.CzgRefundReq;
|
||||
import com.czg.pay.PolyMerchantDTO;
|
||||
import com.czg.pay.RefundRespDTO;
|
||||
import com.czg.pay.*;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
@@ -60,10 +57,19 @@ public class PolyPayAdapter implements PayAdapter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CzgResult<CzgBaseResp> queryPayOrder(@NotBlank String payData, @NotBlank String domain, String payOrderId, String mchOrderNo) {
|
||||
public CzgResult<QueryOrderRespDTO> queryPayOrder(@NotBlank String payData, @NotBlank String domain, String payOrderId, String mchOrderNo, String platform) {
|
||||
PolyMerchantDTO shopMerchant = JSONObject.parseObject(payData, PolyMerchantDTO.class);
|
||||
PolyPayUtils.queryPayOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
|
||||
return null;
|
||||
CzgResult<CzgBaseResp> result = PolyPayUtils.queryPayOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
|
||||
if (result.isSuccess()) {
|
||||
QueryOrderRespDTO respDTO = new QueryOrderRespDTO()
|
||||
.setStatus(result.getData().getState())
|
||||
.setOrderNo(result.getData().getMchOrderNo())
|
||||
.setAmount(result.getData().getAmount())
|
||||
.setErrorMsg("")
|
||||
.setOriginResp(JSONObject.toJSONString(result.getData()));
|
||||
return CzgResult.success(respDTO);
|
||||
}
|
||||
return CzgResult.failure(result.getMsg());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user