From b603c6cfda6ff46e09310d724d0b7374db12496b Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Wed, 30 Nov 2022 11:40:55 +0800
Subject: [PATCH] 20221124

---
 src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java |   41 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 37 insertions(+), 4 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 4b8702d..d33ade5 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
@@ -52,6 +52,7 @@
     private final DappWalletService dappWalletService;
     private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
     private final DappSystemProfitDao dappSystemProfitDao;
+    private final ChainProducer chainProducer;
 
 
     @Override
@@ -338,16 +339,20 @@
 
                 BigDecimal memberLevelProfit = levelProfitTotal.multiply(profit).multiply(memberLevel);
 
-                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 2, BigDecimal.ZERO,null,dappSystemProfit.getId());
+                DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
                 dappFundFlowDao.insert(fundFlow);
+                //发送转币消息
+                chainProducer.sendBnbTransferMsg(fundFlow.getId());
                 systemProfitTotal = systemProfitTotal.add(memberLevelProfit);
             }
         }
         //如果还有剩余给技术方
         if(levelProfitTotal.compareTo(systemProfitTotal) > 0){
             BigDecimal avaProfit = levelProfitTotal.subtract(systemProfit);
-            DappFundFlowEntity fundFlow = new DappFundFlowEntity(memberId, avaProfit, 5, 2, BigDecimal.ZERO,null,dappSystemProfit.getId());
+            DappFundFlowEntity fundFlow = new DappFundFlowEntity(memberId, avaProfit, 5, 1, BigDecimal.ZERO,null,dappSystemProfit.getId());
             dappFundFlowDao.insert(fundFlow);
+            //发送转币消息
+            chainProducer.sendBnbTransferMsg(fundFlow.getId());
         }
     }
 
@@ -401,14 +406,16 @@
         dappSystemProfitDao.updateById(dappSystemProfitNow);
 
         //todo 直接拿走0.95ge
-        DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), new BigDecimal(0.95), 7, 2, BigDecimal.ZERO, null,dappSystemProfitNow.getId());
+        DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), new BigDecimal(0.95), 7, 1, BigDecimal.ZERO, null,dappSystemProfitNow.getId());
         dappFundFlowDao.insert(fundFlowOut);
+        //发送转币消息
+        chainProducer.sendBnbTransferMsg(fundFlowOut.getId());
         //复投 成功{type: 1, txHash: result.transactionHash, id: res.data, flag: 'success', buyType: 2}
         DataDictionaryCustom investAmountSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INVEST_AMOUNT.getType(), DataDictionaryEnum.INVEST_AMOUNT.getCode());
         BigDecimal investAmount = new BigDecimal(investAmountSet.getValue());
         //todo 直接运行转账
         String txHash = "复投";
-        DappFundFlowEntity fundFlow = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmount, 6, 2, BigDecimal.ZERO, txHash);
+        DappFundFlowEntity fundFlow = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmount, 6, 1, BigDecimal.ZERO, txHash);
         dappFundFlowDao.insert(fundFlow);
 
         TransferDto transferDto = new TransferDto();
@@ -421,6 +428,32 @@
         dappWalletService.transferAgain(transferDto);
     }
 
+    @Override
+    public void bnbTransfer(Long id) {
+        //获取对应的流水记录
+        DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id);
+        if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == dappFundFlowEntity.getStatus()){
+            return;
+        }
+        //金额
+        BigDecimal amount = dappFundFlowEntity.getAmount();
+        Long memberId = dappFundFlowEntity.getMemberId();
+        DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId);
+        if(ObjectUtil.isEmpty(dappMemberEntity)){
+            return;
+        }
+        //目标地址
+        String address = dappMemberEntity.getAddress();
+        String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(address, amount);
+        if(StrUtil.isEmpty(hash)){
+            return;
+        }
+        dappFundFlowEntity.setToHash(hash);
+        dappFundFlowEntity.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_AGREE);
+        dappFundFlowDao.updateById(dappFundFlowEntity);
+
+    }
+
     public static void main(String[] args) {
         String refererIds = "1,2,3,4,5," +
                             "6,7,8,9,10," +

--
Gitblit v1.9.1