From be2091afa784c449329255b5a4c1a282cf16cb43 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Sat, 14 Sep 2024 11:24:58 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/domain/entity/SysDept.java | 150 +++++++++--------- .../java/com/ruoyi/system/domain/EtOrder.java | 3 + .../system/service/impl/WxPayService.java | 48 +++--- .../resources/mapper/system/EtOrderMapper.xml | 21 ++- 4 files changed, 120 insertions(+), 102 deletions(-) diff --git a/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java b/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java index 9566a10..ff0b5f7 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java +++ b/electripper-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java @@ -85,26 +85,26 @@ public class SysDept extends BaseEntity /** 余额 */ private BigDecimal balance; - /** appSecret */ - private String appSecret; - - /** merchantId */ - private String merchantId; - - /** apiV3Key */ - private String apiV3Key; - - /** 通知回调地址 */ - private String notifyUrl; - - /** 密钥所在位置 */ - private String privateKeyPath; - - /** 证书序列号 */ - private String merchantSerialNumber; - - /** 退款回调地址 */ - private String refundNotifyUrl; +// /** appSecret */ +// private String appSecret; +// +// /** merchantId */ +// private String merchantId; +// +// /** apiV3Key */ +// private String apiV3Key; +// +// /** 通知回调地址 */ +// private String notifyUrl; +// +// /** 密钥所在位置 */ +// private String privateKeyPath; +// +// /** 证书序列号 */ +// private String merchantSerialNumber; +// +// /** 退款回调地址 */ +// private String refundNotifyUrl; /** app用户id,用于提现,发送短信 */ private Long appUserId; @@ -281,61 +281,61 @@ public class SysDept extends BaseEntity this.appid = appid; } - public String getAppSecret() { - return appSecret; - } - - public void setAppSecret(String appSecret) { - this.appSecret = appSecret; - } - - public String getMerchantId() { - return merchantId; - } - - public void setMerchantId(String merchantId) { - this.merchantId = merchantId; - } - - public String getApiV3Key() { - return apiV3Key; - } - - public void setApiV3Key(String apiV3Key) { - this.apiV3Key = apiV3Key; - } - - public String getNotifyUrl() { - return notifyUrl; - } - - public void setNotifyUrl(String notifyUrl) { - this.notifyUrl = notifyUrl; - } - - public String getPrivateKeyPath() { - return privateKeyPath; - } - - public void setPrivateKeyPath(String privateKeyPath) { - this.privateKeyPath = privateKeyPath; - } - - public String getMerchantSerialNumber() { - return merchantSerialNumber; - } - - public void setMerchantSerialNumber(String merchantSerialNumber) { - this.merchantSerialNumber = merchantSerialNumber; - } - - public String getRefundNotifyUrl() { - return refundNotifyUrl; - } - - public void setRefundNotifyUrl(String refundNotifyUrl) { - this.refundNotifyUrl = refundNotifyUrl; - } +// public String getAppSecret() { +// return appSecret; +// } +// +// public void setAppSecret(String appSecret) { +// this.appSecret = appSecret; +// } +// +// public String getMerchantId() { +// return merchantId; +// } +// +// public void setMerchantId(String merchantId) { +// this.merchantId = merchantId; +// } +// +// public String getApiV3Key() { +// return apiV3Key; +// } +// +// public void setApiV3Key(String apiV3Key) { +// this.apiV3Key = apiV3Key; +// } +// +// public String getNotifyUrl() { +// return notifyUrl; +// } +// +// public void setNotifyUrl(String notifyUrl) { +// this.notifyUrl = notifyUrl; +// } +// +// public String getPrivateKeyPath() { +// return privateKeyPath; +// } +// +// public void setPrivateKeyPath(String privateKeyPath) { +// this.privateKeyPath = privateKeyPath; +// } +// +// public String getMerchantSerialNumber() { +// return merchantSerialNumber; +// } +// +// public void setMerchantSerialNumber(String merchantSerialNumber) { +// this.merchantSerialNumber = merchantSerialNumber; +// } +// +// public String getRefundNotifyUrl() { +// return refundNotifyUrl; +// } +// +// public void setRefundNotifyUrl(String refundNotifyUrl) { +// this.refundNotifyUrl = refundNotifyUrl; +// } public Long[] getAreaIds() { return areaIds; diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java index 787e2ce..d610683 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java @@ -355,4 +355,7 @@ public class EtOrder extends BaseEntity @Excel(name = "描述") private String description; + + /** 支付渠道 */ + public Long payChannel; } 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 b59d376..585c073 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 @@ -121,10 +121,6 @@ public class WxPayService implements IWxPayService { EtOrder order1 = new EtOrder(); order1.setOutTradeNo(outTradeNo); order1.setOrderId(order.getOrderId()); - int updateEtOrder = etOrderService.updateEtOrder(order1); - if(updateEtOrder == 0){ - throw new ServiceException("更新订单outTradeNo失败"); - } Long payChannel = sysDept.getPayChannel(); if(ObjectUtil.isNull(payChannel)){ @@ -132,25 +128,32 @@ public class WxPayService implements IWxPayService { } ChannelVO channelVO = etChannelService.selectSmChannelByChannelId(payChannel); + + order1.setPayChannel(payChannel); + int updateEtOrder = etOrderService.updateEtOrder(order1); + if(updateEtOrder == 0){ + throw new ServiceException("更新订单outTradeNo失败"); + } + if(PayChannel.CT_WX.equalsCode(channelVO.getCode()) || PayChannel.YS_WX.equalsCode(channelVO.getCode())){ log.info("----------{}-------------","微信官方支付"); PrepayRequest request = new PrepayRequest(); request.setAmount(getAmount(order.getPayFee())); request.setOutTradeNo(outTradeNo); request.setAppid(sysDept.getAppid()); - request.setMchid(sysDept.getMerchantId()); + request.setMchid(channelVO.getMerchantId()); request.setAttach(JSON.toJSONString(new AttachVo(payType,user.getUserId(), ""))); request.setDescription(description); - request.setNotifyUrl(sysDept.getNotifyUrl()); + request.setNotifyUrl(channelVO.getNotifyUrl()); request.setPayer(getPayer(user.getWxopenid())); - JsapiServiceExtension jsapiServiceExtension = getJsapiServiceExtension(sysDept); + JsapiServiceExtension jsapiServiceExtension = getJsapiServiceExtension(channelVO); PrepayWithRequestPaymentResponse res = jsapiServiceExtension.prepayWithRequestPayment(request); if(StrUtil.isNotBlank(order.getOutTradeNo())){ String tradeNo = order.getOutTradeNo(); // 关闭订单 CloseOrderRequest closeOrderRequest = new CloseOrderRequest(); - closeOrderRequest.setMchid(sysDept.getMerchantId()); + closeOrderRequest.setMchid(channelVO.getMerchantId()); closeOrderRequest.setOutTradeNo(tradeNo); jsapiServiceExtension.closeOrder(closeOrderRequest); } @@ -203,15 +206,16 @@ public class WxPayService implements IWxPayService { EtOrder order1 = new EtOrder(); order1.setOutTradeNo(outTradeNo); order1.setOrderId(order.getOrderId()); - int updateEtOrder = etOrderService.updateEtOrder(order1); - if(updateEtOrder == 0){ - throw new ServiceException("更新订单outTradeNo失败"); - } Long payChannel = sysDept.getPayChannel(); if(ObjectUtil.isNull(payChannel)){ throw new ServiceException("运营商【"+sysDept.getDeptName()+"】没有支付渠道"); } + order1.setPayChannel(payChannel); + int updateEtOrder = etOrderService.updateEtOrder(order1); + if(updateEtOrder == 0){ + throw new ServiceException("更新订单outTradeNo失败"); + } ChannelVO channelVO = etChannelService.selectSmChannelByChannelId(payChannel); if(PayChannel.CT_WX.equalsCode(channelVO.getCode()) || PayChannel.YS_WX.equalsCode(channelVO.getCode())){ @@ -220,10 +224,10 @@ public class WxPayService implements IWxPayService { request.setAmount(getAmount(order.getPayFee())); request.setOutTradeNo(outTradeNo); request.setAppid(sysDept.getAppid()); - request.setMchid(sysDept.getMerchantId()); + request.setMchid(channelVO.getMerchantId()); request.setAttach(JSON.toJSONString(new AttachVo(order.getType(),user.getUserId(), ""))); request.setDescription(description); - request.setNotifyUrl(sysDept.getNotifyUrl()); + request.setNotifyUrl(channelVO.getNotifyUrl()); request.setPayer(getPayer(user.getWxopenid())); JsapiServiceExtension jsapiServiceExtension = getJsapiServiceExtension(sysDept); PrepayWithRequestPaymentResponse res = jsapiServiceExtension.prepayWithRequestPayment(request); @@ -232,7 +236,7 @@ public class WxPayService implements IWxPayService { String tradeNo = order.getOutTradeNo(); // 关闭订单 CloseOrderRequest closeOrderRequest = new CloseOrderRequest(); - closeOrderRequest.setMchid(sysDept.getMerchantId()); + closeOrderRequest.setMchid(channelVO.getMerchantId()); closeOrderRequest.setOutTradeNo(tradeNo); jsapiServiceExtension.closeOrder(closeOrderRequest); } @@ -268,14 +272,14 @@ public class WxPayService implements IWxPayService { } - private JsapiServiceExtension getJsapiServiceExtension(SysDept sysDept) { + private JsapiServiceExtension getJsapiServiceExtension(ChannelVO channelVO) { // 初始化商户配置 Config config = new RSAAutoCertificateConfig.Builder() - .merchantId(sysDept.getMerchantId()) + .merchantId(channelVO.getMerchantId()) // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 - .privateKeyFromPath(sysDept.getPrivateKeyPath()) - .merchantSerialNumber(sysDept.getMerchantSerialNumber()) - .apiV3Key(sysDept.getApiV3Key()) + .privateKeyFromPath(channelVO.getPrivateKeyPath()) + .merchantSerialNumber(channelVO.getMerchantSerialNumber()) + .apiV3Key(channelVO.getApiV3Key()) .build(); // 初始化服务 return new JsapiServiceExtension @@ -399,8 +403,8 @@ public class WxPayService implements IWxPayService { public void refund(EtOrder etOrder,String reason,BigDecimal amount,String outRefundNo) { SysDept sysDept = getDeptObjByAreaId(etOrder.getAreaId()); - if(ObjectUtil.isNull(sysDept.getPayChannel())) throw new ServiceException("运营商【"+sysDept.getDeptName()+"】没有支付渠道"); - ChannelVO channelVO = etChannelService.selectSmChannelByChannelId(sysDept.getPayChannel()); + if(!etOrder.getStatus().equals(ServiceConstants.ORDER_STATUS_ORDER_END)) throw new ServiceException("订单状态异常"); + ChannelVO channelVO = etChannelService.selectSmChannelByChannelId(etOrder.getPayChannel()); if(PayChannel.CT_WX.equalsCode(channelVO.getCode()) || PayChannel.YS_WX.equalsCode(channelVO.getCode())){ log.info("----------{}-------------","微信官方退款"); diff --git a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml index e5fb5b9..c0cc2c2 100644 --- a/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtOrderMapper.xml @@ -60,6 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -69,7 +70,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_time, appointment_start_time, appointment_end_time,appointment_timeout, unlock_time,return_time, rule_end_time, return_type, AsText(trip_route) trip_route,trip_route_str,cycle,deposit_deduction,video_url, upload_time,deduction_amount,audio_files,used_sn,change_reason,locking,auto_refund_deposit,free_ride_time, - rental_unit,riding_rule,riding_rule_json,charging_cycle,charging_cycle_value,capped_amount,handling_charge, platform_service_fee, operator_dividend from et_order + rental_unit,riding_rule,riding_rule_json,charging_cycle,charging_cycle_value,capped_amount,handling_charge, platform_service_fee, pay_channel + operator_dividend from et_order @@ -77,8 +79,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" device_mac, sn, pay_time, paid, pay_type, type, total_fee, pay_fee, dispatch_fee, manage_fee, riding_fee, appointment_fee, mark, duration, distance, status, create_time, appointment_start_time, appointment_end_time,appointment_timeout, unlock_time,return_time, - rule_end_time, return_type, cycle,deposit_deduction,video_url,upload_time,deduction_amount,audio_files,used_sn,change_reason,locking,auto_refund_deposit,free_ride_time, - rental_unit,riding_rule,riding_rule_json,charging_cycle,charging_cycle_value,capped_amount,handling_charge, platform_service_fee, operator_dividend from et_order + rule_end_time, return_type, cycle,deposit_deduction,video_url,upload_time,deduction_amount,audio_files, + used_sn,change_reason,locking,auto_refund_deposit,free_ride_time, + rental_unit,riding_rule,riding_rule_json,charging_cycle,charging_cycle_value,capped_amount,handling_charge, platform_service_fee, pay_channel + operator_dividend from et_order