From afe2e9a2da152a9b1a54d88b7637e811bf298749 Mon Sep 17 00:00:00 2001 From: wzy <wzy19931122ai@163.com> Date: Sat, 27 Aug 2022 00:39:49 +0800 Subject: [PATCH] finish matrix profit --- src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java | 49 +++++++++++++++++++------------------------------ 1 files changed, 19 insertions(+), 30 deletions(-) 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 22af2e1..0c487d5 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 @@ -13,7 +13,6 @@ import cc.mrbird.febs.dapp.dto.*; import cc.mrbird.febs.dapp.entity.*; import cc.mrbird.febs.dapp.mapper.*; -import cc.mrbird.febs.dapp.service.DappSystemService; import cc.mrbird.febs.dapp.service.DappWalletService; import cc.mrbird.febs.dapp.utils.BoxUtil; import cc.mrbird.febs.dapp.vo.ActiveNftListVo; @@ -53,7 +52,6 @@ private final DappAccountMoneyChangeDao dappAccountMoneyChangeDao; private final RedisUtils redisUtils; private final DataDictionaryCustomMapper dataDictionaryCustomMapper; - private final DappSystemService dappSystemService; private final DappNftActivationDao dappNftActivationDao; private final ChainProducer chainProducer; @@ -228,12 +226,10 @@ if (transferDto.getAmount().compareTo(walletCoin.getAvailableAmount()) > 0) { throw new FebsException("Balance Not Enough"); } - walletCoin.setTotalAmount(walletCoin.getTotalAmount().subtract(transferDto.getAmount())); - walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().subtract(transferDto.getAmount())); - dappWalletCoinDao.updateById(walletCoin); + updateWalletCoinWithLock(transferDto.getAmount().negate(), member.getId()); - DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount(), 1, 2, transferDto.getFee(), transferDto.getTxHash()); + DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount().negate(), 1, 2, transferDto.getFee(), transferDto.getTxHash()); dappFundFlowDao.insert(fundFlow); chainProducer.sendAchieveTreeMsg(member.getId()); @@ -260,30 +256,7 @@ @Override public Map<String, BigDecimal> calPrice(PriceDto priceDto) { - DappMemberEntity member = LoginUserUtil.getAppUser(); - - if (!dappSystemService.systemHasStart()) { - HashMap<String, BigDecimal> map = new HashMap<>(); - map.put("x", new BigDecimal("0.05")); - map.put("y", new BigDecimal("0.05")); - return map; - } - - ContractChainService tfcInstance = ChainService.getInstance(ChainEnum.BSC_TFC.name()); - // u剩余数量 - BigDecimal sourceU = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress()); - // 源池代币剩余数量 - BigDecimal sourceCoin = tfcInstance.balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress()); - // 用户卖出数量 - BigDecimal coin = priceDto.getAmount(); - BigDecimal x = sourceU.divide(sourceCoin, tfcInstance.decimals(), RoundingMode.HALF_UP); - BigDecimal y = sourceU.divide(sourceCoin.add(coin), tfcInstance.decimals(), RoundingMode.HALF_UP); - - log.info("购买价格:{}, 出卖价格:{}", x, y); - HashMap<String, BigDecimal> map = new HashMap<>(); - map.put("x", x); - map.put("y", y); - return map; + return null; } @Override @@ -406,4 +379,20 @@ public void withdraw(WithdrawDto withdrawDto) { } + + @Override + public void updateWalletCoinWithLock(BigDecimal amount, Long memberId) { + boolean isSuccess = false; + while(!isSuccess) { + DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(memberId); + + walletCoin.setTotalAmount(walletCoin.getTotalAmount().add(amount)); + walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().add(amount)); + + int i = dappWalletCoinDao.updateWithLock(walletCoin); + if (i > 0) { + isSuccess = true; + } + } + } } -- Gitblit v1.9.1