Helius
2022-08-27 c54f0c60faae496e0fd989b281b776b69b65a87a
finish sde
15 files modified
3 files deleted
1368 ■■■■■ changed files
src/main/java/cc/mrbird/febs/dapp/chain/ChainEnum.java 52 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/chain/ChainEnumBak.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java 46 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java 12 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/BscUsdtContractEvent.java 2 ●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappMemberServiceImpl.java 3 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java 576 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java 204 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/vo/WalletInfoVo.java 2 ●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/job/ChainListenerJob.java 4 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/job/GiveMeMoneyJob.java 52 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/job/MineProfitJob.java 173 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/job/NewPriceUpdateJob.java 36 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/job/SystemTradeJob.java 82 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java 1 ●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java 2 ●●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/ChainTest.java 100 ●●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/JunitTest.java 15 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/chain/ChainEnum.java
@@ -14,8 +14,8 @@
     * 0x55d398326f99059fF775485246999027B3197955
     * 测试链 0x337610d27c682E347C9cD60BD4b3b107C9d34dDd
     */
    BSC_USDT("BSC", "0x4f5b6875d0d42f019ab6CdFB3054649b5B7b5472",
            "0x86bd3ad3ffd055b27dd7685d494074982fe96d6cc9dde0e42e85a85036e8abe9",
    BSC_USDT("BSC", "0xc5CE0041B2C5a075003D3a631304D272572716cb",
            "0xa1dcc95f2ad7c8e27b0fd75308028bc2ab047553363c16e9742110be9ab96b99",
            "https://bsc-dataseed1.ninicoin.io",
            "0x55d398326f99059fF775485246999027B3197955",
            ""),
@@ -26,44 +26,8 @@
     * 正式 0xb27e44f98543e480dbd071b6605005e3d99b3dd4 https://bsc-dataseed1.ninicoin.io
     *
     */
    BSC_TFC("BSC", "0x4f5b6875d0d42f019ab6CdFB3054649b5B7b5472",
            "0x86bd3ad3ffd055b27dd7685d494074982fe96d6cc9dde0e42e85a85036e8abe9",
            "https://bsc-dataseed1.ninicoin.io",
            "0xb27e44f98543e480dbd071b6605005e3d99b3dd4",
            ""),
    /**
     * 源池币
     */
    BSC_TFC_SOURCE("BSC", "0x8cE9d2A8cA6eF9e05493e73C9b6479D100B94847",
            "",
            "https://bsc-dataseed1.ninicoin.io",
            "0xb27e44f98543e480dbd071b6605005e3d99b3dd4",
            ""),
    /**
     * 源池U
     */
    BSC_USDT_SOURCE("BSC", "0x8cE9d2A8cA6eF9e05493e73C9b6479D100B94847",
            "",
            "https://bsc-dataseed1.ninicoin.io",
            "0x55d398326f99059fF775485246999027B3197955",
            ""),
    /**
     * 技术池
     */
    BSC_TFC_TECH("BSC", "0x8DB4d0E470e6cD206b774f5DAD2b5D0dD43C7688",
            "",
            "https://bsc-dataseed1.ninicoin.io",
            "0xb27e44f98543e480dbd071b6605005e3d99b3dd4",
            ""),
    /**
     * 奖励池
     */
    BSC_TFC_REWARD("BSC", "0x286DDA62A7171a6d6eA6558510834fE8afc0446C",
            "0x3d35db460e2eead11fca7b6ce5a9c5c8a8e0866775008ef5e1721b9f17b57f4f",
    BSC_TFC("BSC", "0x8084Cf691B69c70De8A7c345E63CaA740B730FA5",
            "0x7bee8cf9441800655376ba95729c0807231367cf75702dd3b17fa5290196bb87",
            "https://bsc-dataseed1.ninicoin.io",
            "0xb27e44f98543e480dbd071b6605005e3d99b3dd4",
            ""),
@@ -82,8 +46,8 @@
     * 0x55d398326f99059fF775485246999027B3197955
     * 测试链 0x337610d27c682E347C9cD60BD4b3b107C9d34dDd
     */
    BSC_USDT_LISTENER("BSC", "0x4f5b6875d0d42f019ab6CdFB3054649b5B7b5472",
            "0x86bd3ad3ffd055b27dd7685d494074982fe96d6cc9dde0e42e85a85036e8abe9",
    BSC_USDT_LISTENER("BSC", "0xc5CE0041B2C5a075003D3a631304D272572716cb",
            "0xa1dcc95f2ad7c8e27b0fd75308028bc2ab047553363c16e9742110be9ab96b99",
            "https://bsc-mainnet.blockvision.org/v1/2D3n5NXWVLnIBsdBKZDlDFAC76x",
            "0x55d398326f99059fF775485246999027B3197955",
            ""),
@@ -94,8 +58,8 @@
     * 正式 0xb27e44f98543e480dbd071b6605005e3d99b3dd4 https://bsc-dataseed1.ninicoin.io
     *
     */
    BSC_TFC_LISTENER("BSC", "0x4f5b6875d0d42f019ab6CdFB3054649b5B7b5472",
            "0x86bd3ad3ffd055b27dd7685d494074982fe96d6cc9dde0e42e85a85036e8abe9",
    BSC_TFC_LISTENER("BSC", "0x8084Cf691B69c70De8A7c345E63CaA740B730FA5",
            "0x7bee8cf9441800655376ba95729c0807231367cf75702dd3b17fa5290196bb87",
            "https://bsc-mainnet.blockvision.org/v1/2D3n5NXWVLnIBsdBKZDlDFAC76x",
            "0xb27e44f98543e480dbd071b6605005e3d99b3dd4",
            ""),
src/main/java/cc/mrbird/febs/dapp/chain/ChainEnumBak.java
@@ -123,6 +123,12 @@
                             "0xefe98e00cd227b6322e892c82fcbd8eadf119c3188b7e574bc624f65405d61bf",
                             "https://bsc-dataseed1.ninicoin.io",
                             "0x6c6835e60e7dBaD7a60112a6371271e8eb79ee68",
            ""),
    BSC_TFC_FEE("BSC", "0x977a9ddfb965a9a3416fa72ca7f91c4949c18f25",
            "0xefe98e00cd227b6322e892c82fcbd8eadf119c3188b7e574bc624f65405d61bf",
            "https://bsc-dataseed1.ninicoin.io",
            "0x6c6835e60e7dBaD7a60112a6371271e8eb79ee68",
                             "");
    private String chain;
src/main/java/cc/mrbird/febs/dapp/service/DappSystemService.java
@@ -8,53 +8,7 @@
public interface DappSystemService {
    Map<String, Object> findTotalInComeAndList();
    Map<String, Object> globalSetting();
    SystemDto system();
    /**
     * 卖币滑点返利
     *
     * @param id
     */
    void tradeProfitDistribute(Long id);
    /**
     * nft滑点
     *
     * @param id
     */
    void tradeNftProfitDistribute(Long id);
    /**
     * 挖矿
     */
    void mining();
    void onlineTransfer(String batchNo);
    /**
     * 用户购买奖励
     *
     * @param id
     */
    void userBuyReward(Long id);
    void startSystem();
    void transferPoolSetting();
    void sourcePoolUsdtOutLimitSetting();
    void boxCnt(Long id);
    boolean systemHasStart();
    BigDecimal newestPrice();
    boolean hasProfit(String address);
    void achieveTree(Long memberId);
src/main/java/cc/mrbird/febs/dapp/service/DappWalletService.java
@@ -19,13 +19,9 @@
    WalletInfoVo walletInfo();
    void change(WalletOperateDto walletOperateDto);
    List<DappFundFlowEntity> recordInPage(RecordInPageDto recordInPageDto);
    IPage<DappFundFlowEntity> fundFlowInPage(DappFundFlowEntity dappFundFlowEntity, QueryRequest request);
    void withdrawAgreeOrNot(Long id, int type);
    IPage<DappWalletCoinEntity> walletCoinInPage(DappWalletCoinEntity walletCoin, QueryRequest request);
    IPage<DappWalletMineEntity> walletMineInPage(DappWalletMineEntity walletMine, QueryRequest request);
@@ -35,13 +31,7 @@
    Long transfer(TransferDto transferDto);
    Map<String, BigDecimal> calPrice(PriceDto priceDto);
    ActiveNftListVo boxSurprise();
    void activeNft(ActiveDto activeDto);
    List<ActiveNftListVo> findUnActiveNftList();
    BigDecimal calPrice(PriceDto priceDto);
    void withdraw(WithdrawDto withdrawDto);
src/main/java/cc/mrbird/febs/dapp/service/impl/BscUsdtContractEvent.java
@@ -48,7 +48,7 @@
        redisUtils.set(AppContants.REDIS_KEY_BLOCK_USDT_NUM, e.log.getBlockNumber());
        // 判断对方打款地址是否为源池地址
        if (ChainEnum.BSC_TFC_SOURCE.getAddress().toLowerCase().equals(e.to)) {
        if (ChainEnum.BSC_USDT.getAddress().toLowerCase().equals(e.to)) {
            log.info("触发USDT合约监听事件");
            redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, e.log.getBlockNumber());
src/main/java/cc/mrbird/febs/dapp/service/impl/DappMemberServiceImpl.java
@@ -339,6 +339,9 @@
        DappMemberEntity member = LoginUserUtil.getAppUser();
        DappAchieveMemberTreeEntity topNode = dappAchieveMemberTreeDao.selectNodeByDeep(member.getId(), 1);
        if (topNode == null) {
            return null;
        }
        return buildTeamMatrix(topNode);
    }
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -71,36 +71,6 @@
    @Override
    public Map<String, Object> findTotalInComeAndList() {
        List<DappMemberEntity> addresses = dappMemberDao.selectList(null);
        DappMemberEntity mineAddress = dappMemberDao.selectByAddress(ChainEnum.BSC_TFC.getAddress(), null);
        BigDecimal coinCnt = dappMemberDao.selectAllBalance("normal");
        Map<String, Object> result = new HashMap<>();
        result.put("total", mineAddress.getBalance());
        result.put("addreessCnt", addresses.size());
        result.put("coinCnt", coinCnt);
        result.put("sourceTFC", ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(ChainEnum.BSC_TFC_SOURCE.getAddress()));
        result.put("sourceUSDT", ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress()));
        result.put("cardCnt", 1000);
        result.put("nftPrice", AppContants.NFT_ACTIVE_PRICE);
        return result;
    }
    @Override
    public Map<String, Object> globalSetting() {
        BigDecimal newPrice = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_ETH_NEW_PRICE);
        Integer changeFee = (Integer) redisUtils.get(AppContants.REDIS_KEY_CHANGE_FEE);
        List<DappReturnRatioEntity> ratios = dappReturnRatioDao.selectList(null);
        Map<String, Object> result = new HashMap<>();
        result.put("newPrice", newPrice);
        result.put("changeFee", changeFee);
        result.put("ratio", ratios);
        return result;
    }
    @Override
    public SystemDto system() {
        DappMemberEntity member = LoginUserUtil.getAppUser();
@@ -109,556 +79,10 @@
        return system;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void tradeProfitDistribute(Long id) {
        DappFundFlowEntity fundflow = dappFundFlowDao.selectById(id);
        String batchNo = RandomUtil.randomString(16) + id.toString();
        BigDecimal fee = fundflow.getFee();
        DappMemberEntity member = dappMemberDao.selectById(fundflow.getMemberId());
        List<DappMemberEntity> parents;
        if (StrUtil.isBlank(member.getRefererId()) || "0".equals(member.getRefererId())) {
            parents = new ArrayList<>();
        } else {
            List<String> inviteIds = StrUtil.split(member.getRefererId(), ',');
            parents = dappMemberDao.selectParentsList(inviteIds, 6);
            ;
        }
        DataDictionaryCustom miniHoldCoin = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MINI_HOLD_COIN_LIMIT);
        DataDictionaryCustom slipPointSetting = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SLIP_POINT_SETTING, AppContants.DIC_TYPE_SLIP_POINT_SETTING);
        SlipSettingVo slipSetting = JSONObject.parseObject(slipPointSetting.getValue(), SlipSettingVo.class);
        // 源池
        ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC_SOURCE.name());
        BigDecimal destroy = slipSetting.getDestroyPoint().divide(slipSetting.getAllPoint(), 2, RoundingMode.HALF_DOWN).multiply(fee);
        log.info("销毁数量:{}, 比例:{}", destroy, slipSetting.getDestroyPoint());
        // 销毁
        OnlineTransferUtil.addTransfer(AppContants.DESTROY_ADDRESS, destroy, fundflow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
        // 总分发金额
        BigDecimal distrbAmount = fee.subtract(destroy);
        // 技术金额
        BigDecimal techAmount = distrbAmount.multiply(slipSetting.getTechProp().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
        // 节点金额
        BigDecimal nodeAmount = distrbAmount.subtract(techAmount);
        log.info("总分发金额:{}, 技术:{}, 节点:{}", distrbAmount, techAmount, nodeAmount);
        if (CollUtil.isNotEmpty(parents)) {
            int i = 1;
            for (DappMemberEntity parent : parents) {
                BigDecimal balance = instance.balanceOf(parent.getAddress());
                log.info("地址:{}, 余额:{}", parent.getAddress(), balance);
                // 若地址持币少了指定数量
                if (balance.compareTo(new BigDecimal(miniHoldCoin.getValue())) < 0) {
                    continue;
                }
                DataDictionaryCustom distribDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_DISTRIBUTE_PROP, String.valueOf(i));
                if (distribDic == null) {
                    break;
                }
                BigDecimal total = distrbAmount.multiply(new BigDecimal(distribDic.getValue()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
                OnlineTransferUtil.addTransfer(parent.getAddress(), total, fundflow.getType(), 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
                DappFundFlowEntity distribFlow = new DappFundFlowEntity(parent.getId(), total, 4, 2, BigDecimal.ZERO);
                dappFundFlowDao.insert(distribFlow);
                nodeAmount = nodeAmount.subtract(total);
                i++;
            }
        }
        // 铸池滑点金额
        BigDecimal makerAmount = distrbAmount.multiply(slipSetting.getMakeProp().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
        log.info("铸池滑点金额:{}", makerAmount);
        if (makerAmount.compareTo(BigDecimal.ZERO) > 0) {
            List<DappMemberEntity> makerAddress = dappMemberDao.selectMakerAddress();
            if (CollUtil.isNotEmpty(makerAddress)) {
                BigDecimal totalMaker = BigDecimal.ZERO;
                Map<String, BigDecimal> map = new HashMap<>();
                Map<String, Long> addressAndId = new HashMap<>();
                for (DappMemberEntity maker : makerAddress) {
                    BigDecimal balance = instance.balanceOf(maker.getAddress());
                    map.put(maker.getAddress(), balance);
                    addressAndId.put(maker.getAddress(), maker.getId());
                    totalMaker = totalMaker.add(balance);
                }
                for (Map.Entry<String, BigDecimal> entry : map.entrySet()) {
                    BigDecimal target = makerAmount.multiply(entry.getValue().divide(totalMaker, 2, RoundingMode.HALF_UP));
                    OnlineTransferUtil.addTransfer(entry.getKey(), target, fundflow.getType(), 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
                    DappFundFlowEntity distribFlow = new DappFundFlowEntity(addressAndId.get(entry.getKey()), target, 4, 2, BigDecimal.ZERO);
                    dappFundFlowDao.insert(distribFlow);
                }
            }
        }
        // 若节点金额还有剩余,则进入技术金额
        techAmount = techAmount.add(nodeAmount);
        OnlineTransferUtil.addTransfer(ChainEnum.BSC_TFC_TECH.getAddress(), techAmount, fundflow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
        Map<String, String> map = new HashMap<>();
        map.put("batchNo", batchNo);
        map.put("type", "batch");
        // 发送转账消息
        chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map));
    }
    @Override
    public void tradeNftProfitDistribute(Long id) {
        DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id);
        String batchNo = RandomUtil.randomString(16) + id.toString();
        ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC.name());
        BigDecimal preNFTAmount;
        BigDecimal distribAmount = fundFlow.getFee();
        if (fundFlow.getType() == 1) {
            preNFTAmount = distribAmount.divide(new BigDecimal("5000"), 2, RoundingMode.HALF_UP);
        } else if (fundFlow.getType() == 2) {
            BigDecimal destroyAmount = fundFlow.getFee().multiply(new BigDecimal("2").divide(new BigDecimal("7"), instance.decimals(), RoundingMode.HALF_UP));
            // 销毁
            OnlineTransferUtil.addTransfer(AppContants.DESTROY_ADDRESS, destroyAmount, fundFlow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
            distribAmount = fundFlow.getFee().subtract(destroyAmount);
            preNFTAmount = distribAmount.divide(new BigDecimal("5000"), 2, RoundingMode.HALF_UP);
        } else {
            return;
        }
        List<DappMemberEntity> allMembers = dappMemberDao.selectList(null);
        if (CollUtil.isEmpty(allMembers)) {
            return;
        }
        BigDecimal total = BigDecimal.ZERO;
        for (DappMemberEntity member : allMembers) {
            BigDecimal balance = instance.balanceOf(member.getAddress());
            BigDecimal memberProfit = balance.multiply(preNFTAmount);
            // 返利
            OnlineTransferUtil.addTransfer(member.getAddress(), memberProfit, fundFlow.getType(), 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
            DappFundFlowEntity distribFlow = new DappFundFlowEntity(member.getId(), memberProfit, 4, 2, BigDecimal.ZERO);
            dappFundFlowDao.insert(distribFlow);
            total = total.add(memberProfit);
        }
        BigDecimal remain = distribAmount.subtract(total);
        // 剩余的
        OnlineTransferUtil.addTransfer(ChainEnum.BSC_TFC_TECH.getAddress(), remain, fundFlow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
    }
//    public static void main(String[] args) throws IOException {
//        Document parse = Jsoup.parse(new URL("https://bscscan.com/token/generic-tokenholders2?a=0x03c7d3f141c5f03971604958170e253362e13be6"), 10000000);
//
//        Elements tbodys = parse.getElementsByTag("tbody");
//
//        Element tbody = tbodys.get(0);
//
//        Elements elements = tbody.getElementsMatchingOwnText("^0x.*$");
//
//        String text = elements.get(0).text();
//        System.out.println(1111);
//    }
    @Override
    public void mining() {
        ContractChainService contract = ChainService.getInstance(ChainEnum.BSC_TFC.name());
        // 发行量
        BigInteger totalSupply = contract.totalSupply();
        if (!systemHasStart()) {
            return;
        }
        BigDecimal totalUnHold = contract.balanceOf(AppContants.DESTROY_ADDRESS);
        List<DappMemberEntity> admin = dappMemberDao.selectMemberByAccountType("admin");
        for (DappMemberEntity member : admin) {
            totalUnHold = totalUnHold.add(contract.balanceOf(member.getAddress()));
        }
        Object transferPoolObj = redisUtils.get(AppContants.REDIS_KEY_MINE_TRANSFER_POOL_TRADE_CNT);
        // 全网持币量
        BigDecimal allInternet = new BigDecimal(totalSupply).subtract(totalUnHold);
        // 中转池交易量
        BigDecimal transferPoll = (BigDecimal) transferPoolObj;
        // 判断今日价格比前一日价格是否跌了,若是,则今天挖矿减半
        BigDecimal downReduce = BigDecimal.ONE;
        if (symbolPriceUpOrDown()) {
            downReduce = new BigDecimal("0.5");
        }
        BigDecimal totalMineCnt = transferPoll.multiply(new BigDecimal("0.2")).multiply(downReduce);
        List<DappMemberEntity> allMembers = dappMemberDao.selectList(null);
        if (CollUtil.isEmpty(allMembers)) {
            return;
        }
        DataDictionaryCustom miniHoldCoin = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MINI_HOLD_COIN_LIMIT);
        String batchNo = RandomUtil.randomString(32);
        ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC.name());
        for (DappMemberEntity member : allMembers) {
            if ("admin".equals(member.getAccountType())) {
                continue;
            }
            BigDecimal balance = instance.balanceOf(member.getAddress());
            if (balance.compareTo(new BigDecimal(miniHoldCoin.getValue())) < 1) {
                continue;
            }
            // 挖矿数量
            BigDecimal mine = totalMineCnt.multiply(balance.divide(allInternet, instance.decimals(), RoundingMode.HALF_UP));
            if (mine.compareTo(BigDecimal.ZERO) < 1) {
                continue;
            }
            DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), mine, 3, 2, BigDecimal.ZERO);
            dappFundFlowDao.insert(fundFlow);
            OnlineTransferUtil.addTransfer(member.getAddress(), mine, 3, 1, ChainEnum.BSC_TFC.name(), AppContants.SYMBOL_COIN, batchNo);
            member.setBalance(balance);
            dappMemberDao.updateById(member);
        }
        Map<String, String> map = new HashMap<>();
        map.put("batchNo", batchNo);
        map.put("type", "batch");
        // 发送转账消息
        chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map));
    }
    @Override
    public void onlineTransfer(String str) {
        JSONObject jsonObject = JSONObject.parseObject(str);
        String batchNo = jsonObject.getString("batchNo");
        List<DappOnlineTransferEntity> transferList = dappOnlineTransferDao.selectByBatchNo(batchNo);
        if (CollUtil.isEmpty(transferList)) {
            return;
        }
        for (DappOnlineTransferEntity transfer : transferList) {
            if (transfer.getHasFinish() == 1) {
                continue;
            }
            String txHash = ChainService.getInstance(transfer.getFromType()).transfer(transfer.getAddress(), transfer.getAmount());
            while (StrUtil.isEmpty(txHash)) {
                // 休眠2s
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                txHash = ChainService.getInstance(transfer.getFromType()).transfer(transfer.getAddress(), transfer.getAmount());
            }
            transfer.setTxHash(txHash);
            transfer.setHasFinish(1);
            transfer.setUpdateTime(new Date());
            dappOnlineTransferDao.updateById(transfer);
            if ("flow".equals(jsonObject.getString("type"))) {
                DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(Long.parseLong(batchNo));
                fundFlow.setToHash(txHash);
                dappFundFlowDao.updateById(fundFlow);
            }
        }
        // 判断系统是否启动,如满足条件则启动系统
//        String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG);
//        if (!"start".equals(hasStart)) {
//            DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_SYSTEM_START_TARGET);
//            BigDecimal target = new BigDecimal(dic.getValue());
//
//            // 若源池中的USDT达到或超过8万U,则启动整个系统
//            BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_USDT_SOURCE.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress());
//            if (target.compareTo(balance) < 1) {
//                redisUtils.set(AppContants.SYSTEM_START_FLAG, "start");
//
//                // 启动系统
//                startSystem();
//            }
//        }
    }
    @Override
    public void userBuyReward(Long id) {
        // 系统未启动不参与
        if (!systemHasStart()) {
            return;
        }
        DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id);
        DappMemberEntity member = dappMemberDao.selectById(fundFlow.getMemberId());
        DappMemberEntity referer = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId());
        if (referer == null || "admin".equals(referer.getAccountType())) {
            return;
        }
        if (!hasProfit(referer.getAddress())) {
            return;
        }
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_USER_BUY_REWARD);
        BigDecimal prop = new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
        BigDecimal reward = fundFlow.getAmount().multiply(prop);
        BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC_REWARD.name()).balanceOf(ChainEnum.BSC_TFC_REWARD.getAddress());
        if (balance.compareTo(reward) < 1) {
            return;
        }
        DappFundFlowEntity rewardFlow = new DappFundFlowEntity(referer.getId(), reward, 4, 2, BigDecimal.ZERO);
        dappFundFlowDao.insert(rewardFlow);
        OnlineTransferUtil.addTransfer(referer.getAddress(), reward, 4, 1, ChainEnum.BSC_TFC_REWARD.name(), AppContants.SYMBOL_COIN, rewardFlow.getId().toString());
        Map<String, String> map = new HashMap<>();
        map.put("batchNo", rewardFlow.getId().toString());
        map.put("type", "batch");
        chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map));
    }
    @Override
    public void startSystem() {
        log.info("启动系统");
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                transferPoolSetting();
                sourcePoolUsdtOutLimitSetting();
            }
        });
        thread.start();
    }
    // 最低容量(百分比)
    private final BigDecimal volProp = new BigDecimal("2");
    // 每日增/减百分比
    private final BigDecimal changeProp = new BigDecimal("1");
    @Override
    public void transferPoolSetting() {
        String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG);
        if (!"start".equals(hasStart)) {
            log.info("系统未启动");
            return;
        }
        // 源池初始化容量
        DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_SYSTEM_SOURCE_POOL_VOL);
        BigDecimal basicVol = new BigDecimal(dic.getValue());
        Object o = redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL);
        if (o == null) {
            RedisTransferPoolVo transferPool = new RedisTransferPoolVo();
            BigDecimal total = basicVol.multiply(volProp.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP));
            transferPool.setTodayVol(total);
            transferPool.setTodayProp(volProp);
            transferPool.setFinishCnt(0);
            transferPool.setUnFinishCnt(0);
            redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL, transferPool);
            redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, total);
            redisUtils.set(AppContants.REDIS_KEY_MINE_TRANSFER_POOL_TRADE_CNT, BigDecimal.ZERO);
            return;
        }
        RedisTransferPoolVo transferPool = (RedisTransferPoolVo) o;
        BigDecimal remain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN);
        // 设置当日成交量
        redisUtils.set(AppContants.REDIS_KEY_MINE_TRANSFER_POOL_TRADE_CNT, transferPool.getTodayVol().subtract(remain));
        // 全卖了
        if (remain.compareTo(BigDecimal.ZERO) == 0) {
            int finishCnt = transferPool.getFinishCnt() + 1;
            BigDecimal targetProp = transferPool.getTodayProp();
            if (finishCnt == 1) {
                targetProp = transferPool.getTodayVol().add(changeProp);
                transferPool.setTodayProp(targetProp);
                transferPool.setFinishCnt(0);
            } else {
                transferPool.setFinishCnt(finishCnt);
            }
            BigDecimal total = basicVol.multiply(targetProp.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP));
            transferPool.setTodayVol(total);
            transferPool.setUnFinishCnt(0);
            redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, total);
        } else {
            int unFinishCnt = transferPool.getUnFinishCnt() + 1;
            BigDecimal targetProp = transferPool.getTodayProp();
            if (unFinishCnt >= 1) {
                targetProp = transferPool.getTodayProp().compareTo(volProp) == 0 ? volProp : transferPool.getTodayProp().subtract(changeProp);
                transferPool.setTodayProp(targetProp);
                transferPool.setUnFinishCnt(0);
            } else {
                transferPool.setUnFinishCnt(unFinishCnt);
            }
            BigDecimal aa = targetProp.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP);
            BigDecimal total = basicVol.multiply(aa);
            transferPool.setTodayVol(total);
            redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, total);
        }
        redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL, transferPool);
    }
    @Override
    public void sourcePoolUsdtOutLimitSetting() {
        String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG);
        if (!"start".equals(hasStart)) {
            log.info("系统未启动");
            return;
        }
        BigDecimal sourceBalance = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress());
        BigDecimal total = sourceBalance.multiply(BigDecimal.valueOf(0.1)).setScale(4, RoundingMode.HALF_DOWN);
        redisUtils.set(AppContants.REDIS_KEY_USDT_OUT_LIMIT, total);
        redisUtils.set(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN, total);
    }
    private boolean symbolPriceUpOrDown() {
        String dailyPrice = redisUtils.getString(AppContants.REDIS_KEY_SYMBOL_DAILY_PRICE);
        BigDecimal lastDayPrice = BigDecimal.ZERO;
        if (StrUtil.isNotBlank(dailyPrice)) {
            lastDayPrice = new BigDecimal(dailyPrice);
        }
        ContractChainService tfcInstance = ChainService.getInstance(ChainEnum.BSC_TFC_SOURCE.name());
        // 源池币种数量
        BigDecimal tfcBalance = tfcInstance.balanceOf(ChainEnum.BSC_TFC_SOURCE.getAddress());
        // 源池USDT数量
        BigDecimal usdtBalance = ChainService.getInstance(ChainEnum.BSC_USDT_SOURCE.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress());
        BigDecimal todayPrice = tfcBalance.divide(usdtBalance, tfcInstance.decimals(), RoundingMode.HALF_UP);
        DappSymbolDailyPriceEntity dailyPriceEntity = new DappSymbolDailyPriceEntity();
        dailyPriceEntity.setPrice(todayPrice);
        this.dappSymbolDailyPriceMapper.insert(dailyPriceEntity);
        redisUtils.set(AppContants.REDIS_KEY_SYMBOL_DAILY_PRICE, todayPrice.toString());
        // 如果价格有跌幅,则挖矿减半
        return todayPrice.compareTo(lastDayPrice) < 0;
    }
    @Override
    public void boxCnt(Long id) {
        DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id);
        DappMemberEntity member = dappMemberDao.selectById(fundFlow.getMemberId());
        DappMemberEntity parent = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId());
        if (parent == null) {
            return;
        }
        DappMemberBoxRecordEntity memberBox = dappMemberBoxRecordMapper.selectByFromMemberId(fundFlow.getMemberId());
        if (memberBox != null) {
            return;
        }
        if (!hasProfit(parent.getAddress())) {
            return;
        }
        BigInteger totalSupply = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).totalSupplyNFT();
        int box = 0;
        // 需要第一次购买,才在推荐中加1
        Object parentRecommend = redisUtils.hget(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress());
        if (parentRecommend == null) {
            redisUtils.hset(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress(), 1);
        } else {
            int i = (int) parentRecommend;
            // 如果超过10个,则新增一个盲盒,并重置推荐人数
            if (++i == CardPeriod.ONE.recommendCnt(totalSupply.intValue())) {
                box = 1;
                redisUtils.hset(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress(), 0);
            } else {
                redisUtils.hset(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress(), i);
            }
        }
        if (box > 0) {
            DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(parent.getId());
            walletCoin.setBoxCnt(walletCoin.getBoxCnt() + box);
            dappWalletCoinDao.updateById(walletCoin);
            DappMemberBoxRecordEntity memberBoxRecordEntity = new DappMemberBoxRecordEntity();
            memberBoxRecordEntity.setMemberId(parent.getId());
            memberBoxRecordEntity.setAddress(parent.getAddress());
            memberBoxRecordEntity.setFromMemberId(member.getId());
            memberBoxRecordEntity.setFromAddress(member.getAddress());
            this.dappMemberBoxRecordMapper.insert(memberBoxRecordEntity);
            DappFundFlowEntity boxFundFlow = new DappFundFlowEntity(parent.getId(), new BigDecimal(box), 5, 2, BigDecimal.ZERO);
            dappFundFlowDao.insert(boxFundFlow);
        }
    }
    @Override
    public boolean systemHasStart() {
        String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG);
        if (!"start".equals(hasStart)) {
            log.info("系统未启动");
            return false;
        }
        return true;
    }
    @Override
    public BigDecimal newestPrice() {
        if (systemHasStart()) {
            String dailyPrice = redisUtils.getString(AppContants.REDIS_KEY_SYMBOL_DAILY_PRICE);
            return StrUtil.isNotBlank(dailyPrice) ? new BigDecimal(dailyPrice) : BigDecimal.ZERO;
        } else {
            return new BigDecimal("0.05");
        }
    }
    @Override
    public boolean hasProfit(String address) {
        BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(address);
        BigDecimal usdtBalance = balance.multiply(newestPrice());
        DataDictionaryCustom data = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MINI_HOLD_COIN_LIMIT);
        BigDecimal miniLimit = new BigDecimal(data.getValue());
        if (usdtBalance.compareTo(miniLimit) < 0) {
            return false;
        }
        return true;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -72,46 +72,9 @@
        walletInfo.setHasBuy(memberInfo.getActiveStatus());
        walletInfo.setOutCnt(memberInfo.getOutCnt());
        walletInfo.setProfit(dappFundFlowDao.selectProfitAmountByMemberId(member.getId()));
        walletInfo.setTFCbalance(walletMine.getAvailableAmount());
        walletInfo.setTfcBalance(walletMine.getAvailableAmount());
        return walletInfo;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void change(WalletOperateDto walletOperateDto) {
        DappMemberEntity member = LoginUserUtil.getAppUser();
        BigDecimal ethUsdtPrice = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_ETH_NEW_PRICE);
        DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(member.getId());
        if (walletOperateDto.getAmount().compareTo(walletMine.getAvailableAmount()) > 0) {
            throw new FebsException("可用金额不足");
        }
        DappFundFlowEntity fund = new DappFundFlowEntity(member.getId(), walletOperateDto.getAmount(), AppContants.MONEY_TYPE_CHANGE, null, null);
        dappFundFlowDao.insert(fund);
        BigDecimal preEthAmount = walletMine.getAvailableAmount();
        // TODO 并发加悲观锁
        // 更新eth金额
        walletMine.setAvailableAmount(walletMine.getAvailableAmount().subtract(walletOperateDto.getAmount()));
        dappWalletMineDao.updateById(walletMine);
        DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId());
        BigDecimal preUsdtAmount = walletCoin.getAvailableAmount();
        // 更新usdt金额
        BigDecimal usdt = walletOperateDto.getAmount().multiply(ethUsdtPrice);
        walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().add(usdt));
        walletCoin.setTotalAmount(walletCoin.getTotalAmount().add(usdt));
        dappWalletCoinDao.updateById(walletCoin);
        DappAccountMoneyChangeEntity ethChange = new DappAccountMoneyChangeEntity(member.getId(), preEthAmount, walletOperateDto.getAmount(), walletMine.getAvailableAmount(), "ETH兑换USDT-ETH, 兑换价格为:" + ethUsdtPrice, AppContants.MONEY_TYPE_CHANGE);
        DappAccountMoneyChangeEntity usdtChange = new DappAccountMoneyChangeEntity(member.getId(), preUsdtAmount, usdt, walletCoin.getAvailableAmount(), "ETH兑换USDT-USDT, 兑换价格为:" + ethUsdtPrice, AppContants.MONEY_TYPE_CHANGE);
        dappAccountMoneyChangeDao.insert(ethChange);
        dappAccountMoneyChangeDao.insert(usdtChange);
    }
    @Override
@@ -137,37 +100,6 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void withdrawAgreeOrNot(Long id, int type) {
        DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id);
        if (fundFlow == null) {
            throw new FebsException("数据不存在");
        }
        DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(fundFlow.getMemberId());
        if (type == 1) {
            walletCoin.setFrozenAmount(walletCoin.getFrozenAmount().subtract(fundFlow.getAmount()));
            walletCoin.setTotalAmount(walletCoin.getTotalAmount().subtract(fundFlow.getAmount()));
            fundFlow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
        } else if (type == 2) {
            BigDecimal preAmount = walletCoin.getAvailableAmount();
            walletCoin.setFrozenAmount(walletCoin.getFrozenAmount().subtract(fundFlow.getAmount()));
            walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().add(fundFlow.getAmount()));
            DappAccountMoneyChangeEntity accountMoneyChange = new DappAccountMoneyChangeEntity(walletCoin.getMemberId(), preAmount, fundFlow.getAmount(), walletCoin.getAvailableAmount(), "提现申请被驳回", 2);
            fundFlow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_DISAGREE);
            dappAccountMoneyChangeDao.insert(accountMoneyChange);
        } else {
            throw new FebsException("参数错误");
        }
        dappWalletCoinDao.updateById(walletCoin);
        dappFundFlowDao.updateById(fundFlow);
    }
    @Override
    public IPage<DappWalletCoinEntity> walletCoinInPage(DappWalletCoinEntity walletCoin, QueryRequest request) {
        Page<DappWalletCoinEntity> page = new Page<>(request.getPageNum(), request.getPageSize());
        return dappWalletCoinDao.selectInPage(walletCoin, page);
@@ -189,9 +121,11 @@
    public Long transfer(TransferDto transferDto) {
        DappMemberEntity member = LoginUserUtil.getAppUser();
        if (transferDto.getType() != 2) {
        member = dappMemberDao.selectById(member.getId());
        if (member.getActiveStatus() == 1) {
            throw new FebsException("Do not repeat purchase");
            }
        }
        if (transferDto.getBuyType() == 1) {
@@ -233,128 +167,10 @@
    }
    @Override
    public Map<String, BigDecimal> calPrice(PriceDto priceDto) {
    public BigDecimal calPrice(PriceDto priceDto) {
        String priceStr = redisUtils.getString(AppContants.REDIS_KEY_TFC_NEW_PRICE);
        Map<String, BigDecimal> data = new HashMap<>();
        data.put("fee", new BigDecimal(priceStr));
        return data;
    }
    @Override
    public ActiveNftListVo boxSurprise() {
        DappMemberEntity member = LoginUserUtil.getAppUser();
        DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId());
        if (walletCoin.getBoxCnt() < 1) {
            throw new FebsException(MessageSourceUtils.getString("box_surprise_001"));
        }
        walletCoin.setBoxCnt(walletCoin.getBoxCnt() - 1);
        dappWalletCoinDao.updateById(walletCoin);
        BoxUtil.Box box = BoxUtil.openBox();
//        DappFundFlowEntity boxFundFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(box.getIndex()), 6, 2, BigDecimal.ZERO);
//        dappFundFlowDao.insert(boxFundFlow);
//
//        new Thread(() -> {
//            try {
//                int count = box.getIndex();
//                while (count > 0) {
//                    ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).safeMintNFT(member.getAddress());
//                    Thread.sleep(5000);
//                    count--;
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//                log.error("发放卡牌错误", e);
//            }
//        }).start();
        Date time = new Date();
        Date expire = DateUtil.offset(time, DateField.HOUR, 2);
        DappNftActivation nftActivation = new DappNftActivation();
        nftActivation.setMemberId(member.getId());
        nftActivation.setCount(box.getIndex());
        nftActivation.setOpenTime(time);
        nftActivation.setExpireTime(expire);
        nftActivation.setStatus(1);
        dappNftActivationDao.insert(nftActivation);
        ActiveNftListVo nft = new ActiveNftListVo();
        nft.setCount(box.getIndex());
        nft.setId(nftActivation.getId());
        nft.setRemain(DateUtil.between(time, expire, DateUnit.SECOND));
        return nft;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public synchronized void activeNft(ActiveDto activeDto) {
        DappMemberEntity member = LoginUserUtil.getAppUser();
        DappNftActivation nftActive = dappNftActivationDao.selectById(activeDto.getId());
        if (nftActive == null) {
            throw new FebsException(MessageSourceUtils.getString("nft_active_003"));
        }
        if (nftActive.getCount() < activeDto.getCount()) {
            throw new FebsException(MessageSourceUtils.getString("nft_active_004"));
        }
        if (DateUtil.between(new Date(), nftActive.getExpireTime(), DateUnit.SECOND) < 0) {
            throw new FebsException(MessageSourceUtils.getString("nft_active_005"));
        }
        if (nftActive.getStatus() != 1) {
            throw new FebsException(MessageSourceUtils.getString("nft_active_001"));
        }
        PriceDto priceDto = new PriceDto();
        priceDto.setAmount(BigDecimal.ZERO);
        Map<String, BigDecimal> price = calPrice(priceDto);
        DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(activeDto.getCount()), 8, 1, BigDecimal.ZERO, activeDto.getTxHash());
        fundFlow.setTargetAmount(price.get("x").multiply(new BigDecimal(activeDto.getCount())));
        fundFlow.setNewestPrice(AppContants.NFT_ACTIVE_PRICE.multiply(BigDecimal.valueOf(nftActive.getCount())));
        dappFundFlowDao.insert(fundFlow);
        int count = nftActive.getCount() - activeDto.getCount();
        if (count == 0) {
            nftActive.setStatus(3);
        }
        nftActive.setCount(count);
        nftActive.setHash(activeDto.getTxHash());
        dappNftActivationDao.updateById(nftActive);
    }
    @Override
    public List<ActiveNftListVo> findUnActiveNftList() {
        DappMemberEntity member = LoginUserUtil.getAppUser();
        List<ActiveNftListVo> list = new ArrayList<>();
        UpdateWrapper<DappNftActivation> query = new UpdateWrapper<>();
        query.eq("status", 1);
        query.eq("member_id", member.getId());
        query.ge("expire_time", new Date());
        List<DappNftActivation> nftActivations = dappNftActivationDao.selectList(query);
        if (CollUtil.isEmpty(nftActivations)) {
            return list;
        }
        Date now = new Date();
        nftActivations.forEach(nft -> {
            ActiveNftListVo nftVo = new ActiveNftListVo();
            nftVo.setId(nft.getId());
            nftVo.setRemain(DateUtil.between(now, nft.getExpireTime(), DateUnit.SECOND, false));
            nftVo.setCount(nft.getCount());
            list.add(nftVo);
        });
        return list;
        return priceDto.getAmount().multiply(new BigDecimal("0.1")).multiply(new BigDecimal(priceStr));
    }
    @Override
@@ -362,7 +178,7 @@
        DappMemberEntity member = LoginUserUtil.getAppUser();
        updateWalletCoinWithLock(withdrawDto.getAmount().negate(), member.getId());
        updateWalletMineWithLock(withdrawDto.getFee(), member.getId());
        updateWalletMineWithLock(withdrawDto.getFee().negate(), member.getId());
        DappFundFlowEntity feeFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getFee().negate(), 7, 2, null, null);
        dappFundFlowDao.insert(feeFlow);
@@ -397,12 +213,12 @@
    public void updateWalletMineWithLock(BigDecimal amount, Long memberId) {
        boolean isSuccess = false;
        while(!isSuccess) {
            DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(memberId);
            DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(memberId);
            walletCoin.setTotalAmount(walletCoin.getTotalAmount().add(amount));
            walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().add(amount));
            walletMine.setTotalAmount(walletMine.getTotalAmount().add(amount));
            walletMine.setAvailableAmount(walletMine.getAvailableAmount().add(amount));
            int i = dappWalletCoinDao.updateWithLock(walletCoin);
            int i = dappWalletMineDao.updateWithLock(walletMine);
            if (i > 0) {
                isSuccess = true;
            }
src/main/java/cc/mrbird/febs/dapp/vo/WalletInfoVo.java
@@ -33,5 +33,5 @@
    private Integer hasBuy;
    @ApiModelProperty(value = "手续费")
    private BigDecimal TFCbalance;
    private BigDecimal tfcBalance;
}
src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
@@ -85,7 +85,7 @@
            new Thread(() -> {
                log.info("监听:[{} - {}]", finalBlock, end);
                ChainService.contractEventListener(finalBlock, end, bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name());
                ChainService.contractEventListener(finalBlock, bscCoinContractEvent, ChainEnum.BSC_TFC_LISTENER.name());
                ChainService.contractEventListener(finalBlock, end, bscCoinContractEvent, ChainEnum.BSC_TFC_FEE.name());
            }).start();
            block = block.add(section);
@@ -94,7 +94,7 @@
            }
        }
        ChainService.contractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name());
        ChainService.contractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC_LISTENER.name());
        ChainService.contractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC_FEE.name());
        long end = System.currentTimeMillis();
        log.info("区块链监听启动完成, 消耗时间{}", end - start);
src/main/java/cc/mrbird/febs/job/GiveMeMoneyJob.java
File was deleted
src/main/java/cc/mrbird/febs/job/MineProfitJob.java
File was deleted
src/main/java/cc/mrbird/febs/job/NewPriceUpdateJob.java
File was deleted
src/main/java/cc/mrbird/febs/job/SystemTradeJob.java
@@ -27,45 +27,45 @@
@ConditionalOnProperty(prefix = "system", name = "trade-job", havingValue = "true")
public class SystemTradeJob {
    @Autowired
    private DappSystemService systemService;
    /**
     * 中转池容量计算
     *
     * 源池出币量最低为0.5%每天基础量,作为可s交易量
     * 按当天交易完成量的百分比,第二天出币补齐已成交部分
     * 按每天的基础量,同一阶段累计完成5次100%交易量后增加0.5%基础出币量比例出币,无上限……
     * 当一个阶段的当日量72小时未100%交易完成,中转池回到上一阶段阶容量。
     * 例:当进入一个新阶段为每天出币量为3%时,此笔出量累计72小时未完全成交,源池出币量回到上一阶段每天出币2.5%,需重计5倍量,……以此类推增加或递减
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void transferPoolVol() {
        log.info("中转池容量");
        systemService.transferPoolSetting();
    }
    /**
     * 源池每日出U限制
     *
     * 源池每天可交易量为源池总USDT数量的10%,以上一天00:00时读取源池实时USDT数量为参考,作为当天可交易USDT数量。
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void sourcePoolUsdtOutLimit() {
        log.info("源池每日出U限制");
        systemService.sourcePoolUsdtOutLimitSetting();
    }
    /**
     * 挖矿
     *
     * 以中转池成交数1:0.2出矿(中转池卖出多少,矿池则1:0.2出币),每个地址所得=出币量*(单个地址持币量/全网持币量)
     * source限矿算法:
     * 按前一天价格,有跌幅则按实际产矿量减半。
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void mineJob() {
        log.info("挖矿");
        systemService.mining();
    }
//    @Autowired
//    private DappSystemService systemService;
//
//    /**
//     * 中转池容量计算
//     *
//     * 源池出币量最低为0.5%每天基础量,作为可s交易量
//     * 按当天交易完成量的百分比,第二天出币补齐已成交部分
//     * 按每天的基础量,同一阶段累计完成5次100%交易量后增加0.5%基础出币量比例出币,无上限……
//     * 当一个阶段的当日量72小时未100%交易完成,中转池回到上一阶段阶容量。
//     * 例:当进入一个新阶段为每天出币量为3%时,此笔出量累计72小时未完全成交,源池出币量回到上一阶段每天出币2.5%,需重计5倍量,……以此类推增加或递减
//     */
//    @Scheduled(cron = "0 0 0 * * ?")
//    public void transferPoolVol() {
//        log.info("中转池容量");
//        systemService.transferPoolSetting();
//    }
//
//    /**
//     * 源池每日出U限制
//     *
//     * 源池每天可交易量为源池总USDT数量的10%,以上一天00:00时读取源池实时USDT数量为参考,作为当天可交易USDT数量。
//     */
//    @Scheduled(cron = "0 0 0 * * ?")
//    public void sourcePoolUsdtOutLimit() {
//        log.info("源池每日出U限制");
//        systemService.sourcePoolUsdtOutLimitSetting();
//    }
//
//    /**
//     * 挖矿
//     *
//     * 以中转池成交数1:0.2出矿(中转池卖出多少,矿池则1:0.2出币),每个地址所得=出币量*(单个地址持币量/全网持币量)
//     * source限矿算法:
//     * 按前一天价格,有跌幅则按实际产矿量减半。
//     */
//    @Scheduled(cron = "0 0 1 * * ?")
//    public void mineJob() {
//        log.info("挖矿");
//        systemService.mining();
//    }
}
src/main/java/cc/mrbird/febs/rabbit/consumer/ChainConsumer.java
@@ -58,7 +58,6 @@
     */
    @RabbitListener(queues = QueueConstants.TFC_NEW_PRICE)
    public void tfcNewPrice(String data) {
        log.info("收到最新价消息");
        dappSystemService.tfcNewPrice(data);
    }
}
src/main/java/cc/mrbird/febs/rabbit/producer/ChainProducer.java
@@ -71,5 +71,7 @@
     */
    public void sendTfcFee(String data) {
        log.info("发送提现手续费消息:{}", data);
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(QueueEnum.WITHDRAW_FEE.getExchange(), QueueEnum.WITHDRAW_FEE.getRoute(), data, correlationData);
    }
}
src/test/java/cc/mrbird/febs/ChainTest.java
@@ -32,106 +32,6 @@
@SpringBootTest
public class ChainTest {
    @Test
    public void balanceOfTest() {
        ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC.name());
        System.out.println(instance.balanceOf("0x0000000000000000000000000000000000000001"));
    }
//    @Autowired
//    private SystemTradeJob systemTradeJob;
//
//    @Test
//    public void transferPoolTest() {
//        systemTradeJob.transferPoolVol();
//    }
//
//
//    @Test
//    public void sourceUsdtTest() {
//        systemTradeJob.sourcePoolUsdtOutLimit();
//    }
//
//    @Test
//    public void poolTest() {
//        systemTradeJob.transferPoolVol();
//    }
    @Autowired
    private DappOnlineTransferDao dappOnlineTransferDao;
    @Test
    public void transferTest() {
        System.out.println(ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(ChainEnum.BSC_USDT_SOURCE.getAddress(), BigDecimal.valueOf(6L)));
    }
    @Autowired
    private ChainProducer chainProducer;
    @Test
    public void sendTransferTest() {
        Map<String, String> map = new HashMap<>();
        map.put("batchNo", "678o20scjg5stqf836");
        map.put("type", "batch");
        chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map));
    }
    @Test
    public void totalSupplyTest() {
        System.out.println(ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber());
    }
//    @Test
//    public void mineTest() {
//        systemTradeJob.mineJob();
//    }
    @Autowired
    private DappFundFlowDao dappFundFlowDao;
    @Test
    public void fundFlowInsertTest() {
        DappFundFlowEntity rewardFlow = new DappFundFlowEntity(11L, BigDecimal.valueOf(1L), 4, 2, BigDecimal.ZERO);
        rewardFlow.setFromHash("1");
        dappFundFlowDao.insert(rewardFlow);
    }
    @Test
    public void userBuyRewardTest() {
        chainProducer.sendUserBuyReward(56L);
    }
    @Test
    public void coinDecimalsTest() {
        int decimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals();
        BigInteger bigInteger = new BigInteger("110000000000");
        BigDecimal amount = new BigDecimal(bigInteger.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN);
        System.out.println(amount);
    }
    @Autowired
    private DappSystemService dappSystemService;
    @Test
    public void profitTest() {
        dappSystemService.tradeProfitDistribute(31L);
    }
    @Test
    public void nftBalanceTest() {
        BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).balanceOf("0x971c09aa9735eb98459b17ec8b48932d24cbb931");
        System.out.println(1);
    }
    @Test
    public void nftTotalSupplyTest() {
        BigInteger bigInteger = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).totalSupplyNFT();
        int i = CardPeriod.ONE.recommendCnt(bigInteger.intValue());
        System.out.println(i);
    }
    @Autowired
    private BscUsdtContractEvent bscUsdtContractEvent;
src/test/java/cc/mrbird/febs/JunitTest.java
@@ -3,7 +3,6 @@
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.dapp.entity.DappMemberEntity;
import cc.mrbird.febs.dapp.mapper.DappMemberDao;
import cc.mrbird.febs.job.MineProfitJob;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
@@ -30,22 +29,8 @@
 **/
@SpringBootTest
public class JunitTest {
    @Autowired
    private MineProfitJob mineProfitJob;
    @Autowired
    private DappMemberDao dappMemberDao;
    @Test
    public void incomeTest() {
        mineProfitJob.start();
    }
    @Test
    public void userTest() {
        DappMemberEntity member = dappMemberDao.selectById(6L);
        mineProfitJob.calAgentMoney(member, BigDecimal.TEN);
    }
    public static void main(String[] args) {
        DateTime tomorrow = DateUtil.beginOfDay(DateUtil.tomorrow());