feat:微信付款码支付
This commit is contained in:
1 parent
84c10d7f4f
commit
c477dbf361
7 files changed
+127
-43
No files matched your search
+4
-4
@@ -14,14 +14,14 @@ import lombok.NoArgsConstructor;
|
||||
@NoArgsConstructor
|
||||
public class WechatRefundDto {
|
||||
|
||||
private String orderId;
|
||||
private Long orderId;
|
||||
|
||||
private String wechantOrderId;
|
||||
|
||||
private String refundId;
|
||||
private Long refundId;
|
||||
|
||||
private Long orderPrice;
|
||||
private Integer orderPrice;
|
||||
|
||||
private Long refundPrice;
|
||||
private Integer refundPrice;
|
||||
|
||||
}
|
||||
+3
-3
@@ -63,14 +63,14 @@ public class WechantRefunCallbackVo {
|
||||
public static String wechantError() {
|
||||
return "<xml>" +
|
||||
"<return_code><![CDATA[FAIL]]></return_code>" +
|
||||
"<return_msg><![CDATA[退款错误]]></return_msg>" +
|
||||
"<return_msg><![CDATA[FAIL]]></return_msg>" +
|
||||
"</xml>";
|
||||
}
|
||||
|
||||
public static String wechantSuccess() {
|
||||
return "<xml>" +
|
||||
"<return_code><![CDATA[SUCCESS]]></return_code>" +
|
||||
"<return_msg><![CDATA[退款成功]]></return_msg>" +
|
||||
" <return_code><![CDATA[SUCCESS]]></return_code>" +
|
||||
" <return_msg><![CDATA[OK]]></return_msg>\n" +
|
||||
"</xml>";
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -10,6 +10,7 @@ import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleLogEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.WechantRefunCallbackVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -43,6 +44,11 @@ public interface HardAfterSaleService extends IService<HardAfterSaleEntity> {
|
||||
|
||||
void refund(Long afterSaleId, String prefixStr);
|
||||
|
||||
/**
|
||||
* 微信退款回调通知
|
||||
*/
|
||||
boolean wechatRefundCallback(WechantRefunCallbackVo decrypt);
|
||||
|
||||
/**
|
||||
* 同意售后
|
||||
*/
|
||||
|
||||
+7
@@ -7,6 +7,8 @@ import com.bsd.pjcloud.admin.api.entity.SysUser;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HandCancelCodeDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.hard.HardCreateOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardCreateCarDto;
|
||||
@@ -106,4 +108,9 @@ public interface HardOrderService extends IService<HardOrderEntity> {
|
||||
* 创建订单后发送mq消息
|
||||
*/
|
||||
void createOrderAfterSendMqMsg(Long orderId, UserInfo userInfo);
|
||||
|
||||
/**
|
||||
* 是否需要支付
|
||||
*/
|
||||
boolean isPay(HardOrderTypeEnum type, HardPayTypeEnum payType);
|
||||
}
|
||||
+81
-17
@@ -21,6 +21,7 @@ import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.security.service.PjcloudUser;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardOrderStatusEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardOrderTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.order.HardPayTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.refund.HardAfterSaleOperateTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.refund.HardRefundStatusEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleStatusEnum;
|
||||
@@ -29,17 +30,21 @@ import com.bsd.pjcloud.hard.api.dto.order.HardAdminRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardAfterSaleDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardDisagreeDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.HardOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.wechat.WechatRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleLogEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardOrderEntity;
|
||||
import com.bsd.pjcloud.hard.api.utils.HardUtil;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.WechantRefunCallbackVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.WechatRefundVo;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleLogMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardAfterSaleService;
|
||||
import com.bsd.pjcloud.hard.service.HardOrderService;
|
||||
import com.bsd.pjcloud.hard.service.WechatPayService;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayVoStatusEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundDto;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargeService;
|
||||
@@ -57,9 +62,6 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 售后订单
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-01-07 17:23:08
|
||||
*/
|
||||
@Validated
|
||||
@Slf4j
|
||||
@@ -71,6 +73,7 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
|
||||
private final HardAfterSaleLogMapper hardAfterSaleLogMapper;
|
||||
private final HardOrderService hardOrderService;
|
||||
private final WechatPayService wechatPayService;
|
||||
|
||||
private final HardOrderMapper hardOrderMapper;
|
||||
|
||||
@@ -234,21 +237,82 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
if (ObjectUtil.isEmpty(refundTotalPrice)) {
|
||||
refundTotalPrice = 0;
|
||||
}
|
||||
WalletRechargeRefundDto hardRefundDto = WalletRechargeRefundDto.builder().walletId(order.getWalletId()).orderId(order.getId()).afterSaleId(afterSale.getId()).refundCode(refundCode).reason("订单退款").price(refundPrice).build();
|
||||
R<WalletRechargeVo> walletRefundResult = walletRechargeService.refund(hardRefundDto);
|
||||
if (walletRefundResult.getCode() != 0 || ObjectUtil.isEmpty(walletRefundResult.getData())) {
|
||||
throw new RuntimeException("钱包退款错误");
|
||||
HardOrderTypeEnum hardOrderType = HardOrderTypeEnum.valueOfByType(order.getOrderType());
|
||||
HardPayTypeEnum hardPayType = HardPayTypeEnum.valueOfByType(order.getPayType());
|
||||
// 是否钱包支付
|
||||
boolean isWalletPay = hardOrderService.isPay(hardOrderType, hardPayType);
|
||||
// 是否微信支付
|
||||
boolean isWeChatPay = ObjectUtil.equals(order.getPayType(), HardPayTypeEnum.WECHANT_SELF_QR_CODE_PAY.getType());
|
||||
// 是否支付宝支付
|
||||
boolean isAliPay = ObjectUtil.equals(order.getPayType(), HardPayTypeEnum.ALI_SELF_QR_CODE_PAY.getType());
|
||||
if (isWalletPay) {
|
||||
WalletRechargeRefundDto hardRefundDto = WalletRechargeRefundDto.builder().walletId(order.getWalletId()).orderId(order.getId()).afterSaleId(afterSale.getId()).refundCode(refundCode).reason("订单退款").price(refundPrice).build();
|
||||
R<WalletRechargeVo> walletRefundResult = walletRechargeService.refund(hardRefundDto);
|
||||
if (walletRefundResult.getCode() != 0 || ObjectUtil.isEmpty(walletRefundResult.getData())) {
|
||||
throw new RuntimeException("钱包退款错误");
|
||||
}
|
||||
WalletRechargeVo walletRefund = walletRefundResult.getData();
|
||||
HardOrderEntity updateObj = HardOrderEntity.builder()
|
||||
.id(order.getId())
|
||||
.orderStatus(HardOrderStatusEnum.REFUND.getType())
|
||||
.refundStatus(HardRefundStatusEnum.SUCCESS.getStatus())
|
||||
.payRefundId(walletRefund.getId())
|
||||
.refundPrice(refundTotalPrice + refundPrice)
|
||||
.refundTime(LocalDateTime.now())
|
||||
.build();
|
||||
hardOrderService.updateById(updateObj);
|
||||
} else if (isWeChatPay) {
|
||||
WechatRefundDto refundDto = WechatRefundDto.builder().orderId(order.getId()).refundId(afterSale.getId()).orderPrice(refundPrice).refundPrice(refundPrice).build();
|
||||
WechatRefundVo refundVo = wechatPayService.refund(refundDto);
|
||||
if (ObjectUtil.isEmpty(refundVo)) {
|
||||
throw new RuntimeException("微信退款错误");
|
||||
}
|
||||
if (!refundVo.isAllSuccess()) {
|
||||
throw new RuntimeException(refundVo.getErr_code_des());
|
||||
}
|
||||
} else if (isAliPay) {
|
||||
throw new RuntimeException("支付宝退款暂不支持");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信退款回调通知
|
||||
*/
|
||||
@Override
|
||||
public boolean wechatRefundCallback(WechantRefunCallbackVo decrypt) {
|
||||
try {
|
||||
Long orderId = Long.valueOf(decrypt.getOut_trade_no());
|
||||
Long refunId = Long.valueOf(decrypt.getOut_refund_no());
|
||||
// 查询订单
|
||||
HardOrderEntity order = hardOrderService.getById(orderId);
|
||||
if (ObjectUtil.isEmpty(order)) {
|
||||
log.error("微信退款回调通知,订单不存在orderId:{}", orderId);
|
||||
return false;
|
||||
}
|
||||
// 查询售后单
|
||||
HardAfterSaleEntity afterSale = baseMapper.selectById(refunId);
|
||||
if (ObjectUtil.isEmpty(afterSale)) {
|
||||
log.error("微信退款回调通知,售后单不存在refunId:{}", refunId);
|
||||
return false;
|
||||
}
|
||||
if (ObjectUtil.equals(afterSale.getStatus(), HardSaleStatusEnum.COMPLETE.getStatus())) {
|
||||
log.error("微信退款回调通知,售后单已处理完成refunId:{}", refunId);
|
||||
return false;
|
||||
}
|
||||
HardOrderEntity updateObj = HardOrderEntity.builder()
|
||||
.id(order.getId())
|
||||
.orderStatus(HardOrderStatusEnum.REFUND.getType())
|
||||
.refundStatus(HardRefundStatusEnum.SUCCESS.getStatus())
|
||||
.payRefundId(orderId)
|
||||
.refundPrice(Integer.valueOf(decrypt.getRefund_fee()))
|
||||
.refundTime(LocalDateTime.now())
|
||||
.build();
|
||||
hardOrderService.updateById(updateObj);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("微信退款回调通知失败", e);
|
||||
return false;
|
||||
}
|
||||
WalletRechargeVo walletRefund = walletRefundResult.getData();
|
||||
HardOrderEntity updateObj = HardOrderEntity.builder()
|
||||
.id(order.getId())
|
||||
.orderStatus(HardOrderStatusEnum.REFUND.getType())
|
||||
.refundStatus(HardRefundStatusEnum.SUCCESS.getStatus())
|
||||
.payRefundId(walletRefund.getId())
|
||||
.refundPrice(refundTotalPrice + refundPrice)
|
||||
.refundTime(LocalDateTime.now())
|
||||
.build();
|
||||
hardOrderService.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+19
-17
@@ -301,7 +301,6 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
// 微信支付
|
||||
if (isWeChatPay) {
|
||||
WechatMicropayDto wechatPayDto = WechatMicropayDto.builder().merId(orderObj.getMerchantId()).orderId(orderObj.getId()).price(payPrice).wechatQrCode(String.valueOf(dto.getOrderSourceTypeId())).build();
|
||||
wechatPayDto.setPrice(1);
|
||||
WechatMicropayVo wechatPayVo = wechatPayService.micropay(wechatPayDto);
|
||||
if (ObjectUtil.isEmpty(wechatPayVo)) {
|
||||
throw new RuntimeException("微信支付失败");
|
||||
@@ -312,12 +311,12 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
wechatPayService.reverse(WechantReverseDto.builder().orderId(orderObj.getId()).build());
|
||||
throw new RuntimeException(wechatPayVo.getErr_code_des());
|
||||
} else {
|
||||
getSelf().orderSuccess(orderObj, isWalletPay);
|
||||
getSelf().orderSuccess(orderObj, Boolean.TRUE);
|
||||
}
|
||||
}
|
||||
// 支付宝支付
|
||||
if (isAliPay) {
|
||||
throw new RuntimeException("支付宝支付失败");
|
||||
throw new RuntimeException("支付宝支付失败,暂不支持");
|
||||
}
|
||||
// 发送mq消息
|
||||
getSelf().createOrderAfterSendMqMsg(orderObj.getId(), userDetail);
|
||||
@@ -875,6 +874,23 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否需要支付
|
||||
*/
|
||||
@Override
|
||||
public boolean isPay(HardOrderTypeEnum type, HardPayTypeEnum payType) {
|
||||
if (ObjectUtil.equals(type, HardOrderTypeEnum.BELOW) && ObjectUtil.equals(payType, HardPayTypeEnum.CASH)) {
|
||||
return false;
|
||||
}
|
||||
if (!HardOrderTypeEnum.isPay(type)) {
|
||||
return false;
|
||||
}
|
||||
if (HardPayTypeEnum.isNotWalletPay.contains(payType)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 二维码类型的订单是否被核销 true被核销 false未核销
|
||||
private boolean validateCodeIsCancel(HardOrderTypeEnum orderType, Long orderId) {
|
||||
Boolean flag = switch (orderType) {
|
||||
@@ -891,20 +907,6 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
return flag;
|
||||
}
|
||||
|
||||
// 是否需要支付
|
||||
private boolean isPay(HardOrderTypeEnum type, HardPayTypeEnum payType) {
|
||||
if (ObjectUtil.equals(type, HardOrderTypeEnum.BELOW) && ObjectUtil.equals(payType, HardPayTypeEnum.CASH)) {
|
||||
return false;
|
||||
}
|
||||
if (!HardOrderTypeEnum.isPay(type)) {
|
||||
return false;
|
||||
}
|
||||
if (HardPayTypeEnum.isNotWalletPay.contains(payType)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 是否需要核销
|
||||
private boolean isVerify(HardPayTypeEnum payType) {
|
||||
return HardPayTypeEnum.isNeedCancel.contains(payType);
|
||||
|
||||
+7
-2
@@ -9,11 +9,13 @@ import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.hard.api.dto.wechat.*;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.*;
|
||||
import com.bsd.pjcloud.hard.config.WechatPay;
|
||||
import com.bsd.pjcloud.hard.service.HardAfterSaleService;
|
||||
import com.bsd.pjcloud.hard.service.WechatPayService;
|
||||
import com.bsd.pjcloud.hard.utils.constant.WechantPayConstant;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -38,6 +40,9 @@ public class WechatPayServiceImpl implements WechatPayService {
|
||||
|
||||
private final WechatPay wechatPay;
|
||||
|
||||
@Lazy
|
||||
private final HardAfterSaleService hardAfterSaleService;
|
||||
|
||||
/**
|
||||
* 生成微信支付签名
|
||||
*/
|
||||
@@ -366,7 +371,7 @@ public class WechatPayServiceImpl implements WechatPayService {
|
||||
// 告诉微信错误
|
||||
return WechantRefunCallbackVo.wechantError();
|
||||
}
|
||||
|
||||
return WechantRefunCallbackVo.wechantError();
|
||||
boolean isSuccess = hardAfterSaleService.wechatRefundCallback(decrypt);
|
||||
return isSuccess ? WechantRefunCallbackVo.wechantSuccess() : WechantRefunCallbackVo.wechantError();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user