diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java index a9e5294..52268de 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java @@ -343,7 +343,7 @@ public class AppVerifyController extends BaseController @PostMapping("/order/withdraw") public AjaxResult withdraw() { - + logger.info("【提现请求】-----------------"); //根据订单号查询订单信息 EtOrder etOrder = new EtOrder(); etOrder.setUserId(getUserId()); diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/common/CallbackController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/common/CallbackController.java index 4e46fc7..96445bd 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/common/CallbackController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/common/CallbackController.java @@ -1,6 +1,7 @@ package com.ruoyi.web.controller.common; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.constant.ServiceConstants; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.pay.tm.TmPayService; @@ -98,18 +99,19 @@ public class CallbackController { EtCallbackLog etCallbackLog = new EtCallbackLog(); etCallbackLog.setBody(body); etCallbackLog.setType("1"); - String payType = (String)params.get("payType"); // 交易类型 - String outTradeNo = (String)params.get("outTradeId"); // 商户自定义订单号 - String trxStatus = (String)params.get("payStatus"); // 交易结果 + JSONObject tradeInfo = (JSONObject)params.get("tradeInfo"); + String payType = (String)tradeInfo.get("payType"); // 交易类型 + String outTradeNo = (String)tradeInfo.get("outTradeId"); // 商户自定义订单号 + String trxStatus = (String)tradeInfo.get("payStatus"); // 交易结果 // 构建attachVo AttachVo attach = generateAttach(outTradeNo); log.info("【太米微信支付回调】创建的attachVo : " + JSON.toJSONString(attach)); if(PayStatus.isSuccess(trxStatus) && payType.equals("wx_pay")) { // 新版支付订单 - callbackService.businessHandle(outTradeNo,attach, ServiceConstants.PAY_TYPE_TLWX); + callbackService.businessHandle(outTradeNo,attach, ServiceConstants.PAY_TYPE_TMWX); } //异步保存回调日志 - asynchronousSaveCallbackLog(etCallbackLog); + asynchronousSaveCallbackLog(etCallbackLog);// tradeInfo -> {JSONObject@14208} size = 34 }else { throw new ServiceException("签名验证失败"); } diff --git a/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java b/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java index a7d7cd5..5e48959 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java +++ b/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java @@ -147,9 +147,9 @@ public class ServiceConstants { public static final String PAY_TYPE_WX = "wx"; /** - * 支付方式: tlwx-通联微信 + * 支付方式: tmwx-太米微信 */ - public static final String PAY_TYPE_TLWX = "tlwx"; + public static final String PAY_TYPE_TMWX = "tmwx"; /** * 支付方式: sys-系统 免费骑行时,订单金额为0 diff --git a/electripper-common/src/main/java/com/ruoyi/common/pay/tm/TmPayService.java b/electripper-common/src/main/java/com/ruoyi/common/pay/tm/TmPayService.java index 8eba737..cd9476b 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/pay/tm/TmPayService.java +++ b/electripper-common/src/main/java/com/ruoyi/common/pay/tm/TmPayService.java @@ -50,13 +50,13 @@ public class TmPayService { HashMap<String, Object> body = new HashMap<>(); body.put("refundFee", String.valueOf(refundAble.getAmount())); body.put("terminalType", "1"); - body.put("outTradeId", refundAble.getOutRefundNo()); + body.put("outTradeId", refundAble.getOutTradeNo()); body.put("shopId", channel.getShopId()); String response = doPost(channel.getHttpUrl() + "/open/Pay/refund", body,channel); if (com.ruoyi.common.utils.StringUtils.hasText(response)) { JSONObject jsonResponse = JSON.parseObject(response); - if (jsonResponse.getInteger("errCode") == 0 && "ok".equals(jsonResponse.getString("errMsg"))) { - JSONObject tradeInfo = jsonResponse.getJSONObject("tradeInfo"); + if (jsonResponse.getInteger("errCode") == 0 && "退款成功".equals(jsonResponse.getString("errMsg"))) { + JSONObject tradeInfo = jsonResponse.getJSONObject("refundInfo"); RefundInfo refundInfo = tradeInfo.toJavaObject(RefundInfo.class); return refundInfo; } else { diff --git a/electripper-common/src/main/java/com/ruoyi/common/pay/tm/enums/PayStatus.java b/electripper-common/src/main/java/com/ruoyi/common/pay/tm/enums/PayStatus.java index 6910c8f..ec1b55a 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/pay/tm/enums/PayStatus.java +++ b/electripper-common/src/main/java/com/ruoyi/common/pay/tm/enums/PayStatus.java @@ -36,6 +36,15 @@ public enum PayStatus { return SUCCESS.getCode().equals(code); } + /** + * 判断支付状态是否转入退款 + * @param code 支付状态码 + * @return 是否成功 + */ + public static boolean isRefund(String code) { + return REFUND.getCode().equals(code); + } + /** * 根据状态码获取对应的支付状态 * @param code 支付状态码 diff --git a/electripper-common/src/main/java/com/ruoyi/common/pay/tm/vo/RefundInfo.java b/electripper-common/src/main/java/com/ruoyi/common/pay/tm/vo/RefundInfo.java index fd99e4d..87d0285 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/pay/tm/vo/RefundInfo.java +++ b/electripper-common/src/main/java/com/ruoyi/common/pay/tm/vo/RefundInfo.java @@ -12,12 +12,12 @@ import java.math.BigDecimal; */ @Data public class RefundInfo { - private Long id; // 太米系统退款记录Id + private String id; // 太米系统退款记录Id private Long tradeInfoId; // 太米系统流水Id private String module; // 模块: pay, mall, recharge, become_member, eatIn, takeOut, selfTake, payment_card, times_card private String remark; // 备注 private Long merchantId; // 品牌Id - private Long shopId; // 门店Id + private String shopId; // 门店Id private Long merchantUserId; // 门店员工Id private Long codeId; // 款台码Id private Long memberInfoId; // 会员Id @@ -26,6 +26,6 @@ public class RefundInfo { private String refundTime; // 退款成功时间 private String refundMessage; // 退款失败原因 private RefundStatus refundStatus; // 退款状态: RefundStatus 枚举 - private BigDecimal refundAmount; // 已退款金额 + private String refundAmount; // 已退款金额 private String createTime; // 创建时间 } diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java b/electripper-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java index 37608ee..1725d41 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java @@ -221,6 +221,7 @@ public class HttpUtils * @return 所代表远程资源的响应结果 */ public static String sendPostWithHeaders(String url, Map<String, String> headerData, String body) { + log.info("body------- - {}", body); PrintWriter out = null; BufferedReader in = null; StringBuilder result = new StringBuilder(); diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java index da1fd43..2cc3c22 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/WxPayService.java @@ -321,11 +321,8 @@ public class WxPayService implements IWxPayService { return paymentResult1; }else if(PayChannel.TM_WX.equalsCode(channelVO.getCode())){ TmTradeInfo tmTradeInfo = tmPayService.orderQuery(channelVO, order.getOutTradeNo()); - if(PayStatus.isSuccess(tmTradeInfo.getPayStatus().getCode())) { - paymentResult1.setTradeInfo(tmTradeInfo); - return paymentResult1; - } - return null; + paymentResult1.setTradeInfo(tmTradeInfo); + return paymentResult1; }else{ throw new ServiceException("支付渠道【"+channelVO.getCode()+"】暂不支持"); } @@ -368,35 +365,16 @@ public class WxPayService implements IWxPayService { // 订单未支付并且微信支付结果是成功的情况下,更新订单状态和用户余额 if(transaction.getTradeState().equals(Transaction.TradeStateEnum.SUCCESS)){ if(order.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_NON_PAYMENT)){ - order.setPaid("1"); - order.setPayTime(DateUtils.parseTime(transaction.getSuccessTime())); - order.setPayType(ServiceConstants.PAY_TYPE_WX); - log.info("【主动查询】押金支付"); - order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); - if(ServiceConstants.ORDER_TYPE_RIDING.equals(order.getType())){ - order.setMark("主动查询-骑行支付"); - }else{ - order.setMark("押金支付"); - // 更新用户余额 - AsUser asUser = asUserMapper.selectUserById(order.getUserId()); - asUser.setBalance(order.getTotalFee()); - int updateUser = asUserMapper.updateUser(asUser); - if(updateUser==0){ - log.error("【微信支付回调】更新用户押金失败"); - throw new ServiceException("【微信支付回调】更新用户押金失败"); - } - } - int updateEtOrder = etOrderService.updateEtOrder(order); - if(updateEtOrder==0){ - log.error("【微信支付回调】更新订单信息失败"); - throw new ServiceException("【微信支付回调】更新订单信息失败"); - } + handlePaySuccess(order, transaction.getSuccessTime()); } return true; } }else if(PayChannel.TM_WX.equalsCode(channelVO.getCode())){ TmTradeInfo tmTradeInfo = tmPayService.orderQuery(channelVO, order.getOutTradeNo()); if(PayStatus.isSuccess(tmTradeInfo.getPayStatus().getCode())) { + if(order.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_NON_PAYMENT)){ + handlePaySuccess(order, tmTradeInfo.getPayTime()); + } return true; } }else{ @@ -405,6 +383,32 @@ public class WxPayService implements IWxPayService { return false; } + private void handlePaySuccess(EtOrder order, String payTime) { + order.setPaid("1"); + order.setPayTime(DateUtils.parseTime(payTime)); + order.setPayType(ServiceConstants.PAY_TYPE_WX); + log.info("【主动查询】押金支付"); + order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); + if(ServiceConstants.ORDER_TYPE_RIDING.equals(order.getType())){ + order.setMark("主动查询-骑行支付"); + }else{ + order.setMark("押金支付"); + // 更新用户余额 + AsUser asUser = asUserMapper.selectUserById(order.getUserId()); + asUser.setBalance(order.getTotalFee()); + int updateUser = asUserMapper.updateUser(asUser); + if(updateUser==0){ + log.error("【微信支付回调】更新用户押金失败"); + throw new ServiceException("【微信支付回调】更新用户押金失败"); + } + } + int updateEtOrder = etOrderService.updateEtOrder(order); + if(updateEtOrder==0){ + log.error("【微信支付回调】更新订单信息失败"); + throw new ServiceException("【微信支付回调】更新订单信息失败"); + } + } + private JsapiService getJsapiService(ChannelVO channelVO) { // 初始化商户配置 Config config = new RSAAutoCertificateConfig.Builder() @@ -452,6 +456,7 @@ public class WxPayService implements IWxPayService { refundAble.setOutRefundNo(outRefundNo); refundAble.setReason(reason); refundAble.setAmount(amount.multiply(new BigDecimal(100)).longValue()); + log.info("【退款】请求太米参数:【{}】",JSON.toJSONString(refundAble)); RefundInfo refund = tmPayService.refund(channelVO, refundAble); ServiceUtil.assertion(!RefundStatus.isSuccess(refund.getRefundStatus().getCode()), "发起退款失败:" + refund.getRefundMessage()); scheduledExecutorService.schedule(() -> {