From e6d01c8312b6adb1db73cebea9e8293a44267ee8 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 31 Jul 2023 10:05:33 +0800
Subject: [PATCH] 智能合约

---
 src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java |  871 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 821 insertions(+), 50 deletions(-)

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 1c38810..8c5623b 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
@@ -1,6 +1,7 @@
 package cc.mrbird.febs.dapp.service.impl;
 
 import cc.mrbird.febs.common.contants.AppContants;
+import cc.mrbird.febs.common.exception.FebsException;
 import cc.mrbird.febs.common.utils.LoginUserUtil;
 import cc.mrbird.febs.common.utils.RedisUtils;
 import cc.mrbird.febs.common.utils.SpringContextUtil;
@@ -39,6 +40,8 @@
 import java.math.BigInteger;
 import java.math.RoundingMode;
 import java.util.*;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 import java.util.stream.Collectors;
 
 /**
@@ -623,7 +626,7 @@
                 PoolEnum.COIN_A_PRICE.getType(),
                 PoolEnum.COIN_A_PRICE.getCode()
         );
-        BigDecimal coinAPrice = new BigDecimal(StrUtil.isEmpty(coinAPriceDic.getValue()) ? "0" : coinAPriceDic.getValue()).setScale(8,BigDecimal.ROUND_DOWN);
+        BigDecimal coinAPrice = new BigDecimal(StrUtil.isEmpty(coinAPriceDic.getValue()) ? "0" : coinAPriceDic.getValue()).setScale(12,BigDecimal.ROUND_DOWN);
         /**
          * 会员充值USDT买入A币记录的ID
          */
@@ -650,6 +653,17 @@
         BigDecimal amountPerk = dappUsdtPerkEntity.getAmount();
         amountPerk = amountPerk.add(amount.multiply(new BigDecimal(3)));
         dappUsdtPerkEntity.setAmount(amountPerk);
+        //生成一条金本位的三倍额度的资金流水记录
+        DappFundFlowEntity amountPerkFundFlow = new DappFundFlowEntity(
+                memberId,
+                amount.multiply(new BigDecimal(3)),
+                FundFlowEnum.MEMBER_AMOUNT_PERK_TOTAL.getCode(),
+                2,
+                BigDecimal.ZERO,
+                null,
+                chergeRecordId);
+        dappFundFlowDao.insert(amountPerkFundFlow);
+
         //增加业绩
         BigDecimal achieveAmount = dappUsdtPerkEntity.getAchieveAmount();
         achieveAmount = achieveAmount.add(amount);
@@ -666,10 +680,10 @@
                 PoolEnum.USDT_A_PERCENT.getType(),
                 PoolEnum.USDT_A_PERCENT.getCode()
         );
-        BigDecimal usdtAPercent = new BigDecimal(StrUtil.isEmpty(usdtAPercentDic.getValue()) ? "0.9" : usdtAPercentDic.getValue());
+        BigDecimal usdtAPercent = new BigDecimal(StrUtil.isEmpty(usdtAPercentDic.getValue()) ? "0.7" : usdtAPercentDic.getValue());
         BigDecimal usdtAAmount = amount.multiply(usdtAPercent).setScale(4, BigDecimal.ROUND_DOWN);
 
-        //生成一条进行中的90%进入A币底池的资金流水记录
+        //生成一条进行中的70%进入A币底池的资金流水记录
         DappFundFlowEntity fundFlowToA = new DappFundFlowEntity(
                 1L,
                 usdtAAmount,
@@ -681,6 +695,18 @@
         dappFundFlowDao.insert(fundFlowToA);
         //90%进入A币底池
         chainProducer.sendAntACoinInAPoolMsg(fundFlowToA.getId());
+
+        BigDecimal usdtWAmount = amount.multiply(new BigDecimal(0.2)).setScale(4, BigDecimal.ROUND_DOWN);
+        //生成一条进行中的20%进入A币底池的资金流水记录
+        DappFundFlowEntity fundFlowToW = new DappFundFlowEntity(
+                1L,
+                usdtWAmount,
+                FundFlowEnum.USDT_IN_W_POOL.getCode(),
+                1,
+                BigDecimal.ZERO,
+                null,
+                chergeRecordId);
+        dappFundFlowDao.insert(fundFlowToW);
 
         DataDictionaryCustom usdtBPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                 PoolEnum.USDT_B_PERCENT.getType(),
@@ -740,7 +766,7 @@
         coinAUsdtPriceDic.setValue(coinAUsdtPriceDicCnt.toString());
         dataDictionaryCustomMapper.updateById(coinAUsdtPriceDic);
 
-        BigDecimal divide = coinAUsdtPriceDicCnt.divide(coinACntDicCnt, 8, BigDecimal.ROUND_DOWN);
+        BigDecimal divide = coinAUsdtPriceDicCnt.divide(coinACntDicCnt, 12, BigDecimal.ROUND_DOWN);
         coinAPriceDic.setValue(divide.toString());
         dataDictionaryCustomMapper.updateById(coinAPriceDic);
 
@@ -809,7 +835,24 @@
                 chergeRecordId);
         dappFundFlowDao.insert(poolAllMemberAFundFlow);
 
-        nodePoolPerk(poolAllMemberAPercentCnt, MemberLevelEnum.MEMBER.getType(), FundFlowEnum.POOL_MEMBER_A_CNT.getCode());
+//        BigDecimal poolAllMemberAPercentCntAva = nodePoolPerk(poolAllMemberAPercentCnt, MemberLevelEnum.MEMBER.getType(), FundFlowEnum.POOL_MEMBER_A_CNT.getCode());
+        /**
+         * 20%全网加权平分,按照个人投资占比全网的比例去平分
+         */
+        chainProducer.sendAllMemberPerkAvaMsg(poolAllMemberAFundFlow.getId());
+//        BigDecimal poolAllMemberAPercentCntAva = allMemberPerk(poolAllMemberAPercentCnt, FundFlowEnum.POOL_MEMBER_A_CNT.getCode());
+//        DappFundFlowEntity poolAllMemberAFundFlowAva = new DappFundFlowEntity(
+//                1L,
+//                poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva),
+//                FundFlowEnum.POOL_MEMBER_A_CNT.getCode(),
+//                2,
+//                BigDecimal.ZERO,
+//                null,
+//                chergeRecordId);
+//        dappFundFlowDao.insert(poolAllMemberAFundFlowAva);
+//        dappWalletService.updateWalletMineWithLock(poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva),
+//                1L,1);
+
         /**
          * 10%直推
          */
@@ -854,6 +897,19 @@
                 //用户的A币账户增加directAPercentCnt数量
                 dappWalletService.updateWalletMineWithLock(directAPercentFundFlowToMemberFlag,directMemberEntity.getId(),1);
             }
+            if(directAPercentCnt.compareTo(directAPercentFundFlowToMemberFlag) > 0){
+                DappFundFlowEntity directAPercentFundFlowToMemberAva = new DappFundFlowEntity(
+                        1L,
+                        directAPercentCnt.subtract(directAPercentFundFlowToMemberFlag),
+                        FundFlowEnum.DIRECT_A_PERCENT.getCode(),
+                        2,
+                        BigDecimal.ZERO,
+                        null,
+                        chergeRecordId);
+                dappFundFlowDao.insert(directAPercentFundFlowToMemberAva);
+                dappWalletService.updateWalletMineWithLock(directAPercentCnt.subtract(directAPercentFundFlowToMemberFlag),
+                        AppContants.YL_MEMBER_ID,1);
+            }
         }
         /**
          * 5%节点
@@ -884,7 +940,21 @@
         nodeAPercentPoolDic.setValue(nodeAPercentPoolDicCnt.toString());
         dataDictionaryCustomMapper.updateById(nodeAPercentPoolDic);
 
-        superNodePoolPerk(nodeAPercentCnt, NodeCodeEnum.SUPER_NODE.getCode(), FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode());
+        BigDecimal nodeAPercentCntAva = superNodePoolPerk(nodeAPercentCnt, NodeCodeEnum.SUPER_NODE.getCode(), FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode());
+
+        if(nodeAPercentCnt.compareTo(nodeAPercentCntAva) > 0){
+            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
+                    1L,
+                    nodeAPercentCnt.subtract(nodeAPercentCntAva),
+                    FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode(),
+                    2,
+                    BigDecimal.ZERO,
+                    null,
+                    chergeRecordId);
+            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
+            dappWalletService.updateWalletMineWithLock(nodeAPercentCnt.subtract(nodeAPercentCntAva),
+                    AppContants.YL_MEMBER_ID,1);
+        }
         /**
          * 5%基金会
          */
@@ -897,7 +967,7 @@
 
         //生成一条5%基金会的资金流水记录
         DappFundFlowEntity foundationAPercentFundFlow = new DappFundFlowEntity(
-                1L,
+                295L,
                 foundationAPercentCnt,
                 FundFlowEnum.FOUNDATION_A_PERCENT.getCode(),
                 2,
@@ -906,7 +976,7 @@
                 chergeRecordId);
         dappFundFlowDao.insert(foundationAPercentFundFlow);
         //用户的A币账户增加memberGetACnt数量
-        dappWalletService.updateWalletMineWithLock(foundationAPercentCnt,1L,1);
+        dappWalletService.updateWalletMineWithLock(foundationAPercentCnt,295L,1);
         /**
          * 10%级差奖
          */
@@ -929,6 +999,65 @@
         dappFundFlowDao.insert(levelAPercentCntFundFlow);
         chainProducer.sendAntACoinInLevelMsg(levelAPercentCntFundFlow.getId());
 
+        /**
+         * 更新用户为有效用户
+         */
+        dappMemberDao.updateMemberActiveStatus(1,memberId);
+
+    }
+
+    private BigDecimal allMemberPerk(BigDecimal poolAllMemberAPercentCnt, int code) {
+
+        BigDecimal realPerkAmount = BigDecimal.ZERO;
+        /**
+         * 查询总业绩
+         */
+        List<DappChargeUsdtEntity> dappChargeUsdtEntities = dappChargeUsdtMapper.selectList(null);
+        if(CollUtil.isEmpty(dappChargeUsdtEntities)){
+            return realPerkAmount;
+        }
+        //总入金
+        BigDecimal amountAll = dappChargeUsdtEntities.stream().map(DappChargeUsdtEntity::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+        if(BigDecimal.ZERO.compareTo(amountAll) >= 0){
+            return realPerkAmount;
+        }
+        /**
+         * 每个人入金的总额
+         */
+        Map<Long, BigDecimal> amountMap = dappChargeUsdtEntities.stream().collect(
+                Collectors.groupingBy(DappChargeUsdtEntity::getMemberId,
+                        Collectors.reducing(BigDecimal.ZERO, DappChargeUsdtEntity::getAmount, BigDecimal::add)));
+        /**
+         * 入金1U分的代币个数
+         */
+        BigDecimal usdtOfCnt = poolAllMemberAPercentCnt.divide(amountAll, 8, BigDecimal.ROUND_DOWN);
+
+        for (Map.Entry<Long, BigDecimal> entry : amountMap.entrySet()) {
+            Long memberId = entry.getKey();
+            //当前会员的入金总和
+            BigDecimal amount = entry.getValue();
+            if(BigDecimal.ZERO.compareTo(amount) >= 0){
+                continue;
+            }
+            //应该平分到的数量
+            BigDecimal memberCnt = amount.multiply(usdtOfCnt).setScale(8,BigDecimal.ROUND_DOWN);
+            BigDecimal fundFlowToMemberFlag = this.getAndUpdateMemberPerk(memberId, memberCnt);
+            if(fundFlowToMemberFlag.compareTo(BigDecimal.ZERO) > 0){
+                //生成一条50%客户秒到的资金流水记录
+                DappFundFlowEntity fundFlowToMember = new DappFundFlowEntity(
+                        memberId,
+                        fundFlowToMemberFlag,
+                        code,
+                        2,
+                        BigDecimal.ZERO);
+                dappFundFlowDao.insert(fundFlowToMember);
+                //用户的A币账户增加memberGetACnt数量
+                dappWalletService.updateWalletMineWithLock(fundFlowToMemberFlag,memberId,1);
+
+                realPerkAmount = realPerkAmount.add(fundFlowToMemberFlag);
+            }
+        }
+        return realPerkAmount;
     }
 
     @Override
@@ -943,6 +1072,13 @@
         BigDecimal amount = dappFundFlowEntity.getAmount();
         //目标地址
         String address = AppContants.ADDRESS_A_POOL_PEOJECT;
+        if(5 == dappFundFlowEntity.getType()){
+            address = AppContants.ADDRESS_A_POOL_PEOJECT;
+        }else if(34 == dappFundFlowEntity.getType() ){
+            address = ChainEnum.BSC_USDT_W_POOL.getAddress();
+        }else{
+            return;
+        }
         /**
          * 发起USDT转账
          */
@@ -955,6 +1091,15 @@
         dappFundFlowEntity.setStatus(2);
         dappFundFlowDao.updateById(dappFundFlowEntity);
     }
+
+//    public static void main(String[] args) {
+//        String address = "0x7a9bfE048d110EF90a467803653f9B8666f9096C";
+//        /**
+//         * 发起USDT转账
+//         */
+//        String hash = ChainService.getInstance(ChainEnum.BSC_USDT_W_POOL_CONTRACT.name()).transferUSDT(address, new BigDecimal("0.99"));
+//        System.out.println(hash);
+//    }
 
     @Override
     public void AntACoinBPollInMsg(Long id) {
@@ -1116,7 +1261,19 @@
                     dappFundFlowDao.updateById(dappFundFlowEntity);
                     BigDecimal subtract = amountTC.subtract(teamIncomePerkTotal);
                     //用户的A币账户增加divide数量
-                    dappWalletService.updateWalletMineWithLock(subtract,1L,1);
+//                    if(amountTC.compareTo(teamIncomePerkTotal) > 0){
+//                        DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
+//                                1L,
+//                                subtract,
+//                                FundFlowEnum.LEVEL_A_PERCENT_CNT_MEMBER.getCode(),
+//                                2,
+//                                BigDecimal.ZERO,
+//                                null,
+//                                systemProfitId);
+//                        dappFundFlowDao.insert(nodeAPercentFundFlowAva);
+//                        dappWalletService.updateWalletMineWithLock(subtract,
+//                                1L,1);
+//                    }
                 }
             }
         }
@@ -1131,7 +1288,22 @@
         BigDecimal averagePerk = nodePerk.getAveragePerk();
         BigDecimal averagePerkCnt = amountTC.multiply(averagePerk).setScale(4, BigDecimal.ROUND_DOWN);
 
-        nodePoolPerk(averagePerkCnt, MemberLevelEnum.NODE_3.getType(), FundFlowEnum.DAO_3_NODE_PERK.getCode());
+        BigDecimal averagePerkCntAva = nodePoolPerk(averagePerkCnt, MemberLevelEnum.NODE_3.getType(), FundFlowEnum.DAO_3_NODE_PERK.getCode());
+
+        //用户的A币账户增加divide数量
+        if(averagePerkCnt.compareTo(averagePerkCntAva) > 0){
+            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
+                    1L,
+                    averagePerkCnt.subtract(averagePerkCntAva),
+                    FundFlowEnum.DAO_3_NODE_PERK.getCode(),
+                    2,
+                    BigDecimal.ZERO,
+                    null,
+                    systemProfitId);
+            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
+            dappWalletService.updateWalletMineWithLock(averagePerkCnt.subtract(averagePerkCntAva),
+                    AppContants.YL_MEMBER_ID,1);
+        }
         //生成流水记录
         DappFundFlowEntity nodeThreeFundFlow = new DappFundFlowEntity(
                 1L,
@@ -1158,7 +1330,21 @@
         BigDecimal averagePerkFour = nodeFourDicPerk.getAveragePerk();
         BigDecimal averagePerkFourCnt = amountTC.multiply(averagePerkFour).setScale(4, BigDecimal.ROUND_DOWN);
 
-        nodePoolPerk(averagePerkFourCnt, MemberLevelEnum.NODE_4.getType(), FundFlowEnum.DAO_4_NODE_PERK.getCode());
+        BigDecimal averagePerkFourCntAva = nodePoolPerk(averagePerkFourCnt, MemberLevelEnum.NODE_4.getType(), FundFlowEnum.DAO_4_NODE_PERK.getCode());
+        //用户的A币账户增加divide数量
+        if(averagePerkFourCnt.compareTo(averagePerkFourCntAva) > 0){
+            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
+                    1L,
+                    averagePerkFourCnt.subtract(averagePerkFourCntAva),
+                    FundFlowEnum.DAO_4_NODE_PERK.getCode(),
+                    2,
+                    BigDecimal.ZERO,
+                    null,
+                    systemProfitId);
+            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
+            dappWalletService.updateWalletMineWithLock(averagePerkFourCnt.subtract(averagePerkFourCntAva),
+                    AppContants.YL_MEMBER_ID,1);
+        }
         DappFundFlowEntity nodeFourFundFlow = new DappFundFlowEntity(
                 1L,
                 averagePerkFourCnt,
@@ -1183,7 +1369,21 @@
         BigDecimal averagePerkFive = nodeFiveDicPerk.getAveragePerk();
         BigDecimal averagePerkFiveCnt = amountTC.multiply(averagePerkFive).setScale(4, BigDecimal.ROUND_DOWN);
 
-        nodePoolPerk(averagePerkFiveCnt, MemberLevelEnum.NODE_5.getType(), FundFlowEnum.DAO_5_NODE_PERK.getCode());
+        BigDecimal averagePerkFiveCntAva = nodePoolPerk(averagePerkFiveCnt, MemberLevelEnum.NODE_5.getType(), FundFlowEnum.DAO_5_NODE_PERK.getCode());
+        //用户的A币账户增加divide数量
+        if(averagePerkFiveCnt.compareTo(averagePerkFiveCntAva) > 0){
+            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
+                    1L,
+                    averagePerkFiveCnt.subtract(averagePerkFiveCntAva),
+                    FundFlowEnum.DAO_5_NODE_PERK.getCode(),
+                    2,
+                    BigDecimal.ZERO,
+                    null,
+                    systemProfitId);
+            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
+            dappWalletService.updateWalletMineWithLock(averagePerkFiveCnt.subtract(averagePerkFiveCntAva),
+                    AppContants.YL_MEMBER_ID,1);
+        }
         DappFundFlowEntity nodeFiveFundFlow = new DappFundFlowEntity(
                 1L,
                 averagePerkFiveCnt,
@@ -1210,7 +1410,21 @@
         BigDecimal nodeFiveEquals = new BigDecimal(nodeFiveEqualsDic.getValue());
         BigDecimal nodeFiveEqualsCnt = amountTC.multiply(nodeFiveEquals).setScale(4, BigDecimal.ROUND_DOWN);
 
-        nodePoolEqualsPerk(nodeFiveEqualsCnt, MemberLevelEnum.NODE_5.getType(), FundFlowEnum.DAO_5_NODE_EQUALS_PERK.getCode());
+        BigDecimal nodeFiveEqualsCntAva = nodePoolEqualsPerk(nodeFiveEqualsCnt, MemberLevelEnum.NODE_5.getType(), FundFlowEnum.DAO_5_NODE_EQUALS_PERK.getCode());
+        //用户的A币账户增加divide数量
+        if(nodeFiveEqualsCnt.compareTo(nodeFiveEqualsCntAva) > 0){
+            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
+                    1L,
+                    nodeFiveEqualsCnt.subtract(nodeFiveEqualsCntAva),
+                    FundFlowEnum.DAO_5_NODE_EQUALS_PERK.getCode(),
+                    2,
+                    BigDecimal.ZERO,
+                    null,
+                    systemProfitId);
+            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
+            dappWalletService.updateWalletMineWithLock(nodeFiveEqualsCnt.subtract(nodeFiveEqualsCntAva),
+                    AppContants.YL_MEMBER_ID,1);
+        }
         DappFundFlowEntity nodeFiveEqualsFundFlow = new DappFundFlowEntity(
                 1L,
                 nodeFiveEqualsCnt,
@@ -1318,7 +1532,8 @@
         //获取type级别的会员
         List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectMemberByAccountTypeAnd(type);
         //每日补贴总数
-        BigDecimal nodePerk = nodeFivePoolDicCnt.multiply(AppContants.NODE_PERK_PERCENT);
+//        BigDecimal nodePerk = nodeFivePoolDicCnt.multiply(AppContants.NODE_PERK_PERCENT);
+        BigDecimal nodePerk = nodeFivePoolDicCnt;
         if(CollUtil.isNotEmpty(dappMemberEntities)){
             //每人的补贴
             BigDecimal averagePerk = nodePerk.divide(new BigDecimal(dappMemberEntities.size()), 4, BigDecimal.ROUND_DOWN);
@@ -1347,25 +1562,26 @@
     public BigDecimal superNodePoolPerk(BigDecimal nodeFivePoolDicCnt, String code, int code1) {
         BigDecimal realPerkAmount = BigDecimal.ZERO;
         //获取type级别的会员
-        List<DappMemberNodeEntity> dappMemberNodeEntities = dappMemberNodeMapper.selectNodeByNodeCode(NodeCodeEnum.SUPER_NODE.getCode());
+//        List<DappMemberNodeEntity> dappMemberNodeEntities = dappMemberNodeMapper.selectNodeByNodeCode(NodeCodeEnum.SUPER_NODE.getCode());
+        List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectByNodetype();
         //每日补贴总数
 //        BigDecimal nodePerk = nodeFivePoolDicCnt.multiply(AppContants.NODE_PERK_PERCENT);
         BigDecimal nodePerk = nodeFivePoolDicCnt;
-        if(CollUtil.isNotEmpty(dappMemberNodeEntities)){
+        if(CollUtil.isNotEmpty(dappMemberEntities)){
             //每人的补贴
-            BigDecimal averagePerk = nodePerk.divide(new BigDecimal(dappMemberNodeEntities.size()), 4, BigDecimal.ROUND_DOWN);
+            BigDecimal averagePerk = nodePerk.divide(new BigDecimal(dappMemberEntities.size()), 4, BigDecimal.ROUND_DOWN);
 
-            for(DappMemberNodeEntity dappMemberNodeEntity : dappMemberNodeEntities){
+            for(DappMemberEntity dappMemberEntitie : dappMemberEntities){
 
                 DappFundFlowEntity fundFlowToMember = new DappFundFlowEntity(
-                        dappMemberNodeEntity.getMemberId(),
+                        dappMemberEntitie.getId(),
                         averagePerk,
                         code1,
                         2,
                         BigDecimal.ZERO);
                 dappFundFlowDao.insert(fundFlowToMember);
                 //用户的A币账户增加memberGetACnt数量
-                dappWalletService.updateWalletMineWithLock(averagePerk,dappMemberNodeEntity.getMemberId(),1);
+                dappWalletService.updateWalletMineWithLock(averagePerk,dappMemberEntitie.getId(),1);
 
                 realPerkAmount = realPerkAmount.add(averagePerk);
             }
@@ -1375,6 +1591,7 @@
 
     @Override
     public void selectAndInsertDics() {
+        selectAndInsertDic(PoolEnum.ANDAO_MEMBER_TO_MENBER_PERCENT.getType(),PoolEnum.ANDAO_MEMBER_TO_MENBER_PERCENT.getCode(),"0.2","ANDAO互转20%");
         selectAndInsertDic(PoolEnum.TRANSFER_A_AUSD_PRICE.getType(),PoolEnum.TRANSFER_A_AUSD_PRICE.getCode(),"0.01","AUSD价格");
         selectAndInsertDic(PoolEnum.TRANSFER_A_AUSD_PERCENT.getType(),PoolEnum.TRANSFER_A_AUSD_PERCENT.getCode(),"0.1","买入A,10%的AUSD比例");
         selectAndInsertDic(PoolEnum.WALLET_COIN_OUT_PERCENT.getType(),PoolEnum.WALLET_COIN_OUT_PERCENT.getCode(),"0.3","30%回流底池溢价");
@@ -1448,7 +1665,11 @@
             return;
         }
         //金额
-        BigDecimal amount = dappFundFlowEntity.getAmount();
+        BigDecimal amount = dappFundFlowEntity.getAmount().setScale(4,BigDecimal.ROUND_DOWN).negate();
+        log.info("amount:{}",amount);
+        if(BigDecimal.ZERO.compareTo(amount) >= 0){
+            return;
+        }
 
         Long memberId = dappFundFlowEntity.getMemberId();
         DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
@@ -1458,14 +1679,34 @@
          * 发起USDT转账
          */
         log.info("amount:{},address:{}",amount,address);
-//        String hash = ChainService.getInstance(ChainEnum.BSC_USDT_W_POOL.name()).transfer(address, amount);
+
+        String hash = ChainService.getInstance(ChainEnum.BSC_USDT_W_POOL_CONTRACT.name()).transferUSDT(address, amount);
+        if(StrUtil.isEmpty(hash)){
+//            hash = ChainService.getInstance(ChainEnum.BSC_USDT_W_POOL.name()).transfer(address, amount);
+            return;
+        }
 //        if(StrUtil.isEmpty(hash)){
 //            return;
 //        }
-//        log.info("{},{}",id,hash);
-//        dappFundFlowEntity.setFromHash(hash);
-//        dappFundFlowEntity.setStatus(2);
-//        dappFundFlowDao.updateById(dappFundFlowEntity);
+        log.info("{},{}",id,hash);
+        dappFundFlowEntity.setFromHash(hash);
+        dappFundFlowEntity.setStatus(2);
+        dappFundFlowDao.updateById(dappFundFlowEntity);
+    }
+
+    /**
+     * 紧急提现方法
+     */
+    public static void main(String[] args) {
+        BigDecimal amount = new BigDecimal("0.01");
+        String address = "0xB3cF9669F398f444DfCAebbAd2A49bF32ba41fE3";
+
+        String hash = ChainService.getInstance(ChainEnum.BSC_USDT_W_POOL_CONTRACT.name()).transferUSDT(address, amount);
+
+        System.out.println(hash);
+
+
+//        int i = ChainService.getInstance(ChainEnum.BSC_TFC.name()).allowanceCnt("0x80098f854950f9327C4F4E747d285Fd2d41fbf3e");
     }
 
     @Override
@@ -1511,7 +1752,7 @@
                 PoolEnum.COIN_A_CNT.getType(),
                 PoolEnum.COIN_A_CNT.getCode());
         BigDecimal coinACnt = new BigDecimal(coinACntDic.getValue());
-        coinACnt = coinACnt.subtract(totalCnt);
+        coinACnt = coinACnt.subtract(totalCnt.multiply(new BigDecimal(0.8)));
         coinACntDic.setValue(coinACnt.toString());
         dataDictionaryCustomMapper.updateById(coinACntDic);
 
@@ -1523,11 +1764,42 @@
         DataDictionaryCustom coinAPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                 PoolEnum.COIN_A_PRICE.getType(),
                 PoolEnum.COIN_A_PRICE.getCode());
-        BigDecimal coinAPrice = coinAUsdt.divide(coinACnt,8,BigDecimal.ROUND_DOWN);
+
+        BigDecimal coinAPrice = coinAUsdt.divide(coinACnt,12,BigDecimal.ROUND_DOWN);
         coinAPriceDic.setValue(coinAPrice.toString());
         dataDictionaryCustomMapper.updateById(coinAPriceDic);
+        /**
+         * 增加K线数据
+         */
+        DappAKlineEntity dappAKlineEntity = new DappAKlineEntity();
+        dappAKlineEntity.setType(0);
+        /**
+         * 获取最新一条小时或者分钟的数据
+         */
+        DappAKlineEntity oldOne = dappAKlineMapper.selectOneByType();
+        if(ObjectUtil.isNotEmpty(oldOne)){
+            dappAKlineEntity.setOpenPrice(oldOne.getClosePrice());
+            dappAKlineEntity.setLowestPrice(oldOne.getClosePrice());
+        }else{
+            dappAKlineEntity.setOpenPrice(coinAPrice);
+            dappAKlineEntity.setLowestPrice(coinAPrice);
+        }
+        dappAKlineEntity.setHighestPrice(coinAPrice);
+        dappAKlineEntity.setClosePrice(coinAPrice);
+        dappAKlineMapper.insert(dappAKlineEntity);
 
-        chainProducer.sendAntKLineMsg(0);
+
+        List<cn.hutool.json.JSONObject> objects = new ArrayList<>();
+        List<AKLineLimitVo> akLineLimitVos = dappAKlineMapper.selectListByTypeAndLimit(0, AppContants.K_LINE_LIMIT);
+        if(CollUtil.isNotEmpty(akLineLimitVos)) {
+            Collections.reverse(akLineLimitVos);
+            for (AKLineLimitVo akLineLimitVo : akLineLimitVos) {
+                cn.hutool.json.JSONObject parseObj = JSONUtil.parseObj(akLineLimitVo);
+                objects.add(parseObj);
+            }
+            redisUtils.del(AppContants.K_LINE_NOW);
+            redisUtils.set(AppContants.K_LINE_NOW, objects.toString());
+        }
     }
 
     @Override
@@ -1583,11 +1855,15 @@
         );
 
         BigDecimal coinAPrice = new BigDecimal(dataDictionaryCustom.getValue());
-        DateTime dateTime = DateUtil.offsetHour(DateUtil.date(), -1);
-        String format = DateUtil.format(dateTime, "yyyy-MM-dd HH");
-        List<String> dataDayStrList = new ArrayList<>();
-        dataDayStrList.add(format);
-        List<DappAKlineEntity> dappAKlineEntities = dappAKlineMapper.selectListByTypeAndHour(dataDayStrList);
+        /**
+         * 查询出上一条更新的小时数据
+         */
+        DappAKlineEntity minRecord = dappAKlineMapper.selectOneHourByType();
+        if(ObjectUtil.isEmpty(minRecord)){
+            minRecord = dappAKlineMapper.selectOneByTypeAsc();
+        }
+        DappAKlineEntity maxRecord = dappAKlineMapper.selectOneByType();
+        List<DappAKlineEntity> dappAKlineEntities = dappAKlineMapper.selectListByIds(minRecord.getId(),maxRecord.getId());
 
         DappAKlineEntity dappAKlineEntity = new DappAKlineEntity();
         dappAKlineEntity.setType(1);
@@ -1609,12 +1885,7 @@
             dappAKlineEntity.setHighestPrice(coinAPrice);
             dappAKlineEntity.setLowestPrice(coinAPrice);
         }
-        DappAKlineEntity oldOne = dappAKlineMapper.selectOneByType();
-        if(ObjectUtil.isNotEmpty(oldOne)){
-            dappAKlineEntity.setClosePrice(oldOne.getClosePrice());
-        }else{
-            dappAKlineEntity.setClosePrice(coinAPrice);
-        }
+        dappAKlineEntity.setClosePrice(coinAPrice);
         dappAKlineMapper.insert(dappAKlineEntity);
 
         chainProducer.sendAntKLineMsg(1);
@@ -1757,7 +2028,7 @@
             redisKey = AppContants.K_LINE_MONTH;
         }else if(0 == type){
             createKDate();
-            return;
+            redisKey = AppContants.K_LINE_NOW;
         }else{
             return;
         }
@@ -1774,6 +2045,504 @@
         }
 
     }
+
+    @Override
+    public void antKLineABMsg(Long id) {
+        log.info("{}",id);
+        //获取对应的流水记录
+        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id);
+        if(ObjectUtil.isEmpty(dappFundFlowEntity)){
+            return;
+        }
+        Long memberId = dappFundFlowEntity.getMemberId();
+        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
+        if(ObjectUtil.isEmpty(dappMemberEntity)){
+            return;
+        }
+        DappFundFlowEntity dappFundFlow = dappFundFlowDao.selectById(id);
+        //金额
+        BigDecimal amount = dappFundFlow.getAmount();
+        //目标地址
+        String address = null;
+        if(5 == dappFundFlowEntity.getType()){
+            address = AppContants.ADDRESS_A_POOL_PEOJECT;
+        }else if(6 == dappFundFlowEntity.getType()){
+            address = AppContants.ADDRESS_B_POOL_PEOJECT;
+        }else if(34 == dappFundFlowEntity.getType()){
+            address = ChainEnum.BSC_USDT_W_POOL.getAddress();
+        }else{
+            return;
+        }
+        /**
+         * 发起USDT转账
+         */
+        String hash = ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(address, amount);
+        if(StrUtil.isEmpty(hash)){
+            return;
+        }
+        log.info("{},{}",id,hash);
+        dappFundFlow.setFromHash(hash);
+        dappFundFlow.setStatus(2);
+        dappFundFlowDao.updateById(dappFundFlow);
+
+    }
+
+//    public static void main(String[] args) {
+//        for(int i = 0; i < 100; i++){
+//            ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(AppContants.ADDRESS_A_POOL_PEOJECT, new BigDecimal(70));
+//            try {
+//                Thread.sleep(20000);
+//            } catch (InterruptedException e) {
+//                e.printStackTrace();
+//            }
+//
+//            ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(AppContants.ADDRESS_B_POOL_PEOJECT, new BigDecimal(20));
+//
+//            try {
+//                Thread.sleep(20000);
+//            } catch (InterruptedException e) {
+//                e.printStackTrace();
+//            }
+//
+//            ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(ChainEnum.BSC_USDT_W_POOL.getAddress(), new BigDecimal(10));
+//            try {
+//                Thread.sleep(20000);
+//            } catch (InterruptedException e) {
+//                e.printStackTrace();
+//            }
+//        }
+//    }
+
+    @Override
+    public void allMemberPerkAvaMsg(Long id) {
+        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id);
+        if(ObjectUtil.isEmpty(dappFundFlowEntity)){
+            return;
+        }
+
+        BigDecimal poolAllMemberAPercentCnt = dappFundFlowEntity.getAmount();
+        BigDecimal poolAllMemberAPercentCntAva = allMemberPerk(poolAllMemberAPercentCnt, FundFlowEnum.POOL_MEMBER_A_CNT.getCode());
+        DappFundFlowEntity poolAllMemberAFundFlowAva = new DappFundFlowEntity(
+                1L,
+                poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva),
+                FundFlowEnum.POOL_MEMBER_A_CNT.getCode(),
+                2,
+                BigDecimal.ZERO,
+                null,
+                dappFundFlowEntity.getSystemProfitId());
+        dappFundFlowDao.insert(poolAllMemberAFundFlowAva);
+        dappWalletService.updateWalletMineWithLock(poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva),
+                AppContants.YL_MEMBER_ID,1);
+
+    }
+    @Override
+    public void contractAnDaoMsg(Long flowId) {
+        DappFundFlowEntity flow = dappFundFlowDao.selectById(flowId);
+        if(ObjectUtil.isEmpty(flow)){
+            return;
+        }
+        Long memberId = flow.getMemberId();
+        if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == flow.getStatus()){
+            return;
+        }
+        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
+        if(ObjectUtil.isEmpty(dappMemberEntity)){
+            return;
+        }
+        /**
+         * 生成会员入金买A币的记录
+         */
+        DappChargeUsdtEntity dappChargeUsdtEntity = new DappChargeUsdtEntity(
+                memberId,
+                dappMemberEntity.getAddress(),
+                null,
+                2,
+                flow.getAmount(),
+                BigDecimal.ZERO,
+                BigDecimal.ZERO);
+        dappChargeUsdtMapper.insert(dappChargeUsdtEntity);
+        /**
+         * 减少用户的AUSD数量
+         */
+        DappUsdtPerkEntity dappUsdtPerkEntity = dappUsdtPerkEntityMapper.selectByMemberId(memberId);
+        BigDecimal ausdAmount = dappUsdtPerkEntity.getAusdAmount();
+        ausdAmount = ausdAmount.subtract(flow.getFee()).setScale(4,BigDecimal.ROUND_DOWN);
+        dappUsdtPerkEntity.setAusdAmount(ausdAmount);
+        dappUsdtPerkEntityMapper.updateById(dappUsdtPerkEntity);
+        /**
+         * 流水关联用户购买记录
+         */
+        flow.setSystemProfitId(dappChargeUsdtEntity.getId());
+        /**
+         * 链上转账的hash值
+         */
+//        flow.setFromHash(null);
+        flow.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
+        dappFundFlowDao.updateById(flow);
+
+        /**
+         * 发送消息处理返利逻辑
+         */
+        chainProducer.sendAntACoinInContractMsg(flow.getId());
+        /**
+         * 发送消息处理代理升级
+         */
+        chainProducer.sendAntMemberLevelMsg(memberId);
+    }
+
+    @Override
+    public void contractAnDaoInMsg(Long flowId) {
+        /**
+         * 获取对应的流水记录
+         */
+        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(flowId);
+        if(ObjectUtil.isEmpty(dappFundFlowEntity)){
+            return;
+        }
+        if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE != dappFundFlowEntity.getStatus()){
+            return;
+        }
+        Long memberId = dappFundFlowEntity.getMemberId();
+        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
+        if(ObjectUtil.isEmpty(dappMemberEntity)){
+            return;
+        }
+        /**
+         * 会员充值金额
+         */
+        BigDecimal amount = dappFundFlowEntity.getAmount();
+        /**
+         * A币的当前价格
+         */
+        DataDictionaryCustom coinAPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.COIN_A_PRICE.getType(),
+                PoolEnum.COIN_A_PRICE.getCode()
+        );
+        BigDecimal coinAPrice = new BigDecimal(StrUtil.isEmpty(coinAPriceDic.getValue()) ? "0" : coinAPriceDic.getValue()).setScale(12,BigDecimal.ROUND_DOWN);
+        /**
+         * 会员充值USDT买入A币记录的ID
+         */
+        Long chergeRecordId = dappFundFlowEntity.getSystemProfitId() == null ? 0L : dappFundFlowEntity.getSystemProfitId();
+        DappChargeUsdtEntity dappChargeUsdtEntity = dappChargeUsdtMapper.selectById(chergeRecordId);
+        if(ObjectUtil.isEmpty(dappChargeUsdtEntity)){
+            return;
+        }
+        if(2 != dappChargeUsdtEntity.getStatus()){
+            return;
+        }
+//        if(StrUtil.isEmpty(dappChargeUsdtEntity.getMemberHash())){
+//            return;
+//        }
+        /**
+         * 金本位的三倍额度,增加业绩,增加对应的NFT的值
+         */
+        DappUsdtPerkEntity dappUsdtPerkEntity = dappUsdtPerkEntityMapper.selectByMemberId(memberId);
+        if(ObjectUtil.isEmpty(dappUsdtPerkEntity)){
+            dappUsdtPerkEntity = new DappUsdtPerkEntity();
+            dappUsdtPerkEntity.setAmount(amount.multiply(new BigDecimal(3)));
+            dappUsdtPerkEntity.setNftDevote(amount);
+            dappUsdtPerkEntity.setMemberId(memberId);
+            dappUsdtPerkEntityMapper.insert(dappUsdtPerkEntity);
+        }
+        //金本位的三倍额度
+        BigDecimal amountPerk = dappUsdtPerkEntity.getAmount();
+        amountPerk = amountPerk.add(amount.multiply(new BigDecimal(3)));
+        dappUsdtPerkEntity.setAmount(amountPerk);
+        //生成一条金本位的三倍额度的资金流水记录
+        DappFundFlowEntity amountPerkFundFlow = new DappFundFlowEntity(
+                memberId,
+                amount.multiply(new BigDecimal(3)),
+                FundFlowEnum.MEMBER_AMOUNT_PERK_TOTAL.getCode(),
+                2,
+                BigDecimal.ZERO,
+                null,
+                chergeRecordId);
+        dappFundFlowDao.insert(amountPerkFundFlow);
+
+        //增加业绩
+        BigDecimal achieveAmount = dappUsdtPerkEntity.getAchieveAmount();
+        achieveAmount = achieveAmount.add(amount);
+        dappUsdtPerkEntity.setAchieveAmount(achieveAmount);
+        //增加对应的NFT的值
+        BigDecimal nftDevote = dappUsdtPerkEntity.getNftDevote();
+        nftDevote = nftDevote.add(amount);
+        dappUsdtPerkEntity.setNftDevote(nftDevote);
+        dappUsdtPerkEntityMapper.updateById(dappUsdtPerkEntity);
+        /**
+         * 1.90%底池的USDT做成100%溢价,铸造出70%金本位价值的A币。
+         */
+        DataDictionaryCustom produceAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.PRODUCE_A_PERCENT.getType(),
+                PoolEnum.PRODUCE_A_PERCENT.getCode()
+        );
+        BigDecimal produceAPercent = new BigDecimal(StrUtil.isEmpty(produceAPercentDic.getValue()) ? "0.7" : produceAPercentDic.getValue());
+        //购买数量
+        BigDecimal totalCnt = amount.divide(coinAPrice, 4, BigDecimal.ROUND_DOWN);
+        /**
+         * 铸造出70%金本位价值的A币。实际产生数量
+         */
+        BigDecimal realCnt = totalCnt.multiply(produceAPercent).setScale(4, BigDecimal.ROUND_DOWN);
+        dappChargeUsdtEntity.setTotalCnt(totalCnt);
+        dappChargeUsdtEntity.setRealCnt(realCnt);
+        dappChargeUsdtMapper.updateById(dappChargeUsdtEntity);
+        /**
+         * 重新计算A币的价格
+         */
+        DataDictionaryCustom coinACntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.COIN_A_CNT.getType(),
+                PoolEnum.COIN_A_CNT.getCode()
+        );
+        //A币币本位底池-A币的数量
+        BigDecimal coinACntDicCnt = new BigDecimal(coinACntDic.getValue());
+        coinACntDicCnt = coinACntDicCnt.add(realCnt);
+        coinACntDic.setValue(coinACntDicCnt.toString());
+        dataDictionaryCustomMapper.updateById(coinACntDic);
+
+        DataDictionaryCustom coinAUsdtPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.COIN_A_USDT_PRICE.getType(),
+                PoolEnum.COIN_A_USDT_PRICE.getCode()
+        );
+        //A币金本位底池-usdt数量
+        BigDecimal coinAUsdtPriceDicCnt = new BigDecimal(coinAUsdtPriceDic.getValue());
+        coinAUsdtPriceDicCnt = coinAUsdtPriceDicCnt.add(amount.multiply(new BigDecimal(0.8)));
+        coinAUsdtPriceDic.setValue(coinAUsdtPriceDicCnt.toString());
+        dataDictionaryCustomMapper.updateById(coinAUsdtPriceDic);
+
+        BigDecimal divide = coinAUsdtPriceDicCnt.divide(coinACntDicCnt, 12, BigDecimal.ROUND_DOWN);
+        coinAPriceDic.setValue(divide.toString());
+        dataDictionaryCustomMapper.updateById(coinAPriceDic);
+
+        chainProducer.sendAntKLineMsg(0);
+        /**
+         * A币的分配 walletMine
+         * 【70%换算100%分配】
+         * 50%客户秒到
+         * 20%全网加权分红(按20%释放递减)
+         * 10%直推
+         * 5%节点
+         * 5%基金会
+         * 10%级差奖
+         */
+        /**
+         * 50%客户秒到
+         */
+        DataDictionaryCustom memberGetAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.MEMBER_GET_A_PERCENT.getType(),
+                PoolEnum.MEMBER_GET_A_PERCENT.getCode()
+        );
+        BigDecimal memberGetAPercent = new BigDecimal(StrUtil.isEmpty(memberGetAPercentDic.getValue()) ? "0.5" : memberGetAPercentDic.getValue());
+        BigDecimal memberGetACnt = realCnt.multiply(memberGetAPercent).setScale(4, BigDecimal.ROUND_DOWN);
+
+        BigDecimal fundFlowToMemberFlag = this.getAndUpdateMemberPerk(dappFundFlowEntity.getMemberId(), memberGetACnt);
+        if(fundFlowToMemberFlag.compareTo(BigDecimal.ZERO) > 0){
+            //生成一条50%客户秒到的资金流水记录
+            DappFundFlowEntity fundFlowToMember = new DappFundFlowEntity(
+                    dappFundFlowEntity.getMemberId(),
+                    fundFlowToMemberFlag,
+                    FundFlowEnum.MEMBER_GET_A_CNT.getCode(),
+                    2,
+                    BigDecimal.ZERO,
+                    null,
+                    chergeRecordId);
+            dappFundFlowDao.insert(fundFlowToMember);
+            //用户的A币账户增加memberGetACnt数量
+            dappWalletService.updateWalletMineWithLock(fundFlowToMemberFlag,dappFundFlowEntity.getMemberId(),1);
+        }
+        /**
+         * 20%全网加权分红(按20%释放递减)进入加权分红底池
+         */
+        DataDictionaryCustom poolAllMemberAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.POOL_ALL_MEMBER_A_PERCENT.getType(),
+                PoolEnum.POOL_ALL_MEMBER_A_PERCENT.getCode()
+        );
+        BigDecimal poolAllMemberAPercent = new BigDecimal(StrUtil.isEmpty(poolAllMemberAPercentDic.getValue()) ? "0.2" : poolAllMemberAPercentDic.getValue());
+        BigDecimal poolAllMemberAPercentCnt = realCnt.multiply(poolAllMemberAPercent).setScale(4, BigDecimal.ROUND_DOWN);
+
+        DataDictionaryCustom poolAllMemberACntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.POOL_ALL_MEMBER_A_CNT.getType(),
+                PoolEnum.POOL_ALL_MEMBER_A_CNT.getCode()
+        );
+        BigDecimal poolAllMemberACnt = new BigDecimal(StrUtil.isEmpty(poolAllMemberACntDic.getValue()) ? "0" : poolAllMemberACntDic.getValue());
+        poolAllMemberACnt = poolAllMemberACnt.add(poolAllMemberAPercentCnt);
+        poolAllMemberACntDic.setValue(poolAllMemberACnt.toString());
+        dataDictionaryCustomMapper.updateById(poolAllMemberACntDic);
+        //生成一条20%全网加权分红(按20%释放递减)进入加权分红底池的资金流水记录
+        DappFundFlowEntity poolAllMemberAFundFlow = new DappFundFlowEntity(
+                1L,
+                poolAllMemberAPercentCnt,
+                FundFlowEnum.POOL_ALL_MEMBER_A_CNT.getCode(),
+                2,
+                BigDecimal.ZERO,
+                null,
+                chergeRecordId);
+        dappFundFlowDao.insert(poolAllMemberAFundFlow);
+
+        /**
+         * 20%全网加权平分,按照个人投资占比全网的比例去平分
+         */
+        chainProducer.sendAllMemberPerkAvaMsg(poolAllMemberAFundFlow.getId());
+        /**
+         * 10%直推
+         */
+        DataDictionaryCustom directAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.DIRECT_A_PERCENT.getType(),
+                PoolEnum.DIRECT_A_PERCENT.getCode()
+        );
+        BigDecimal directAPercent = new BigDecimal(StrUtil.isEmpty(directAPercentDic.getValue()) ? "0.1" : directAPercentDic.getValue());
+        BigDecimal directAPercentCnt = realCnt.multiply(directAPercent).setScale(4, BigDecimal.ROUND_DOWN);
+
+        String refererId = dappMemberEntity.getRefererId();
+        DappMemberEntity directMemberEntity = dappMemberDao.selectMemberInfoByInviteId(refererId);
+        if(ObjectUtil.isNotEmpty(directMemberEntity)){
+            /**
+             *推荐用户入单可享有贡献值.例.推荐100获得100贡献值
+             */
+            DappUsdtPerkEntity directDappUsdtPerkEntity = dappUsdtPerkEntityMapper.selectByMemberId(directMemberEntity.getId());
+            if(ObjectUtil.isEmpty(directDappUsdtPerkEntity)){
+                directDappUsdtPerkEntity = new DappUsdtPerkEntity();
+                directDappUsdtPerkEntity.setNftDevote(amount);
+                directDappUsdtPerkEntity.setMemberId(directMemberEntity.getId());
+                dappUsdtPerkEntityMapper.insert(directDappUsdtPerkEntity);
+            }
+
+            BigDecimal directNftDevote = directDappUsdtPerkEntity.getNftDevote();
+            directNftDevote = directNftDevote.add(amount);
+            directDappUsdtPerkEntity.setNftDevote(directNftDevote);
+            dappUsdtPerkEntityMapper.updateById(directDappUsdtPerkEntity);
+
+            BigDecimal directAPercentFundFlowToMemberFlag = this.getAndUpdateMemberPerk(directMemberEntity.getId(), directAPercentCnt);
+            if(directAPercentFundFlowToMemberFlag.compareTo(BigDecimal.ZERO) > 0){
+                //生成一条10%直推的资金流水记录
+                DappFundFlowEntity directAPercentFundFlowToMember = new DappFundFlowEntity(
+                        directMemberEntity.getId(),
+                        directAPercentFundFlowToMemberFlag,
+                        FundFlowEnum.DIRECT_A_PERCENT.getCode(),
+                        2,
+                        BigDecimal.ZERO,
+                        null,
+                        chergeRecordId);
+                dappFundFlowDao.insert(directAPercentFundFlowToMember);
+                //用户的A币账户增加directAPercentCnt数量
+                dappWalletService.updateWalletMineWithLock(directAPercentFundFlowToMemberFlag,directMemberEntity.getId(),1);
+            }
+            if(directAPercentCnt.compareTo(directAPercentFundFlowToMemberFlag) > 0){
+                DappFundFlowEntity directAPercentFundFlowToMemberAva = new DappFundFlowEntity(
+                        1L,
+                        directAPercentCnt.subtract(directAPercentFundFlowToMemberFlag),
+                        FundFlowEnum.DIRECT_A_PERCENT.getCode(),
+                        2,
+                        BigDecimal.ZERO,
+                        null,
+                        chergeRecordId);
+                dappFundFlowDao.insert(directAPercentFundFlowToMemberAva);
+                dappWalletService.updateWalletMineWithLock(directAPercentCnt.subtract(directAPercentFundFlowToMemberFlag),
+                        AppContants.YL_MEMBER_ID,1);
+            }
+        }
+        /**
+         * 5%节点
+         */
+        DataDictionaryCustom nodeAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.NODE_A_PERCENT.getType(),
+                PoolEnum.NODE_A_PERCENT.getCode()
+        );
+        BigDecimal nodeAPercent = new BigDecimal(StrUtil.isEmpty(nodeAPercentDic.getValue()) ? "0.05" : nodeAPercentDic.getValue());
+        BigDecimal nodeAPercentCnt = realCnt.multiply(nodeAPercent).setScale(4, BigDecimal.ROUND_DOWN);
+        //生成一条5%节点的资金流水记录
+        DappFundFlowEntity nodeAPercentFundFlow = new DappFundFlowEntity(
+                1L,
+                nodeAPercentCnt,
+                FundFlowEnum.NODE_A_PERCENT.getCode(),
+                2,
+                BigDecimal.ZERO,
+                null,
+                chergeRecordId);
+        dappFundFlowDao.insert(nodeAPercentFundFlow);
+//        chainProducer.sendAntACoinInNodeMsg(nodeAPercentFundFlow.getId());
+        DataDictionaryCustom nodeAPercentPoolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.NODE_A_PERCENT_POOL.getType(),
+                PoolEnum.NODE_A_PERCENT_POOL.getCode()
+        );
+        BigDecimal nodeAPercentPoolDicCnt = new BigDecimal(StrUtil.isEmpty(nodeAPercentPoolDic.getValue()) ? "0" : nodeAPercentPoolDic.getValue());
+        nodeAPercentPoolDicCnt = nodeAPercentPoolDicCnt.add(nodeAPercentCnt);
+        nodeAPercentPoolDic.setValue(nodeAPercentPoolDicCnt.toString());
+        dataDictionaryCustomMapper.updateById(nodeAPercentPoolDic);
+
+        BigDecimal nodeAPercentCntAva = superNodePoolPerk(nodeAPercentCnt, NodeCodeEnum.SUPER_NODE.getCode(), FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode());
+
+        if(nodeAPercentCnt.compareTo(nodeAPercentCntAva) > 0){
+            DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity(
+                    1L,
+                    nodeAPercentCnt.subtract(nodeAPercentCntAva),
+                    FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode(),
+                    2,
+                    BigDecimal.ZERO,
+                    null,
+                    chergeRecordId);
+            dappFundFlowDao.insert(nodeAPercentFundFlowAva);
+            dappWalletService.updateWalletMineWithLock(nodeAPercentCnt.subtract(nodeAPercentCntAva),
+                    AppContants.YL_MEMBER_ID,1);
+        }
+        /**
+         * 5%基金会
+         */
+        DataDictionaryCustom foundationAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.FOUNDATION_A_PERCENT.getType(),
+                PoolEnum.FOUNDATION_A_PERCENT.getCode()
+        );
+        BigDecimal foundationAPercent = new BigDecimal(StrUtil.isEmpty(foundationAPercentDic.getValue()) ? "0.05" : foundationAPercentDic.getValue());
+        BigDecimal foundationAPercentCnt = realCnt.multiply(foundationAPercent).setScale(4, BigDecimal.ROUND_DOWN);
+
+        //生成一条5%基金会的资金流水记录
+        DappFundFlowEntity foundationAPercentFundFlow = new DappFundFlowEntity(
+                295L,
+                foundationAPercentCnt,
+                FundFlowEnum.FOUNDATION_A_PERCENT.getCode(),
+                2,
+                BigDecimal.ZERO,
+                null,
+                chergeRecordId);
+        dappFundFlowDao.insert(foundationAPercentFundFlow);
+        //用户的A币账户增加memberGetACnt数量
+        dappWalletService.updateWalletMineWithLock(foundationAPercentCnt,295L,1);
+        /**
+         * 10%级差奖
+         */
+        DataDictionaryCustom levelAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.LEVEL_A_PERCENT.getType(),
+                PoolEnum.LEVEL_A_PERCENT.getCode()
+        );
+        BigDecimal levelAPercent = new BigDecimal(StrUtil.isEmpty(levelAPercentDic.getValue()) ? "0.1" : levelAPercentDic.getValue());
+        BigDecimal levelAPercentCnt = realCnt.multiply(levelAPercent).setScale(4, BigDecimal.ROUND_DOWN);
+
+        //生成一条10%级差奖进入10%级差奖底池的资金流水记录
+        DappFundFlowEntity levelAPercentCntFundFlow = new DappFundFlowEntity(
+                1L,
+                levelAPercentCnt,
+                FundFlowEnum.LEVEL_A_PERCENT_CNT.getCode(),
+                2,
+                BigDecimal.ZERO,
+                null,
+                chergeRecordId);
+        dappFundFlowDao.insert(levelAPercentCntFundFlow);
+        chainProducer.sendAntACoinInLevelMsg(levelAPercentCntFundFlow.getId());
+
+        /**
+         * 更新用户为有效用户
+         */
+        dappMemberDao.updateMemberActiveStatus(1,memberId);
+
+    }
+
+    /**
+     * 测试转账
+     * @param args
+     */
+//    public static void main(String[] args) {
+//        String transfer = ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer("0x74fC0e035f315F7BD8b7686e22581AB1afC45e97", new BigDecimal(1));
+//        System.out.println(transfer);
+//
+//    }
 
     /**
      * 生成当前分钟的k线数据,type为0
@@ -1793,22 +2562,24 @@
         DappAKlineEntity oldOne = dappAKlineMapper.selectOneByType();
         if(ObjectUtil.isNotEmpty(oldOne)){
             dappAKlineEntity.setOpenPrice(oldOne.getClosePrice());
+            dappAKlineEntity.setLowestPrice(oldOne.getClosePrice());
+        }else{
+            dappAKlineEntity.setOpenPrice(coinAPrice);
+            dappAKlineEntity.setLowestPrice(coinAPrice);
         }
-        dappAKlineEntity.setOpenPrice(coinAPrice);
-        dappAKlineEntity.setLowestPrice(coinAPrice);
         dappAKlineEntity.setHighestPrice(coinAPrice);
         dappAKlineEntity.setClosePrice(coinAPrice);
         dappAKlineMapper.insert(dappAKlineEntity);
 
     }
 
-    public static void main(String[] args) {
-
-        int month = DateUtil.dayOfMonth(DateUtil.date());
-        String s = DateUtil.dayOfWeekEnum(DateUtil.date()).toChinese();
-        System.out.println(s);
-        System.out.println(month);
-    }
+//    public static void main(String[] args) {
+//
+//        int month = DateUtil.dayOfMonth(DateUtil.date());
+//        String s = DateUtil.dayOfWeekEnum(DateUtil.date()).toChinese();
+//        System.out.println(s);
+//        System.out.println(month);
+//    }
 
     /**
      * 判断直推人数是否达标

--
Gitblit v1.9.1