fix
Helius
2022-11-13 c9c9bde983d6b77d44d75ce9a0eba87a1aef55e2
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -12,6 +12,7 @@
import cc.mrbird.febs.dapp.chain.ContractChainService;
import cc.mrbird.febs.dapp.dto.*;
import cc.mrbird.febs.dapp.entity.*;
import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum;
import cc.mrbird.febs.dapp.mapper.*;
import cc.mrbird.febs.dapp.service.DappWalletService;
import cc.mrbird.febs.dapp.utils.BoxUtil;
@@ -54,6 +55,7 @@
    private final RedisUtils redisUtils;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final DappNftActivationDao dappNftActivationDao;
    private final MemberCoinWithdrawDao memberCoinWithdrawDao;
    private final ChainProducer chainProducer;
    private final DappSystemDao dappSystemDao;
@@ -64,7 +66,7 @@
        DappMemberEntity memberInfo = dappMemberDao.selectById(member.getId());
        WalletInfoVo walletInfo = new WalletInfoVo();
        List<DappMemberEntity> direct = dappMemberDao.selectChildMemberDirectOrNot(member.getInviteId(), 1, null);
        List<DappMemberEntity> direct = dappMemberDao.selectChildMemberDirectOrNot(member.getInviteId(), 1, 1);
        DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId());
        DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(member.getId());
@@ -90,7 +92,7 @@
            dappFundFlowEntity.setType(recordInPageDto.getType());
        }
        dappFundFlowEntity.setMemberId(member.getId());
        dappFundFlowEntity.setStatus(2);
//        dappFundFlowEntity.setStatus(2);
        IPage<DappFundFlowEntity> records = dappFundFlowDao.selectInPage(page, dappFundFlowEntity);
        return records.getRecords();
@@ -176,13 +178,15 @@
    @Override
    public BigDecimal calPrice(PriceDto priceDto) {
        String priceStr = redisUtils.getString(AppContants.REDIS_KEY_TFC_NEW_PRICE);
//        String priceStr = redisUtils.getString(AppContants.REDIS_KEY_TFC_NEW_PRICE);
        DataDictionaryCustom symbolPrice = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYMBOL_PRICE.getType(), DataDictionaryEnum.SYMBOL_PRICE.getCode());
        DataDictionaryCustom serviceFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WITHDRAW_SERVICE_FEE.getType(), DataDictionaryEnum.WITHDRAW_SERVICE_FEE.getCode());
        BigDecimal amount = priceDto.getAmount();
        if (priceDto.getAmount() == null) {
            amount = BigDecimal.ZERO;
        }
        return amount.multiply(new BigDecimal("0.1")).divide(new BigDecimal(priceStr), 2, RoundingMode.HALF_UP);
        return amount.multiply(new BigDecimal(serviceFeeDic.getValue()).divide(BigDecimal.valueOf(100), 8, RoundingMode.HALF_DOWN)).multiply(new BigDecimal(symbolPrice.getValue()));
    }
    @Override
@@ -197,11 +201,12 @@
        DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(member.getId());
        if (walletMine.getAvailableAmount().compareTo(withdrawDto.getFee()) < 0) {
            throw new FebsException("TFC Not Enough");
            throw new FebsException("DMD Not Enough");
        }
        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);
@@ -209,15 +214,26 @@
        DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getAmount().negate(), 5, 2, withdrawDto.getFee(), null);
        dappFundFlowDao.insert(fundFlow);
        MemberCoinWithdrawEntity memberCoinWithdraw = new MemberCoinWithdrawEntity();
        memberCoinWithdraw.setMemberId(member.getId());
        memberCoinWithdraw.setAddress(member.getAddress());
        memberCoinWithdraw.setAmount(withdrawDto.getAmount());
        memberCoinWithdraw.setFeeAmount(withdrawDto.getFee());
        memberCoinWithdraw.setStatus(MemberCoinWithdrawEntity.STATUS_YES);
        memberCoinWithdraw.setSymbol("USDT");
        memberCoinWithdraw.setFlowId(fundFlow.getId());
        memberCoinWithdrawDao.insert(memberCoinWithdraw);
        String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(member.getAddress(), withdrawDto.getAmount());
        fundFlow.setToHash(hash);
        dappFundFlowDao.updateById(fundFlow);
        Map<String, Object> map = new HashMap<>();
        map.put("fee", withdrawDto.getFee());
        map.put("address", ChainEnum.BSC_TFC_FEE.getAddress());
        map.put("flow", feeFlow.getId());
        chainProducer.sendTfcFee(JSONObject.toJSONString(map));
        chainProducer.sendFeeDistributeMsg(fundFlow.getId());
//        Map<String, Object> map = new HashMap<>();
//        map.put("fee", withdrawDto.getFee());
//        map.put("address", ChainEnum.BSC_TFC_FEE.getAddress());
//        map.put("flow", feeFlow.getId());
//        chainProducer.sendTfcFee(JSONObject.toJSONString(map));
    }
    @Override
@@ -257,7 +273,7 @@
                walletMine.setAvailableAmount(walletMine.getAvailableAmount().add(amount));
            } else {
                if (amount.compareTo(walletMine.getAvailableAmount()) > 0) {
                    throw new FebsException("TFC Not Enough");
                    throw new FebsException("DMD Not Enough");
                }
                walletMine.setTotalAmount(walletMine.getTotalAmount().subtract(amount));
                walletMine.setAvailableAmount(walletMine.getAvailableAmount().subtract(amount));