Helius
2022-06-08 21c4edde92e2c7bade302db52329422821f0a8d5
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -135,6 +135,7 @@
    @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());
@@ -155,8 +156,7 @@
        log.info("销毁数量:{}, 比例:{}", destroy, slipSetting.getDestroyPoint());
        // 销毁
//        instance.transfer(AppContants.DESTROY_ADDRESS, destroy);
        OnlineTransferUtil.addTransfer(AppContants.DESTROY_ADDRESS, destroy, fundflow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, fundflow.getId().toString());
        OnlineTransferUtil.addTransfer(AppContants.DESTROY_ADDRESS, destroy, fundflow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
        // 总分发金额
        BigDecimal distrbAmount = fee.subtract(destroy);
@@ -166,6 +166,7 @@
        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());
@@ -173,26 +174,30 @@
            // 若地址持币少了指定数量
            if (balance.compareTo(new BigDecimal(miniHoldCoin.getValue())) < 0) {
                return;
                    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, fundflow.getId().toString());
                OnlineTransferUtil.addTransfer(parent.getAddress(), total, fundflow.getType(), 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
            nodeAmount = nodeAmount.subtract(total);
                i++;
            }
        }
        // 若节点金额还有剩余,则进入技术金额
        techAmount = techAmount.add(nodeAmount);
//        instance.transfer(ChainEnum.BSC_TFC_TECH.getAddress(), techAmount);
        OnlineTransferUtil.addTransfer(ChainEnum.BSC_TFC_TECH.getAddress(), techAmount, fundflow.getType(), 2, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, fundflow.getId().toString());
        OnlineTransferUtil.addTransfer(ChainEnum.BSC_TFC_TECH.getAddress(), techAmount, fundflow.getType(), 2, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo);
        Map<String, String> map = new HashMap<>();
        map.put("batchNo", fundflow.getId().toString());
        map.put("type", "flow");
        map.put("batchNo", batchNo);
        map.put("type", "batch");
        // 发送转账消息
        chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map));
@@ -262,8 +267,17 @@
                continue;
            }
            // TODO 线上转账,已注释
            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());
@@ -271,26 +285,8 @@
            if ("flow".equals(jsonObject.getString("type"))) {
                DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(Long.parseLong(batchNo));
                fundFlow.setStatus(3);
                fundFlow.setToHash(txHash);
                dappFundFlowDao.updateById(fundFlow);
            }
            // 修改剩余量
            if (AppContants.SYMBOL_COIN.equals(transfer.getSymbol())) {
                BigDecimal poolRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN);
                redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, poolRemain.subtract(transfer.getAmount()));
            } else {
                BigDecimal usdtRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN);
                usdtRemain = usdtRemain.subtract(transfer.getAmount());
                if (usdtRemain.compareTo(BigDecimal.ZERO) < 0) {
                    usdtRemain = BigDecimal.ZERO;
                }
                redisUtils.set(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN, usdtRemain);
            }
        }
    }