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 | 14 | |
| 15 | 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 | 22 | */ |
| 23 | 23 | default int updateWhenConsumptionRefund(Integer price, Long id){ |
| 24 | 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 | 27 | .eq(PayWalletDO::getId, id); |
| 27 | 28 | return update(null, lambdaUpdateWrapper); |
| 28 | 29 | } |
| ... | ... | @@ -35,7 +36,8 @@ public interface PayWalletMapper extends BaseMapperX<PayWalletDO> { |
| 35 | 36 | */ |
| 36 | 37 | default int updateWhenConsumption(Integer price, Long id){ |
| 37 | 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 | 41 | .eq(PayWalletDO::getId, id) |
| 40 | 42 | .ge(PayWalletDO::getBalance, price); // cas 逻辑 |
| 41 | 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 | 112 | @Override |
| 113 | 113 | public PayWalletTransactionDO reduceWalletBalance(Long userId, Integer userType, |
| 114 | 114 | Long bizId, PayWalletBizTypeEnum bizType, Integer price) { |
| 115 | - // 1.1 获取钱包 | |
| 115 | + // 1. 获取钱包 | |
| 116 | 116 | PayWalletDO payWallet = getOrCreateWallet(userId, userType); |
| 117 | + | |
| 117 | 118 | // 2.1 扣除余额 |
| 118 | - int number = 0 ; | |
| 119 | + int updateCounts = 0 ; | |
| 119 | 120 | switch (bizType) { |
| 120 | 121 | case PAYMENT: { |
| 121 | - number = walletMapper.updateWhenConsumption(price, payWallet.getId()); | |
| 122 | + updateCounts = walletMapper.updateWhenConsumption(price, payWallet.getId()); | |
| 122 | 123 | break; |
| 123 | 124 | } |
| 124 | 125 | case RECHARGE_REFUND: { |
| ... | ... | @@ -126,11 +127,11 @@ public class PayWalletServiceImpl implements PayWalletService { |
| 126 | 127 | break; |
| 127 | 128 | } |
| 128 | 129 | } |
| 129 | - if (number == 0) { | |
| 130 | + if (updateCounts == 0) { | |
| 130 | 131 | throw exception(WALLET_BALANCE_NOT_ENOUGH); |
| 131 | 132 | } |
| 132 | - int afterBalance = payWallet.getBalance() - price; | |
| 133 | 133 | // 2.2 生成钱包流水 |
| 134 | + Integer afterBalance = payWallet.getBalance() - price; | |
| 134 | 135 | CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) |
| 135 | 136 | .setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId)) |
| 136 | 137 | .setBizType(bizType.getType()).setTitle(bizType.getDescription()); |
| ... | ... | @@ -140,7 +141,7 @@ public class PayWalletServiceImpl implements PayWalletService { |
| 140 | 141 | @Override |
| 141 | 142 | public PayWalletTransactionDO addWalletBalance(Long userId, Integer userType, |
| 142 | 143 | Long bizId, PayWalletBizTypeEnum bizType, Integer price) { |
| 143 | - // 获取钱包 | |
| 144 | + // 1. 获取钱包 | |
| 144 | 145 | PayWalletDO payWallet = getOrCreateWallet(userId, userType); |
| 145 | 146 | switch (bizType) { |
| 146 | 147 | case PAYMENT_REFUND: { |
| ... | ... | @@ -153,7 +154,8 @@ public class PayWalletServiceImpl implements PayWalletService { |
| 153 | 154 | break; |
| 154 | 155 | } |
| 155 | 156 | } |
| 156 | - // 2.2 生成钱包流水 | |
| 157 | + | |
| 158 | + // 2. 生成钱包流水 | |
| 157 | 159 | CreateWalletTransactionBO bo = new CreateWalletTransactionBO().setWalletId(payWallet.getId()) |
| 158 | 160 | .setPrice(price).setBalance(payWallet.getBalance()+price).setBizId(String.valueOf(bizId)) |
| 159 | 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 | import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; |
| 7 | 7 | import cn.iocoder.yudao.module.pay.service.wallet.bo.CreateWalletTransactionBO; |
| 8 | 8 | |
| 9 | +import javax.validation.Valid; | |
| 10 | + | |
| 9 | 11 | /** |
| 10 | 12 | * 钱包余额流水 Service 接口 |
| 11 | 13 | * |
| ... | ... | @@ -29,7 +31,7 @@ public interface PayWalletTransactionService { |
| 29 | 31 | * @param bo 创建钱包流水 bo |
| 30 | 32 | * @return 新建的钱包 do |
| 31 | 33 | */ |
| 32 | - PayWalletTransactionDO createWalletTransaction(CreateWalletTransactionBO bo); | |
| 34 | + PayWalletTransactionDO createWalletTransaction(@Valid CreateWalletTransactionBO bo); | |
| 33 | 35 | |
| 34 | 36 | /** |
| 35 | 37 | * 根据 no,获取钱包余流水 |
| ... | ... | @@ -46,4 +48,5 @@ public interface PayWalletTransactionService { |
| 46 | 48 | * @return 钱包流水 |
| 47 | 49 | */ |
| 48 | 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 | 22 | @Service |
| 23 | 23 | @Slf4j |
| 24 | 24 | public class PayWalletTransactionServiceImpl implements PayWalletTransactionService { |
| 25 | + | |
| 25 | 26 | /** |
| 26 | 27 | * 钱包流水的 no 前缀 |
| 27 | 28 | */ |
| 28 | 29 | private static final String WALLET_NO_PREFIX = "W"; |
| 30 | + | |
| 29 | 31 | @Resource |
| 30 | 32 | private PayWalletService payWalletService; |
| 31 | 33 | @Resource |
| ... | ... | @@ -42,10 +44,10 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ |
| 42 | 44 | |
| 43 | 45 | @Override |
| 44 | 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 | 53 | @Override |
| ... | ... | @@ -57,4 +59,5 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ |
| 57 | 59 | public PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type) { |
| 58 | 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