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" <result property="handlingCharge" column="handling_charge" /> <result property="platformServiceFee" column="platform_service_fee" /> <result property="operatorDividend" column="operator_dividend" /> + <result property="payChannel" column="pay_channel" /> </resultMap> <sql id="selectEtOrderVo"> @@ -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 </sql> <sql id="selectEtOrderVoNoRoute"> @@ -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 </sql> <select id="selectEtOrderList" parameterType="EtOrder" resultMap="EtOrderResult"> @@ -132,7 +136,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" o.locking, o.handling_charge, o.platform_service_fee, - o.operator_dividend + o.operator_dividend, + o.pay_channel FROM et_order o LEFT JOIN @@ -230,7 +235,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" o.locking, o.handling_charge, o.platform_service_fee, - o.operator_dividend + o.operator_dividend, + o.pay_channel FROM et_order o LEFT JOIN @@ -316,6 +322,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" o.return_time, o.rule_end_time, o.return_type, + o.pay_channel, AsText(o.trip_route) trip_route, o.trip_route_str from et_order o LEFT JOIN et_user u ON u.user_id = o.user_id @@ -857,6 +864,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="chargingCycle != null">charging_cycle,</if> <if test="chargingCycleValue != null">charging_cycle_value,</if> <if test="cappedAmount != null">capped_amount,</if> + <if test="payChannel != null and payChannel != ''">pay_channel,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="orderId != null">#{orderId},</if> @@ -901,6 +909,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="chargingCycle != null">#{chargingCycle},</if> <if test="chargingCycleValue != null">#{chargingCycleValue},</if> <if test="cappedAmount != null">#{cappedAmount},</if> + <if test="payChannel != null and payChannel != ''">#{payChannel},</if> </trim> </insert> @@ -958,6 +967,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="handlingCharge != null">handling_charge = #{handlingCharge},</if> <if test="platformServiceFee != null">platform_service_fee = #{platformServiceFee},</if> <if test="operatorDividend != null">operator_dividend = #{operatorDividend},</if> + <if test="payChannel != null">pay_channel = #{payChannel},</if> </trim> where order_id = #{orderId} </update> @@ -1016,6 +1026,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <if test="handlingCharge != null">handling_charge = #{handlingCharge},</if> <if test="platformServiceFee != null">platform_service_fee = #{platformServiceFee},</if> <if test="operatorDividend != null">operator_dividend = #{operatorDividend},</if> + <if test="payChannel != null">pay_channel = #{payChannel},</if> </trim> where order_no = #{orderNo} </update>