gongzuming
2024-10-27 c25b0632e4a360f7499f1c79ff1d70a67919e008
src/main/java/com/mzl/flower/service/impl/wallet/WalletWithdrawRecordServiceImpl.java
@@ -128,7 +128,11 @@
                    withdrawRecordDO.setWithdrawState(Constants.WALLET_WITHDRAW_STATE.WAITING.name());
                    withdrawRecordDO.setMethod(Constants.WALLET_WITHDRAW_METHOD.WEIXIN.name());
                    withdrawRecordDO.setWithdrawType(Constants.WALLET_WITHDRAW_TYPE.BALANCE.name());
                    // 待审核状态
                    withdrawRecordDO.setApproveState(Constants.WALLET_APPROVE_STATE.WAITING.name());
                    withdrawRecordDO.create(SecurityUtils.getUserId());
                    // 保存余额提现记录
                    save(withdrawRecordDO);
@@ -244,7 +248,7 @@
            }
            //记录转账状态,定时任务定时获取状态并更新钱包交易记录表信息
            walletBillRecordDO.setTransferDetailId(Constants.TRANSFER_STATUS.ACCEPTED.name());
            walletBillRecordDO.setRemark("账户资金提现中");
            walletBillRecordMapper.insert(walletBillRecordDO);
            //不需要更新结算单了,此时提现的金额和计算单上的金额不一致
        }
@@ -252,13 +256,25 @@
        if (Constants.WALLET_APPROVE_STATE.REJECT.name().equals(walletWithdrawRecordDTO.getApproveState())) {
            //更新钱包
            Supplier s = supplierMapper.selectById(withdrawRecordDO.getSupplierId());
            WalletDO walletDO = walletService.getBySupplierId(s.getId());
            if(!ObjectUtils.isEmpty(walletDO)){
                //提现中金额:审核失败体现中金额扣减
                walletDO.setWithdrawingAmount(walletDO.getWithdrawingAmount().subtract(withdrawRecordDO.getAmount()));
                //可提现金额:审核失败可提现金额增加
                walletDO.setWithdrawableAmount(walletDO.getWithdrawableAmount().add(withdrawRecordDO.getAmount()));
                walletMapper.updateById(walletDO);
            WalletDO walletDO = walletService.getOrCreateBySupplierId(s.getId());
            RLock lock = redissonClient.getLock(String.format(LockConstants.WALLET_ID_KEY, walletDO.getId()));
            try {
                if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
                    try {
                        if (!ObjectUtils.isEmpty(walletDO)) {
                            //提现中金额:审核失败体现中金额扣减
                            walletDO.setWithdrawingAmount(walletDO.getWithdrawingAmount().subtract(withdrawRecordDO.getAmount()));
                            //可提现金额:审核失败可提现金额增加
                            walletDO.setWithdrawableAmount(walletDO.getWithdrawableAmount().add(withdrawRecordDO.getAmount()));
                            walletMapper.updateById(walletDO);
                        }
                    } finally {
                        lock.unlock();
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }