diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java index 5825c83e5..03e6bb613 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java @@ -27,6 +27,12 @@ public interface PayClientFactory { void createOrUpdatePayClient(Long channelId, String channelCode, Config config); - void createOrUpdateDelegatePayClient(Long channelId, DelegatePayClient delegatePayClient); + /** + * 新增或更新代理支付客户端 + * @param channelId 渠道编号 + * @param delegatePayClient 代理支付客户端 + * @param 支付配置 + */ + void addOrUpdateDelegatePayClient(Long channelId, DelegatePayClient delegatePayClient); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java index e8ae76607..eb11009d7 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java @@ -53,7 +53,7 @@ public class PayClientFactoryImpl implements PayClientFactory { } @Override - public void createOrUpdateDelegatePayClient(Long channelId, DelegatePayClient delegatePayClient) { + public void addOrUpdateDelegatePayClient(Long channelId, DelegatePayClient delegatePayClient) { clients.put(channelId, delegatePayClient); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/delegate/DelegatePayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/delegate/DelegatePayClient.java index e700c70ec..dc567765c 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/delegate/DelegatePayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/delegate/DelegatePayClient.java @@ -10,6 +10,8 @@ import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; import java.util.Map; /** + * 代理支付 Client 的抽象类。用于支付 Client 由其它模块实现, 例如钱包支付 + * * @author jason */ public abstract class DelegatePayClient extends AbstractPayClient { diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java index 5b244b79f..dd435c9be 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java @@ -44,6 +44,9 @@ public interface ErrorCodeConstants { // ========== 钱包模块(退款) 1007007000 ========== ErrorCode WALLET_NOT_FOUND = new ErrorCode(1007007000, "用户钱包不存在"); ErrorCode WALLET_NOT_ENOUGH = new ErrorCode(1007007001, "钱包余额不足"); + ErrorCode WALLET_TRANSACTION_NOT_FOUND = new ErrorCode(1007007002, "未找到对应的钱包交易"); + ErrorCode WALLET_REFUND_AMOUNT_ERROR = new ErrorCode(1007007003, "钱包退款金额不对"); + ErrorCode WALLET_REFUND_EXIST = new ErrorCode(1007007004, "已经存在钱包退款"); // ========== 示例订单 1007900000 ========== ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1007900000, "示例订单不存在"); diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletBizTypeEnum.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletBizTypeEnum.java index 1ea73d8b0..d5c714e2a 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletBizTypeEnum.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletBizTypeEnum.java @@ -13,7 +13,8 @@ import lombok.Getter; public enum WalletBizTypeEnum { RECHARGE(1, "充值"), RECHARGE_REFUND(2, "充值退款"), - PAYMENT(3, "支付"); + PAYMENT(3, "支付"), + PAYMENT_REFUND(4, "支付退款"); // TODO 后续增加 /** diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/refund/PayRefundMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/refund/PayRefundMapper.java index af5fad77b..f018063fe 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/refund/PayRefundMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/refund/PayRefundMapper.java @@ -37,6 +37,11 @@ public interface PayRefundMapper extends BaseMapperX { .eq(PayRefundDO::getNo, no)); } + default PayRefundDO selectByNo(String no){ + return selectOne(new LambdaQueryWrapperX() + .eq(PayRefundDO::getNo, no)); + } + default int updateByIdAndStatus(Long id, Integer status, PayRefundDO update) { return update(update, new LambdaQueryWrapper() .eq(PayRefundDO::getId, id).eq(PayRefundDO::getStatus, status)); @@ -71,5 +76,4 @@ public interface PayRefundMapper extends BaseMapperX { default List selectListByStatus(Integer status) { return selectList(PayRefundDO::getStatus, status); } - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java index 28b4a62e0..f02b6f5e7 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java @@ -26,6 +26,15 @@ public interface PayWalletTransactionMapper extends BaseMapperX { - private PayWalletService payWalletService; public WalletPayClient(Long channelId, String channelCode, NonePayClientConfig config) { @@ -38,13 +40,24 @@ public class WalletPayClient extends DelegatePayClient { @Override protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { - PayWalletTransactionDO payWalletTransaction = payWalletService.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice()); - return PayOrderRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getCreator(), - payWalletTransaction.getTransactionTime(), - reqDTO.getOutTradeNo(), ""); + try { + PayWalletTransactionDO payWalletTransaction = payWalletService.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice()); + return PayOrderRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getCreator(), + payWalletTransaction.getTransactionTime(), + reqDTO.getOutTradeNo(), "WALLET_PAY_SUCCESS"); + } catch (Throwable ex) { + log.error("[doUnifiedOrder] 失败", ex); + String errorCode = String.valueOf(INTERNAL_SERVER_ERROR); + String errorMsg = INTERNAL_SERVER_ERROR.getMsg(); + if (ex instanceof ServiceException) { + ServiceException serviceException = (ServiceException) ex; + errorCode = String.valueOf(serviceException.getCode()); + errorMsg = serviceException.getMessage(); + } + return PayOrderRespDTO.closedOf(errorCode, errorMsg, reqDTO.getOutTradeNo(), ex); + } } - @Override protected PayOrderRespDTO doParseOrderNotify(Map params, String body) { throw new UnsupportedOperationException("钱包支付无支付回调"); @@ -52,12 +65,27 @@ public class WalletPayClient extends DelegatePayClient { @Override protected PayOrderRespDTO doGetOrder(String outTradeNo) { - return null; + throw new UnsupportedOperationException("待实现"); } @Override protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) { - return null; + try { + PayWalletTransactionDO payWalletTransaction = payWalletService.refund(reqDTO.getOutRefundNo(), + reqDTO.getRefundPrice(), reqDTO.getReason()); + return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getTransactionTime(), + reqDTO.getOutRefundNo(), "WALLET_REFUND_SUCCESS"); + } catch (Throwable ex) { + log.error("[doUnifiedRefund] 失败", ex); + String errorCode = String.valueOf(INTERNAL_SERVER_ERROR); + String errorMsg = INTERNAL_SERVER_ERROR.getMsg(); + if (ex instanceof ServiceException) { + ServiceException serviceException = (ServiceException) ex; + errorCode = String.valueOf(serviceException.getCode()); + errorMsg = serviceException.getMessage(); + } + return PayRefundRespDTO.failureOf(errorCode, errorMsg, reqDTO.getOutRefundNo(), ex); + } } @Override @@ -67,6 +95,6 @@ public class WalletPayClient extends DelegatePayClient { @Override protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) { - return null; + throw new UnsupportedOperationException("待实现"); } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java index 9604ffbf7..a8317b6ed 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java @@ -81,6 +81,7 @@ public class PayChannelServiceImpl implements PayChannelService { log.error("[支付模块 yudao-module-pay - 表结构未导入][参考 https://doc.iocoder.cn/pay/build/ 开启]"); } log.info("[initLocalCache][缓存支付渠道,数量为:{}]", channels.size()); + // 钱包 client 需要和其它 client 分开了创建 List walletChannels = new ArrayList<>(); List otherChannels = new ArrayList<>(); channels.forEach(t -> { @@ -97,7 +98,7 @@ public class PayChannelServiceImpl implements PayChannelService { walletChannels.forEach(payChannel -> { WalletPayClient walletPayClient = new WalletPayClient(payChannel.getId(), payChannel.getCode(), (NonePayClientConfig) payChannel.getConfig(), payWalletService); - payClientFactory.createOrUpdateDelegatePayClient(payChannel.getId(), walletPayClient); + payClientFactory.addOrUpdateDelegatePayClient(payChannel.getId(), walletPayClient); }); this.channelCache = channels; }); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundService.java index 8a93ec4da..258cea964 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundService.java @@ -24,6 +24,14 @@ public interface PayRefundService { */ PayRefundDO getRefund(Long id); + /** + * 获得退款订单 + * + * @param no 外部退款单号 + * @return 退款订单 + */ + PayRefundDO getRefundByNo(String no); + /** * 获得指定应用的退款数量 * diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java index 4ab692b19..e4d75c035 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/refund/PayRefundServiceImpl.java @@ -74,6 +74,11 @@ public class PayRefundServiceImpl implements PayRefundService { return refundMapper.selectById(id); } + @Override + public PayRefundDO getRefundByNo(String no) { + return refundMapper.selectByNo(no); + } + @Override public Long getRefundCountByAppId(Long appId) { return refundMapper.selectCountByAppId(appId); diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java index 473e6f704..780433b71 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -17,5 +17,18 @@ public interface PayWalletService { */ PayWalletDO getPayWallet(Long userId, Integer userType); + /** + * 钱包支付 + * @param outTradeNo 外部订单号 + * @param price 金额 + */ PayWalletTransactionDO pay(String outTradeNo, Integer price); + + /** + * 钱包支付退款 + * @param outRefundNo 外部退款号 + * @param refundPrice 退款金额 + * @param reason 退款原因 + */ + PayWalletTransactionDO refund(String outRefundNo, Integer refundPrice, String reason); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index d322c73e1..f9168dbd1 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -1,18 +1,19 @@ package cn.iocoder.yudao.module.pay.service.wallet; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO; +import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletMapper; import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO; import cn.iocoder.yudao.module.pay.service.order.PayOrderService; +import cn.iocoder.yudao.module.pay.service.refund.PayRefundService; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; - import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -20,6 +21,7 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType; import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.pay.enums.member.WalletBizTypeEnum.PAYMENT; +import static cn.iocoder.yudao.module.pay.enums.member.WalletBizTypeEnum.PAYMENT_REFUND; /** * 钱包 Service 实现类 @@ -29,16 +31,20 @@ import static cn.iocoder.yudao.module.pay.enums.member.WalletBizTypeEnum.PAYMENT @Service @Slf4j public class PayWalletServiceImpl implements PayWalletService { - private static final String WALLET_CHANNEL_NO_PREFIX = "W"; - @Resource - @Lazy - private PayOrderService payOrderService; + private static final String WALLET_PAY_NO_PREFIX = "WP"; + private static final String WALLET_REFUND_NO_PREFIX = "WR"; @Resource private PayWalletMapper payWalletMapper; @Resource private PayWalletTransactionService payWalletTransactionService; @Resource private PayNoRedisDAO noRedisDAO; + @Resource + @Lazy + private PayOrderService payOrderService; + @Resource + @Lazy + private PayRefundService payRefundService; @Override public PayWalletDO getPayWallet(Long userId, Integer userType) { @@ -53,13 +59,7 @@ public class PayWalletServiceImpl implements PayWalletService { if (orderExtension == null) { throw exception(ORDER_EXTENSION_NOT_FOUND); } - Long userId = getLoginUserId(); - Integer userType = getLoginUserType(); - PayWalletDO payWallet = getPayWallet(userId, userType); - if (payWallet == null) { - log.error("[pay] 用户 {} 钱包不存在", userId); - throw exception(WALLET_NOT_FOUND); - } + PayWalletDO payWallet = validatePayWallet(); // 判断余额是否足够 int afterBalance = payWallet.getBalance() - price; if(afterBalance < 0){ @@ -70,12 +70,73 @@ public class PayWalletServiceImpl implements PayWalletService { payWalletMapper.updateById(payWallet); // 生成钱包渠道流水号 - String walletNo = noRedisDAO.generate(WALLET_CHANNEL_NO_PREFIX); + String walletNo = noRedisDAO.generate(WALLET_PAY_NO_PREFIX); PayWalletTransactionDO payWalletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) - .setNo(walletNo).setAmount(price).setBalance(afterBalance).setTransactionTime(LocalDateTime.now()) + .setNo(walletNo).setAmount(price * -1).setBalance(afterBalance).setTransactionTime(LocalDateTime.now()) .setBizId(orderExtension.getOrderId()).setBizType(PAYMENT.getBizType()); payWalletTransactionService.addPayWalletTransaction(payWalletTransaction); return payWalletTransaction; } + + private PayWalletDO validatePayWallet() { + Long userId = getLoginUserId(); + Integer userType = getLoginUserType(); + PayWalletDO payWallet = getPayWallet(userId, userType); + if (payWallet == null) { + log.error("[validatePayWallet] 用户 {} 钱包不存在", userId); + throw exception(WALLET_NOT_FOUND); + } + return payWallet; + } + + @Override + @Transactional(rollbackFor = Exception.class) + public PayWalletTransactionDO refund(String outRefundNo, Integer refundPrice, String reason) { + // 判断退款单是否存在 + PayRefundDO payRefund = payRefundService.getRefundByNo(outRefundNo); + if (payRefund == null) { + throw exception(REFUND_NOT_FOUND); + } + PayWalletDO payWallet = validatePayWallet(); + // 校验是否可以退款 + validateWalletCanRefund(payRefund.getId(), payRefund.getChannelOrderNo(), payWallet.getId(), refundPrice); + + Integer afterBalance = payWallet.getBalance() + refundPrice; + payWallet.setBalance(afterBalance); + payWallet.setTotalExpense(payWallet.getTotalExpense() + refundPrice * -1L); + payWalletMapper.updateById(payWallet); + + String walletNo = noRedisDAO.generate(WALLET_REFUND_NO_PREFIX); + PayWalletTransactionDO newWalletTransaction = new PayWalletTransactionDO().setWalletId(payWallet.getId()) + .setNo(walletNo).setAmount(refundPrice).setBalance(afterBalance).setTransactionTime(LocalDateTime.now()) + .setBizId(payRefund.getId()).setBizType(PAYMENT_REFUND.getBizType()) + .setDescription(reason); + payWalletTransactionService.addPayWalletTransaction(newWalletTransaction); + + return newWalletTransaction; + } + + /** + * 校验是否能退款 + * @param refundId 支付退款单 id + * @param walletPayNo 钱包支付 no + * @param walletId 钱包 id + */ + private void validateWalletCanRefund(long refundId, String walletPayNo, long walletId, int refundPrice) { + // 查询钱包支付交易 + PayWalletTransactionDO payWalletTransaction = payWalletTransactionService.getPayWalletTransactionByNo(walletPayNo); + if (payWalletTransaction == null) { + throw exception(WALLET_TRANSACTION_NOT_FOUND); + } + // 原来的支付金额 + int amount = payWalletTransaction.getAmount() * -1; + if (refundPrice != amount) { + throw exception(WALLET_REFUND_AMOUNT_ERROR); + } + PayWalletTransactionDO refundTransaction = payWalletTransactionService.getPayWalletTransaction(walletId, refundId, PAYMENT_REFUND); + if (refundTransaction != null) { + throw exception(WALLET_REFUND_EXIST); + } + } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java index 2ec913222..1e140f0ae 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.pay.service.wallet; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; +import cn.iocoder.yudao.module.pay.enums.member.WalletBizTypeEnum; /** * 钱包余额明细 Service 接口 @@ -21,5 +22,25 @@ public interface PayWalletTransactionService { PageResult getWalletTransactionPage(Long userId, Integer userType, AppPayWalletTransactionPageReqVO pageVO); + /** + * 新增钱包余额明细 + * @param payWalletTransaction 余额明细 + * @return id + */ Long addPayWalletTransaction(PayWalletTransactionDO payWalletTransaction); + + /** + * 获取钱包余额明细 根据 no + * @param no 流水号 + */ + PayWalletTransactionDO getPayWalletTransactionByNo(String no); + + /** + * 获取钱包 + * @param walletId 钱包 id + * @param bizId 业务编号 + * @param typeEnum 业务类型 + * @return 钱包余额明细 + */ + PayWalletTransactionDO getPayWalletTransaction(Long walletId, Long bizId, WalletBizTypeEnum typeEnum); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java index e62edf549..320321a63 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransact import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletTransactionMapper; +import cn.iocoder.yudao.module.pay.enums.member.WalletBizTypeEnum; import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -45,5 +46,15 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ return payWalletTransaction.getId(); } + @Override + public PayWalletTransactionDO getPayWalletTransactionByNo(String no) { + return payWalletTransactionMapper.selectByNo(no); + } + + @Override + public PayWalletTransactionDO getPayWalletTransaction(Long walletId, Long bizId, WalletBizTypeEnum typeEnum) { + return payWalletTransactionMapper.selectByWalletIdAndBiz(walletId, bizId, typeEnum.getBizType()); + } + }