From 46def5897de95d01c1606a49da4292f5f1e53760 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 12 Jun 2023 10:14:05 +0800
Subject: [PATCH] twoCoin项目修改

---
 src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java |  159 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 138 insertions(+), 21 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 5115526..e4d20b4 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
@@ -36,6 +36,7 @@
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import freemarker.template.utility.StringUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -363,6 +364,15 @@
          * A币卖币规则,卖出100%销毁,30%回流底池溢价
          */
         DappMemberEntity member = LoginUserUtil.getAppUser();
+
+        DataDictionaryCustom systemStateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.SYSTEM.getType(),
+                PoolEnum.SYSTEM.getCode()
+        );
+        String value = systemStateDic.getValue();
+        if("STOP".equals(value)){
+            throw new FebsException("Not yet open");
+        }
         //提币数量
         BigDecimal amount = withdrawDto.getAmount();
         if(BigDecimal.ZERO.compareTo(amount) >= 0){
@@ -402,9 +412,16 @@
         BigDecimal feePercent = new BigDecimal(toUsdtPercentFeeDic.getValue());
         //手续费扣除USDT
         BigDecimal feeUsdtAmount = coinUsdtAmount.multiply(feePercent).setScale(4,BigDecimal.ROUND_DOWN);
-        //实际提现USDT数量
-        BigDecimal realUsdtAmount = coinUsdtAmount.subtract(feeUsdtAmount).setScale(4,BigDecimal.ROUND_DOWN);
+        //实际提现USDT数量,先扣除1%的手续费后,只到账70%
 
+        DataDictionaryCustom outPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.WALLET_COIN_OUT_PERCENT.getType(),
+                PoolEnum.WALLET_COIN_OUT_PERCENT.getCode()
+        );
+        BigDecimal outPercent = new BigDecimal(outPercentDic.getValue());
+        BigDecimal realUsdtAmount = coinUsdtAmount.subtract(feeUsdtAmount).setScale(4,BigDecimal.ROUND_DOWN);
+        BigDecimal realUsdtAmountFee = realUsdtAmount.multiply(outPercent).setScale(4,BigDecimal.ROUND_DOWN);
+        realUsdtAmount = realUsdtAmount.subtract(realUsdtAmountFee);
         //减少闪对钱包的币的数量
         this.updateWalletCoinWithLock(amount, member.getId(), 2);
         //增加流水
@@ -429,11 +446,6 @@
         /**
          * A币卖币规则,卖出100%销毁,30%回流底池溢价
          */
-        DataDictionaryCustom outPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
-                PoolEnum.WALLET_COIN_OUT_PERCENT.getType(),
-                PoolEnum.WALLET_COIN_OUT_PERCENT.getCode()
-        );
-        BigDecimal outPercent = new BigDecimal(outPercentDic.getValue());
         coinUsdtAmount = coinUsdtAmount.multiply(outPercent).setScale(4,BigDecimal.ROUND_DOWN);
         //金本位底池数量
         DataDictionaryCustom coinAUsdtPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
@@ -457,13 +469,6 @@
         coinAPrice = coinAUsdtCnt.divide(coinACnt,12,BigDecimal.ROUND_DOWN);
         aCoinPriceDic.setValue(coinAPrice.toString());
         dataDictionaryCustomMapper.updateById(aCoinPriceDic);
-
-        DappFundFlowEntity flowSubtract = new DappFundFlowEntity(1L,
-                coinUsdtAmount,
-                FundFlowEnum.WALLET_COIN_TO_USDT_W.getCode(),
-                2,
-                BigDecimal.ZERO);
-        dappFundFlowDao.insert(flowSubtract);
 
         chainProducer.sendAntKLineMsg(0);
     }
@@ -624,11 +629,32 @@
         }
     }
 
+    public static void main(String[] args) {
+        String ss = "0x2bBAD0d2362a8dbdc655fBa5A0cd51d5379e38f7,0xd5c13dc4372d1e02b93add9dcca901bef51168be,0xe22bb5fB2e0F8ED9366785dADD33cA19355d037c,0x7685E62E679886494E3cdc3DE7103E026f815AF0,0x6893bE8F4fb73595A13f32bA5e1d198Ab135516C";
+//        if(ss.contains("0xd5c13dc4372d1e02b93add9dcca901bef51168be")){
+//            System.out.println(1);
+//        }else{
+//            System.out.println(2);
+//        }
+//        getLocalAddress("0x2bBAD0d2362a8dbdc655fBa5A0cd51d5379e38f7");
+        BigDecimal amountIn = BigDecimal.valueOf(951);
+        BigDecimal result = amountIn.divide(BigDecimal.valueOf(100));
+        System.out.println(result.remainder(BigDecimal.ONE).equals(BigDecimal.ZERO));
+    }
+
     @Override
     public Long transferA(TransferADto transferADto) {
         DappMemberEntity member = LoginUserUtil.getAppUser();
         DappMemberEntity dappMemberEntity = dappMemberDao.selectById(member.getId());
 
+        DataDictionaryCustom systemStateDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                PoolEnum.SYSTEM.getType(),
+                PoolEnum.SYSTEM.getCode()
+        );
+        String value = systemStateDic.getValue();
+        if("STOP".equals(value)){
+            throw new FebsException("Not yet open");
+        }
         String upgrade = redisUtils.getString("APP_UPGRADE");
         if ("upgrade".equals(upgrade)) {
             throw new FebsException("功能升级中");
@@ -682,6 +708,46 @@
                     if (fundFlowOld.getStatus() == 1 && StrUtil.isEmpty(fundFlowOld.getFromHash())) {
                         dappFundFlowDao.deleteById(fundFlowOld.getId());
                         throw new FebsException("Refresh and try again");
+                    }
+                }
+                /**
+                 * 入金限制
+                 *  每人总共入金100U
+                 */
+                BigDecimal amountIn = transferADto.getAmount();
+//                if(amountIn.compareTo(new BigDecimal(100)) != 0){
+//                    throw new FebsException("Limit per address 100 USDT");
+//                }
+                /**
+                 * 每单金额得大于100 小于1000 限制
+                 */
+                if(amountIn.compareTo(new BigDecimal(100)) < 0){
+                    throw new FebsException("Min 100");
+                }
+                if(amountIn.compareTo(new BigDecimal(1000)) > 0){
+                    throw new FebsException("Max 1000");
+                }
+
+                BigDecimal result = amountIn.divide(BigDecimal.valueOf(100));
+                if(!result.remainder(BigDecimal.ONE).equals(BigDecimal.ZERO)){
+                    throw new FebsException("Please enter an integer multiple of 100");
+                }
+
+//                BigDecimal amountInLast = dappChargeUsdtMapper.selectByMaxAmountMemberId(member.getId());
+                /**
+                 * 限制用户买入总额,
+                 *  目前每人限一单,总金额限制100U
+                 */
+//                BigDecimal amountInLast = dappChargeUsdtMapper.selectBySumAmountMemberId(member.getId());
+                BigDecimal amountInLast = dappChargeUsdtMapper.selectBySumAmountMemberIdAndDate(member.getId(),DateUtil.today());
+                /**
+                 * 每个地址只能使用一次 限制总额1000U
+                 */
+                BigDecimal amountInAll = amountInLast.add(amountIn);
+                if(getLocalAddress(dappMemberEntity.getAddress())){
+                    if(amountInAll.compareTo(new BigDecimal(1000)) > 0){
+                        BigDecimal add = new BigDecimal(1000).subtract(amountInLast).setScale(0, BigDecimal.ROUND_DOWN);
+                        throw new FebsException("Max "+ add.toString());
                     }
                 }
                 /**
@@ -785,6 +851,29 @@
         return null;
     }
 
+    public boolean getLocalAddress(String address){
+        /**
+         * dappMemberEntity.getAddress().equals("0x2bBAD0d2362a8dbdc655fBa5A0cd51d5379e38f7")
+         *                             ||dappMemberEntity.getAddress().equals("0xd5c13dc4372d1e02b93add9dcca901bef51168be")
+         *                             ||dappMemberEntity.getAddress().equals("0xe22bb5fB2e0F8ED9366785dADD33cA19355d037c")
+         *                             ||dappMemberEntity.getAddress().equals("0x7685E62E679886494E3cdc3DE7103E026f815AF0")
+         *                             ||dappMemberEntity.getAddress().equals("0x6893bE8F4fb73595A13f32bA5e1d198Ab135516C"
+         */
+        if(address.equals("0x2bBAD0d2362a8dbdc655fBa5A0cd51d5379e38f7")){
+            return false;
+        }else if(address.equals("0xd5c13dc4372d1e02b93add9dcca901bef51168be")){
+            return false;
+        }else if(address.equals("0xe22bb5fB2e0F8ED9366785dADD33cA19355d037c")){
+            return false;
+        }else if(address.equals("0x7685E62E679886494E3cdc3DE7103E026f815AF0")){
+            return false;
+        }else if(address.equals("0x6893bE8F4fb73595A13f32bA5e1d198Ab135516C")){
+            return false;
+        }else{
+            return true;
+        }
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void mineToCoin(MineToCoinDto mineToCoinDto) {
@@ -846,13 +935,13 @@
         dappFundFlowDao.insert(memberFeeflow);
         //插入资产闪对手续费的流水
         DappFundFlowEntity dappFundFlowEntityFee = new DappFundFlowEntity(
-                1L,
+                295L,
                 feeCnt,
                 FundFlowEnum.WALLET_MINE_TO_COIN_FEE.getCode(),
                 2,
                 BigDecimal.ZERO);
         dappFundFlowDao.insert(dappFundFlowEntityFee);
-        this.updateWalletMineWithLock(feeCnt,1L,1);
+        this.updateWalletMineWithLock(feeCnt,295L,1);
     }
 
     @Override
@@ -1014,7 +1103,10 @@
                 coinCnt.negate(),
                 FundFlowEnum.ANDAO_MEMBER_TO_MENBER.getCode(),
                 2,
-                BigDecimal.ZERO);
+                BigDecimal.ZERO,
+                dappMemberEntity.getAddress(),
+                memberParent.getAddress(),
+                memberParent.getId());
         dappFundFlowDao.insert(aCoinCntFlow);
         //闪对钱包20% 手续费(扣币)
         DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
@@ -1033,7 +1125,10 @@
                 aCoinCntReal,
                 FundFlowEnum.ANDAO_MEMBER_TO_MENBER.getCode(),
                 2,
-                BigDecimal.ZERO);
+                BigDecimal.ZERO,
+                dappMemberEntity.getAddress(),
+                memberParent.getAddress(),
+                dappMemberEntity.getId());
         dappFundFlowDao.insert(dappFundFlowEntity);
 
         //金本位底池数量
@@ -1077,6 +1172,17 @@
             throw new FebsException("请输入正确的地址");
         }
 
+        /**
+         * 转ausdt,只能推广线上
+         */
+        String refererIdsDone = dappMemberEntity.getRefererIds();
+        String inviteIdDone = dappMemberEntity.getInviteId();
+        String refererIdsOther = memberParent.getRefererIds();
+        String inviteId1Other = memberParent.getInviteId();
+        if(!(StrUtil.contains(refererIdsOther,inviteIdDone) || StrUtil.contains(refererIdsDone,inviteId1Other))){
+            throw new FebsException("不满足互转规则");
+        }
+
         BigDecimal coinCnt = roundCoinDto.getCoinCnt();
         if(BigDecimal.ZERO.compareTo(coinCnt) >= 0){
             throw new FebsException("输入正确的数量");
@@ -1095,11 +1201,19 @@
                 coinCnt.negate(),
                 FundFlowEnum.AUSDT_MEMBER_TO_MENBER.getCode(),
                 2,
-                BigDecimal.ZERO);
+                BigDecimal.ZERO,
+                dappMemberEntity.getAddress(),
+                memberParent.getAddress(),
+                memberParent.getId());
         dappFundFlowDao.insert(aCoinCntFlow);
 
         DappUsdtPerkEntity parentEntity = dappUsdtPerkEntityMapper.selectByMemberId(memberParent.getId());
-        BigDecimal availableAmountParent = parentEntity.getAusdAmount();
+        if(ObjectUtil.isEmpty(parentEntity)){
+            parentEntity = new DappUsdtPerkEntity();
+            parentEntity.setMemberId(memberParent.getId());
+            dappUsdtPerkEntityMapper.insert(parentEntity);
+        }
+        BigDecimal availableAmountParent = ObjectUtil.isEmpty(parentEntity.getAusdAmount()) ? BigDecimal.ZERO : parentEntity.getAusdAmount();
         parentEntity.setAusdAmount(availableAmountParent.add(coinCnt));
         dappUsdtPerkEntityMapper.updateById(parentEntity);
         //插入资产闪对的流水
@@ -1108,7 +1222,10 @@
                 coinCnt,
                 FundFlowEnum.AUSDT_MEMBER_TO_MENBER.getCode(),
                 2,
-                BigDecimal.ZERO);
+                BigDecimal.ZERO,
+                dappMemberEntity.getAddress(),
+                memberParent.getAddress(),
+                dappMemberEntity.getId());
         dappFundFlowDao.insert(aCoinCntFlowParent);
     }
 }

--
Gitblit v1.9.1