Commit cd51d57f122ad8d74c5ade811098472b17860ecb
1 parent
426594ae
分销:调整 app 的 price 到 brokeragePrice
Showing
6 changed files
with
28 additions
and
15 deletions
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java
| @@ -14,5 +14,6 @@ public interface PayWalletTransactionConvert { | @@ -14,5 +14,6 @@ public interface PayWalletTransactionConvert { | ||
| 14 | 14 | ||
| 15 | PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page); | 15 | PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page); |
| 16 | 16 | ||
| 17 | - PayWalletTransactionDO convert(CreateWalletTransactionBO bo); | 17 | + PayWalletTransactionDO convert(CreateWalletTransactionBO bean); |
| 18 | + | ||
| 18 | } | 19 | } |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletMapper.java
| @@ -22,7 +22,8 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { | @@ -22,7 +22,8 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { | ||
| 22 | */ | 22 | */ |
| 23 | default int updateWhenConsumptionRefund(Integer price, Long id){ | 23 | default int updateWhenConsumptionRefund(Integer price, Long id){ |
| 24 | LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() | 24 | LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() |
| 25 | - .setSql(" balance = balance + " + price + ", total_expense = total_expense - " + price) | 25 | + .setSql(" balance = balance + " + price |
| 26 | + + ", total_expense = total_expense - " + price) | ||
| 26 | .eq(PayWalletDO::getId, id); | 27 | .eq(PayWalletDO::getId, id); |
| 27 | return update(null, lambdaUpdateWrapper); | 28 | return update(null, lambdaUpdateWrapper); |
| 28 | } | 29 | } |
| @@ -35,7 +36,8 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { | @@ -35,7 +36,8 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { | ||
| 35 | */ | 36 | */ |
| 36 | default int updateWhenConsumption(Integer price, Long id){ | 37 | default int updateWhenConsumption(Integer price, Long id){ |
| 37 | LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() | 38 | LambdaUpdateWrapper<PayWalletDO> lambdaUpdateWrapper = new LambdaUpdateWrapper<PayWalletDO>() |
| 38 | - .setSql(" balance = balance - " + price + ", total_expense = total_expense + " + price) | 39 | + .setSql(" balance = balance - " + price |
| 40 | + + ", total_expense = total_expense + " + price) | ||
| 39 | .eq(PayWalletDO::getId, id) | 41 | .eq(PayWalletDO::getId, id) |
| 40 | .ge(PayWalletDO::getBalance, price); // cas 逻辑 | 42 | .ge(PayWalletDO::getBalance, price); // cas 逻辑 |
| 41 | return update(null, lambdaUpdateWrapper); | 43 | return update(null, lambdaUpdateWrapper); |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
| @@ -112,13 +112,14 @@ public class PayWalletServiceImpl implements PayWalletService { | @@ -112,13 +112,14 @@ public class PayWalletServiceImpl implements PayWalletService { | ||
| 112 | @Override | 112 | @Override |
| 113 | public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, | 113 | public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, |
| 114 | Long bizId, PayWalletBizTypeEnum bizType, Integer price) { | 114 | Long bizId, PayWalletBizTypeEnum bizType, Integer price) { |
| 115 | - // 1.1 获取钱包 | 115 | + // 1. 获取钱包 |
| 116 | PayWalletDO payWallet = getOrCreateWallet(userId, userType); | 116 | PayWalletDO payWallet = getOrCreateWallet(userId, userType); |
| 117 | + | ||
| 117 | // 2.1 扣除余额 | 118 | // 2.1 扣除余额 |
| 118 | - int number = 0 ; | 119 | + int updateCounts = 0 ; |
| 119 | switch (bizType) { | 120 | switch (bizType) { |
| 120 | case PAYMENT: { | 121 | case PAYMENT: { |
| 121 | - number = walletMapper.updateWhenConsumption(price, payWallet.getId()); | 122 | + updateCounts = walletMapper.updateWhenConsumption(price, payWallet.getId()); |
| 122 | break; | 123 | break; |
| 123 | } | 124 | } |
| 124 | case RECHARGE_REFUND: { | 125 | case RECHARGE_REFUND: { |
| @@ -126,11 +127,11 @@ public class PayWalletServiceImpl implements PayWalletService { | @@ -126,11 +127,11 @@ public class PayWalletServiceImpl implements PayWalletService { | ||
| 126 | break; | 127 | break; |
| 127 | } | 128 | } |
| 128 | } | 129 | } |
| 129 | - if (number == 0) { | 130 | + if (updateCounts == 0) { |
| 130 | throw exception(WALLET_BALANCE_NOT_ENOUGH); | 131 | throw exception(WALLET_BALANCE_NOT_ENOUGH); |
| 131 | } | 132 | } |
| 132 | - int afterBalance = payWallet.getBalance() - price; | ||
| 133 | // 2.2 生成钱包流水 | 133 | // 2.2 生成钱包流水 |
| 134 | + Integer afterBalance = payWallet.getBalance() - price; | ||
| 134 | CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) | 135 | CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) |
| 135 | .setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId)) | 136 | .setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId)) |
| 136 | .setBizType(bizType.getType()).setTitle(bizType.getDescription()); | 137 | .setBizType(bizType.getType()).setTitle(bizType.getDescription()); |
| @@ -140,7 +141,7 @@ public class PayWalletServiceImpl implements PayWalletService { | @@ -140,7 +141,7 @@ public class PayWalletServiceImpl implements PayWalletService { | ||
| 140 | @Override | 141 | @Override |
| 141 | public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, | 142 | public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, |
| 142 | Long bizId, PayWalletBizTypeEnum bizType, Integer price) { | 143 | Long bizId, PayWalletBizTypeEnum bizType, Integer price) { |
| 143 | - // 获取钱包 | 144 | + // 1. 获取钱包 |
| 144 | PayWalletDO payWallet = getOrCreateWallet(userId, userType); | 145 | PayWalletDO payWallet = getOrCreateWallet(userId, userType); |
| 145 | switch (bizType) { | 146 | switch (bizType) { |
| 146 | case PAYMENT_REFUND: { | 147 | case PAYMENT_REFUND: { |
| @@ -153,7 +154,8 @@ public class PayWalletServiceImpl implements PayWalletService { | @@ -153,7 +154,8 @@ public class PayWalletServiceImpl implements PayWalletService { | ||
| 153 | break; | 154 | break; |
| 154 | } | 155 | } |
| 155 | } | 156 | } |
| 156 | - // 2.2 生成钱包流水 | 157 | + |
| 158 | + // 2. 生成钱包流水 | ||
| 157 | CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) | 159 | CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) |
| 158 | .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(String.valueOf(bizId)) | 160 | .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(String.valueOf(bizId)) |
| 159 | .setBizType(bizType.getType()).setTitle(bizType.getDescription()); | 161 | .setBizType(bizType.getType()).setTitle(bizType.getDescription()); |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java
| @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; | @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; | ||
| 6 | import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; | 6 | import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; |
| 7 | import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; | 7 | import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; |
| 8 | 8 | ||
| 9 | +import javax.validation.Valid; | ||
| 10 | + | ||
| 9 | /** | 11 | /** |
| 10 | * 钱包余额流水 Service 接口 | 12 | * 钱包余额流水 Service 接口 |
| 11 | * | 13 | * |
| @@ -29,7 +31,7 @@ public interface PayWalletTransactionService { | @@ -29,7 +31,7 @@ public interface PayWalletTransactionService { | ||
| 29 | * @param bo 创建钱包流水 bo | 31 | * @param bo 创建钱包流水 bo |
| 30 | * @return 新建的钱包 do | 32 | * @return 新建的钱包 do |
| 31 | */ | 33 | */ |
| 32 | - PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo); | 34 | + PayWalletTransactionDO createWalletTransaction(@Valid CreateWalletTransactionBO bo); |
| 33 | 35 | ||
| 34 | /** | 36 | /** |
| 35 | * 根据 no,获取钱包余流水 | 37 | * 根据 no,获取钱包余流水 |
| @@ -46,4 +48,5 @@ public interface PayWalletTransactionService { | @@ -46,4 +48,5 @@ public interface PayWalletTransactionService { | ||
| 46 | * @return 钱包流水 | 48 | * @return 钱包流水 |
| 47 | */ | 49 | */ |
| 48 | PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type); | 50 | PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type); |
| 51 | + | ||
| 49 | } | 52 | } |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java
| @@ -22,10 +22,12 @@ import javax.annotation.Resource; | @@ -22,10 +22,12 @@ import javax.annotation.Resource; | ||
| 22 | @Service | 22 | @Service |
| 23 | @Slf4j | 23 | @Slf4j |
| 24 | public class PayWalletTransactionServiceImpl implements PayWalletTransactionService { | 24 | public class PayWalletTransactionServiceImpl implements PayWalletTransactionService { |
| 25 | + | ||
| 25 | /** | 26 | /** |
| 26 | * 钱包流水的 no 前缀 | 27 | * 钱包流水的 no 前缀 |
| 27 | */ | 28 | */ |
| 28 | private static final String WALLET_NO_PREFIX = "W"; | 29 | private static final String WALLET_NO_PREFIX = "W"; |
| 30 | + | ||
| 29 | @Resource | 31 | @Resource |
| 30 | private PayWalletService payWalletService; | 32 | private PayWalletService payWalletService; |
| 31 | @Resource | 33 | @Resource |
| @@ -42,10 +44,10 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ | @@ -42,10 +44,10 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ | ||
| 42 | 44 | ||
| 43 | @Override | 45 | @Override |
| 44 | public PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo) { | 46 | public PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo) { |
| 45 | - PayWalletTransactionDO transactionDO = PayWalletTransactionConvert.INSTANCE.convert(bo); | ||
| 46 | - transactionDO.setNo(noRedisDAO.generate(WALLET_NO_PREFIX)); | ||
| 47 | - payWalletTransactionMapper.insert(transactionDO); | ||
| 48 | - return transactionDO; | 47 | + PayWalletTransactionDO transaction = PayWalletTransactionConvert.INSTANCE.convert(bo) |
| 48 | + .setNo(noRedisDAO.generate(WALLET_NO_PREFIX)); | ||
| 49 | + payWalletTransactionMapper.insert(transaction); | ||
| 50 | + return transaction; | ||
| 49 | } | 51 | } |
| 50 | 52 | ||
| 51 | @Override | 53 | @Override |
| @@ -57,4 +59,5 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ | @@ -57,4 +59,5 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ | ||
| 57 | public PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type) { | 59 | public PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type) { |
| 58 | return payWalletTransactionMapper.selectByBiz(bizId, type.getType()); | 60 | return payWalletTransactionMapper.selectByBiz(bizId, type.getType()); |
| 59 | } | 61 | } |
| 62 | + | ||
| 60 | } | 63 | } |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/bo/CreateWalletTransactionBO.java