From 8cbdd19f5ceca9614da4b77426ba27a6baa34007 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Sun, 28 Aug 2022 23:54:00 +0800
Subject: [PATCH] fix
---
src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java | 4 ++--
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java | 6 +++---
src/main/java/cc/mrbird/febs/dapp/service/impl/BscCoinContractEvent.java | 2 +-
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java | 36 +++++++++++++++++++++++++++---------
4 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java b/src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java
index 213ee72..3376782 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java
@@ -35,8 +35,8 @@
void withdraw(WithdrawDto withdrawDto);
- void updateWalletCoinWithLock(BigDecimal amount, Long memberId);
+ void updateWalletCoinWithLock(BigDecimal amount, Long memberId, int type);
- void updateWalletMineWithLock(BigDecimal amount, Long memberId);
+ void updateWalletMineWithLock(BigDecimal amount, Long memberId, int type);
}
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/BscCoinContractEvent.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/BscCoinContractEvent.java
index 968c301..c1747b9 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/impl/BscCoinContractEvent.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/BscCoinContractEvent.java
@@ -114,7 +114,7 @@
fundFlow.setStatus(2);
dappFundFlowDao.updateById(fundFlow);
- dappWalletService.updateWalletMineWithLock(amount, fromMember.getId());
+ dappWalletService.updateWalletMineWithLock(amount, fromMember.getId(), 1);
}
}
}
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
index a43e135..ad5521a 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -164,7 +164,7 @@
if (parent != null) {
BigDecimal directProfit = new BigDecimal("100").multiply(new BigDecimal("0.15"));
- dappWalletService.updateWalletCoinWithLock(directProfit, parent.getId());
+ dappWalletService.updateWalletCoinWithLock(directProfit, parent.getId(), 1);
DappFundFlowEntity fundFlow = new DappFundFlowEntity(parent.getId(), directProfit, 3, 2, null, null);
dappFundFlowDao.insert(fundFlow);
@@ -175,7 +175,7 @@
member.setOutCnt(member.getOutCnt() + 1);
dappMemberDao.updateById(member);
- dappWalletService.updateWalletCoinWithLock(new BigDecimal(190), member.getId());
+ dappWalletService.updateWalletCoinWithLock(new BigDecimal(190), member.getId(), 1);
DappFundFlowEntity matrixProfitFlow = new DappFundFlowEntity(memberId, new BigDecimal("190"), 2, 2, null, null);
dappFundFlowDao.insert(matrixProfitFlow);
@@ -215,7 +215,7 @@
BigDecimal preAmount = mineDataEntity.getSafePool().divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP);
list.forEach(item -> {
- dappWalletService.updateWalletCoinWithLock(preAmount, item.getMidNode());
+ dappWalletService.updateWalletCoinWithLock(preAmount, item.getMidNode(), 1);
DappFundFlowEntity flow = new DappFundFlowEntity(item.getMidNode(), preAmount, 8, 2, null, null);
dappFundFlowDao.insert(flow);
});
diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
index 37baa79..5bf5bba 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -135,7 +135,7 @@
throw new FebsException("Balance Not Enough");
}
- updateWalletCoinWithLock(transferDto.getAmount().negate(), member.getId());
+ updateWalletCoinWithLock(transferDto.getAmount(), member.getId(), 2);
DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount().negate(), 1, 2, transferDto.getFee(), transferDto.getTxHash());
dappFundFlowDao.insert(fundFlow);
@@ -192,8 +192,8 @@
throw new FebsException("TFC Not Enough");
}
- updateWalletCoinWithLock(withdrawDto.getAmount().negate(), member.getId());
- updateWalletMineWithLock(withdrawDto.getFee().negate(), member.getId());
+ updateWalletCoinWithLock(withdrawDto.getAmount(), member.getId(), 2);
+ updateWalletMineWithLock(withdrawDto.getFee(), member.getId(), 2);
DappFundFlowEntity feeFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getFee().negate(), 7, 2, null, null);
dappFundFlowDao.insert(feeFlow);
@@ -212,13 +212,23 @@
}
@Override
- public void updateWalletCoinWithLock(BigDecimal amount, Long memberId) {
+ public void updateWalletCoinWithLock(BigDecimal amount, Long memberId, int type) {
boolean isSuccess = false;
while(!isSuccess) {
DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(memberId);
- walletCoin.setTotalAmount(walletCoin.getTotalAmount().add(amount));
- walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().add(amount));
+ // 加
+ if (type == 1) {
+ walletCoin.setTotalAmount(walletCoin.getTotalAmount().add(amount));
+ walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().add(amount));
+ // 减
+ } else {
+ if (amount.compareTo(walletCoin.getAvailableAmount()) < 0) {
+ throw new FebsException("Balance Not Enough");
+ }
+ walletCoin.setTotalAmount(walletCoin.getTotalAmount().subtract(amount));
+ walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().subtract(amount));
+ }
int i = dappWalletCoinDao.updateWithLock(walletCoin);
if (i > 0) {
@@ -228,13 +238,21 @@
}
@Override
- public void updateWalletMineWithLock(BigDecimal amount, Long memberId) {
+ public void updateWalletMineWithLock(BigDecimal amount, Long memberId, int type) {
boolean isSuccess = false;
while(!isSuccess) {
DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(memberId);
- walletMine.setTotalAmount(walletMine.getTotalAmount().add(amount));
- walletMine.setAvailableAmount(walletMine.getAvailableAmount().add(amount));
+ if (type == 1) {
+ walletMine.setTotalAmount(walletMine.getTotalAmount().add(amount));
+ walletMine.setAvailableAmount(walletMine.getAvailableAmount().add(amount));
+ } else {
+ if (amount.compareTo(walletMine.getAvailableAmount()) < 0) {
+ throw new FebsException("TFC Not Enough");
+ }
+ walletMine.setTotalAmount(walletMine.getTotalAmount().subtract(amount));
+ walletMine.setAvailableAmount(walletMine.getAvailableAmount().subtract(amount));
+ }
int i = dappWalletMineDao.updateWithLock(walletMine);
if (i > 0) {
--
Gitblit v1.9.1