From b8def92a54d520776e37db7925c5109f3bd95ff8 Mon Sep 17 00:00:00 2001
From: wzy <wzy19931122ai@163.com>
Date: Wed, 09 Nov 2022 23:56:39 +0800
Subject: [PATCH] fix

---
 src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java |   43 +++++++++++++++++++++++++++++--------------
 1 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
index 1f8da63..26758fc 100644
--- a/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -12,6 +12,7 @@
 import cc.mrbird.febs.dapp.chain.ContractChainService;
 import cc.mrbird.febs.dapp.dto.*;
 import cc.mrbird.febs.dapp.entity.*;
+import cc.mrbird.febs.dapp.enumerate.DataDictionaryEnum;
 import cc.mrbird.febs.dapp.mapper.*;
 import cc.mrbird.febs.dapp.service.DappWalletService;
 import cc.mrbird.febs.dapp.utils.BoxUtil;
@@ -54,6 +55,7 @@
     private final RedisUtils redisUtils;
     private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
     private final DappNftActivationDao dappNftActivationDao;
+    private final MemberCoinWithdrawDao memberCoinWithdrawDao;
 
     private final ChainProducer chainProducer;
     private final DappSystemDao dappSystemDao;
@@ -90,7 +92,7 @@
             dappFundFlowEntity.setType(recordInPageDto.getType());
         }
         dappFundFlowEntity.setMemberId(member.getId());
-        dappFundFlowEntity.setStatus(2);
+//        dappFundFlowEntity.setStatus(2);
 
         IPage<DappFundFlowEntity> records = dappFundFlowDao.selectInPage(page, dappFundFlowEntity);
         return records.getRecords();
@@ -176,13 +178,15 @@
 
     @Override
     public BigDecimal calPrice(PriceDto priceDto) {
-        String priceStr = redisUtils.getString(AppContants.REDIS_KEY_TFC_NEW_PRICE);
+//        String priceStr = redisUtils.getString(AppContants.REDIS_KEY_TFC_NEW_PRICE);
+        DataDictionaryCustom symbolPrice = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYMBOL_PRICE.getType(), DataDictionaryEnum.SYMBOL_PRICE.getCode());
+        DataDictionaryCustom serviceFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WITHDRAW_SERVICE_FEE.getType(), DataDictionaryEnum.WITHDRAW_SERVICE_FEE.getCode());
 
         BigDecimal amount = priceDto.getAmount();
         if (priceDto.getAmount() == null) {
             amount = BigDecimal.ZERO;
         }
-        return amount.multiply(new BigDecimal("0.1")).divide(new BigDecimal(priceStr), 2, RoundingMode.HALF_UP);
+        return amount.multiply(new BigDecimal(serviceFeeDic.getValue()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_DOWN)).divide(new BigDecimal(symbolPrice.getValue()), 2, RoundingMode.HALF_UP);
     }
 
     @Override
@@ -197,27 +201,38 @@
 
         DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(member.getId());
         if (walletMine.getAvailableAmount().compareTo(withdrawDto.getFee()) < 0) {
-            throw new FebsException("TFC Not Enough");
+            throw new FebsException("DMD Not Enough");
         }
 
         updateWalletCoinWithLock(withdrawDto.getAmount(), member.getId(), 2);
         updateWalletMineWithLock(withdrawDto.getFee(), member.getId(), 2);
 
+
         DappFundFlowEntity feeFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getFee().negate(), 7, 2, null, null);
         dappFundFlowDao.insert(feeFlow);
 
-        DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getAmount().negate(), 5, 2, withdrawDto.getFee(), null);
+        DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getAmount().negate(), 5, 1, withdrawDto.getFee(), null);
         dappFundFlowDao.insert(fundFlow);
 
-        String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(member.getAddress(), withdrawDto.getAmount());
-        fundFlow.setToHash(hash);
-        dappFundFlowDao.updateById(fundFlow);
+        MemberCoinWithdrawEntity memberCoinWithdraw = new MemberCoinWithdrawEntity();
+        memberCoinWithdraw.setMemberId(member.getId());
+        memberCoinWithdraw.setAddress(member.getAddress());
+        memberCoinWithdraw.setAmount(withdrawDto.getAmount());
+        memberCoinWithdraw.setFeeAmount(withdrawDto.getFee());
+        memberCoinWithdraw.setStatus(MemberCoinWithdrawEntity.STATUS_DOING);
+        memberCoinWithdraw.setSymbol("USDT");
+        memberCoinWithdraw.setFlowId(fundFlow.getId());
+        memberCoinWithdrawDao.insert(memberCoinWithdraw);
 
-        Map<String, Object> map = new HashMap<>();
-        map.put("fee", withdrawDto.getFee());
-        map.put("address", ChainEnum.BSC_TFC_FEE.getAddress());
-        map.put("flow", feeFlow.getId());
-        chainProducer.sendTfcFee(JSONObject.toJSONString(map));
+//        String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(member.getAddress(), withdrawDto.getAmount());
+//        fundFlow.setToHash(hash);
+//        dappFundFlowDao.updateById(fundFlow);
+
+//        Map<String, Object> map = new HashMap<>();
+//        map.put("fee", withdrawDto.getFee());
+//        map.put("address", ChainEnum.BSC_TFC_FEE.getAddress());
+//        map.put("flow", feeFlow.getId());
+//        chainProducer.sendTfcFee(JSONObject.toJSONString(map));
     }
 
     @Override
@@ -257,7 +272,7 @@
                 walletMine.setAvailableAmount(walletMine.getAvailableAmount().add(amount));
             } else {
                 if (amount.compareTo(walletMine.getAvailableAmount()) > 0) {
-                    throw new FebsException("TFC Not Enough");
+                    throw new FebsException("DMD Not Enough");
                 }
                 walletMine.setTotalAmount(walletMine.getTotalAmount().subtract(amount));
                 walletMine.setAvailableAmount(walletMine.getAvailableAmount().subtract(amount));

--
Gitblit v1.9.1