zainali5120
2020-10-15 c923589da6a3b090efb9896e0568e8b40e260e50
src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java
@@ -1,6 +1,7 @@
package com.xcong.excoin.modules.member.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -28,7 +29,9 @@
import com.xcong.excoin.modules.member.mapper.MemberMapper;
import com.xcong.excoin.modules.member.mapper.MemberQuickBuySaleMapper;
import com.xcong.excoin.modules.member.mapper.MemberWalletCoinMapper;
import com.xcong.excoin.modules.member.service.EthService;
import com.xcong.excoin.modules.member.service.IMemberService;
import com.xcong.excoin.modules.member.service.RocService;
import com.xcong.excoin.modules.member.vo.MemberAuthenticationVo;
import com.xcong.excoin.modules.member.vo.MemberCoinChargeVo;
import com.xcong.excoin.modules.member.vo.MemberCoinWithdrawVo;
@@ -47,6 +50,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
@@ -450,13 +454,14 @@
   @Override
   @Transactional(rollbackFor = Exception.class)
   public FebsResponse memberWithdrawCoinConfirm(@NotNull(message = "{required}") Long id) {
   public FebsResponse memberWithdrawCoinConfirm(@NotNull(message = "{required}") Long id) throws ExecutionException, InterruptedException {
      
      MemberCoinWithdrawEntity selectById = memberCoinWithdrawMapper.selectById(id);
      Long memberId = selectById.getMemberId();
      String symbol = selectById.getSymbol();
      String address = selectById.getAddress();
      int status = selectById.getStatus();
      BigDecimal amount = selectById.getAmount();
      if(status != 1) {
         return new FebsResponse().fail().message("只有等待审核的状态才能确认!");
      }
@@ -483,8 +488,8 @@
         Long aimMemberId = selectByMap.get(0).getMemberId();
         MemberWalletCoinEntity aimWalletCoin = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(aimMemberId, symbol);
         
         BigDecimal addTotal = aimWalletCoin.getTotalBalance().add(selectById.getAmount());
         BigDecimal addAvailable = aimWalletCoin.getAvailableBalance().add(selectById.getAmount());
         BigDecimal addTotal = aimWalletCoin.getTotalBalance().add(amount.subtract(selectById.getFeeAmount()));
         BigDecimal addAvailable = aimWalletCoin.getAvailableBalance().add(amount.subtract(selectById.getFeeAmount()));
         aimWalletCoin.setTotalBalance(addTotal);
         aimWalletCoin.setAvailableBalance(addAvailable);
         
@@ -493,7 +498,7 @@
         MemberAccountMoneyChangeEntity memberAccountMoneyChangeEntity = new MemberAccountMoneyChangeEntity();
         memberAccountMoneyChangeEntity.setContent("收款");
         memberAccountMoneyChangeEntity.setMemberId(aimMemberId);
         memberAccountMoneyChangeEntity.setAmount(selectById.getAmount());
         memberAccountMoneyChangeEntity.setAmount(amount.subtract(selectById.getFeeAmount()));
         memberAccountMoneyChangeEntity.setStatus(MemberAccountMoneyChangeEntity.STATUS_SUCCESS_INTEGER);
         memberAccountMoneyChangeEntity.setSymbol(selectById.getSymbol());
         memberAccountMoneyChangeEntity.setType(MemberAccountMoneyChangeEntity.TYPE_WALLET_COIN);
@@ -525,6 +530,28 @@
      if(StrUtil.isNotBlank(phone)) {
         Sms106Send.sendWithdrawalCoinMsg(phone, time);
      }
      // 转币 需要扣除手续费
      amount = amount.subtract(selectById.getFeeAmount());
      if("ROC".equals(symbol) && !"Y".equals(selectById.getIsInside())){
         // 如果是ROC  则自动转
         String transfer = RocService.transfer(amount, address, "ROC");
      }else if("USDT".equals(symbol) && !"Y".equals(selectById.getIsInside())){
//         EthService ethService = new EthService();
//         // 查询余额是否足够
//         BigDecimal bigDecimal = ethService.tokenGetBalance(EthService.TOTAL_ADDRESS);
//         if(bigDecimal==null ||bigDecimal.compareTo(amount)<0 ){
//            FebsResponse fail = new FebsResponse().fail();
//            fail.message("总钱包余额不足");
//            return fail;
//         }
//         amount = amount.multiply(new BigDecimal("1000000"));
//         String usdtStr = amount.toPlainString();
//         if (usdtStr.contains(".")) {
//            usdtStr = usdtStr.substring(0, usdtStr.lastIndexOf("."));
//         }
//         String s = ethService.tokenSend(address, usdtStr, null);
      }
      /**
      //短信提醒
       SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
@@ -649,6 +676,10 @@
      String walletNum = memberMapper.selectBBZCForBasicRealData();
      String walletCoinNum = memberMapper.selectHYZCForBasicRealData();
      String agentNum = memberMapper.selectDLZCForBasicRealData();
      double allCoin = 0 ;
      allCoin = (walletNum == null ? 0 : Double.parseDouble(walletNum))
            +(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum))
            +(agentNum == null ? 0 : Double.parseDouble(agentNum));
      
      double platformProfitAndLoss = 0 ;
      platformProfitAndLoss = platformProfitAndLoss + (totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
@@ -673,6 +704,7 @@
         memberDataInfoVo.setWalletNum(walletNum == null ? "0" : walletNum);
         memberDataInfoVo.setWalletCoinNum(walletCoinNum == null ? "0" : walletCoinNum);
         memberDataInfoVo.setAgentNum(agentNum == null ? "0" : agentNum);
         memberDataInfoVo.setAllCoin(allCoin);
      }
      selectMemberListInPage.setTotal(1);
        return selectMemberListInPage;
@@ -902,6 +934,10 @@
      String walletNum = memberMapper.selectBBZCForBasicRealDataAlone();
      String walletCoinNum = memberMapper.selectHYZCForBasicRealDataAlone();
      String agentNum = memberMapper.selectDLZCForBasicRealDataAlone();
      double allCoin = 0 ;
      allCoin = (walletNum == null ? 0 : Double.parseDouble(walletNum))
            +(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum))
            +(agentNum == null ? 0 : Double.parseDouble(agentNum));
      
      double platformProfitAndLoss = 0 ;
      platformProfitAndLoss = platformProfitAndLoss + (totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
@@ -926,6 +962,7 @@
         memberDataInfoVo.setWalletNum(walletNum == null ? "0" : walletNum);
         memberDataInfoVo.setWalletCoinNum(walletCoinNum == null ? "0" : walletCoinNum);
         memberDataInfoVo.setAgentNum(agentNum == null ? "0" : agentNum);
         memberDataInfoVo.setAllCoin(allCoin);
      }
      selectMemberListInPage.setTotal(1);
        return selectMemberListInPage;
@@ -965,6 +1002,10 @@
      String walletNum = memberMapper.selectBBZCForBasicData();
      String walletCoinNum = memberMapper.selectHYZCForBasicData();
      String agentNum = memberMapper.selectDLZCForBasicData();
      double allCoin = 0 ;
      allCoin = (walletNum == null ? 0 : Double.parseDouble(walletNum))
            +(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum))
            +(agentNum == null ? 0 : Double.parseDouble(agentNum));
      
      double platformProfitAndLoss = 0 ;
      platformProfitAndLoss = platformProfitAndLoss + (totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
@@ -989,6 +1030,7 @@
         memberDataInfoVo.setWalletNum(walletNum == null ? "0" : walletNum);
         memberDataInfoVo.setWalletCoinNum(walletCoinNum == null ? "0" : walletCoinNum);
         memberDataInfoVo.setAgentNum(agentNum == null ? "0" : agentNum);
         memberDataInfoVo.setAllCoin(allCoin);
      }
      selectMemberListInPage.setTotal(1);
        return selectMemberListInPage;
@@ -1029,6 +1071,10 @@
      String walletNum = memberMapper.selectBBZCForBasicAllDataAlone();
      String walletCoinNum = memberMapper.selectHYZCForBasicAllDataAlone();
      String agentNum = memberMapper.selectDLZCForBasicAllDataAlone();
      double allCoin = 0 ;
      allCoin = (walletNum == null ? 0 : Double.parseDouble(walletNum))
            +(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum))
            +(agentNum == null ? 0 : Double.parseDouble(agentNum));
      
      double platformProfitAndLoss = 0 ;
      platformProfitAndLoss = platformProfitAndLoss + (totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
@@ -1053,6 +1099,7 @@
         memberDataInfoVo.setWalletNum(walletNum == null ? "0" : walletNum);
         memberDataInfoVo.setWalletCoinNum(walletCoinNum == null ? "0" : walletCoinNum);
         memberDataInfoVo.setAgentNum(agentNum == null ? "0" : agentNum);
         memberDataInfoVo.setAllCoin(allCoin);
      }
      selectMemberListInPage.setTotal(1);
        return selectMemberListInPage;
@@ -1155,6 +1202,7 @@
      //USDT充币总额+USDT提币总额
       String totalAmountUsdtB = memberMapper.selectTotalAmountUsdtBForBasicRealTestDataAlone();
       String totalAmountUsdtS = memberMapper.selectTotalAmountUsdtSForBasicRealTestDataAlone();
       //USDT充值总额+USDT提现总额
       String totalAmountUsdtCZ = memberMapper.selectTotalAmountUsdtCZForBasicRealTestDataAlone();
       String totalAmountUsdtTX = memberMapper.selectTotalAmountUsdtTXForBasicRealTestDataAlone();
@@ -1181,18 +1229,25 @@
      String walletNum = memberMapper.selectBBZCForBasicRealTestDataAlone();
      String walletCoinNum = memberMapper.selectHYZCForBasicRealTestDataAlone();
      String agentNum = memberMapper.selectDLZCForBasicRealTestDataAlone();
      double allCoin = 0 ;
      allCoin = (walletNum == null ? 0 : Double.parseDouble(walletNum))
            +(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum))
            +(agentNum == null ? 0 : Double.parseDouble(agentNum));
      
      double platformProfitAndLoss = 0 ;
      platformProfitAndLoss = platformProfitAndLoss + (totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
      platformProfitAndLoss = platformProfitAndLoss + (totalAmountUsdtCZ == null ? 0 : Double.parseDouble(totalAmountUsdtCZ));
      platformProfitAndLoss = platformProfitAndLoss - (totalAmountUsdtS == null ? 0 : Double.parseDouble(totalAmountUsdtS));
      platformProfitAndLoss = platformProfitAndLoss - (totalAmountUsdtS == null ? 0 : (Double.parseDouble(totalAmountUsdtS)-6780));
      platformProfitAndLoss = platformProfitAndLoss - (totalAmountUsdtTX == null ? 0 : Double.parseDouble(totalAmountUsdtTX));
      List<MemberDataInfoVo> records = selectMemberListInPage.getRecords();
      for(MemberDataInfoVo memberDataInfoVo : records) {
         memberDataInfoVo.setChargeUsdt(totalAmountUsdtCZ == null ? 0 : Double.parseDouble(totalAmountUsdtCZ));
         memberDataInfoVo.setAppealUsdt(totalAmountUsdtTX == null ? 0 : Double.parseDouble(totalAmountUsdtTX));
         memberDataInfoVo.setChargeCoin(totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
         memberDataInfoVo.setAppealCoin(totalAmountUsdtS == null ? 0 : Double.parseDouble(totalAmountUsdtS));
         memberDataInfoVo.setAppealCoin(totalAmountUsdtS == null ? 0 : (Double.parseDouble(totalAmountUsdtS)-6780));
         memberDataInfoVo.setClosingPrice(closingpriceByMid == null ? "0" : closingpriceByMid);
         memberDataInfoVo.setSellClosingPrice(sellClosingpriceByMid == null ? "0" : sellClosingpriceByMid);
         memberDataInfoVo.setFee(returnMoneyByMid == null ? "0" : returnMoneyByMid);
@@ -1205,6 +1260,7 @@
         memberDataInfoVo.setWalletNum(walletNum == null ? "0" : walletNum);
         memberDataInfoVo.setWalletCoinNum(walletCoinNum == null ? "0" : walletCoinNum);
         memberDataInfoVo.setAgentNum(agentNum == null ? "0" : agentNum);
         memberDataInfoVo.setAllCoin(allCoin);
      }
      selectMemberListInPage.setTotal(1);
        return selectMemberListInPage;
@@ -1245,18 +1301,22 @@
      String walletNum = memberMapper.selectBBZCForBasicRealTestAllDataAlone();
      String walletCoinNum = memberMapper.selectHYZCForBasicRealTestAllDataAlone();
      String agentNum = memberMapper.selectDLZCForBasicRealTestAllDataAlone();
      double allCoin = 0 ;
      allCoin = (walletNum == null ? 0 : Double.parseDouble(walletNum))
            +(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum))
            +(agentNum == null ? 0 : Double.parseDouble(agentNum));
      
      double platformProfitAndLoss = 0 ;
      platformProfitAndLoss = platformProfitAndLoss + (totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
      platformProfitAndLoss = platformProfitAndLoss + (totalAmountUsdtCZ == null ? 0 : Double.parseDouble(totalAmountUsdtCZ));
      platformProfitAndLoss = platformProfitAndLoss - (totalAmountUsdtS == null ? 0 : Double.parseDouble(totalAmountUsdtS));
      platformProfitAndLoss = platformProfitAndLoss - (totalAmountUsdtS == null ? 0 : (Double.parseDouble(totalAmountUsdtS)-6780));
      platformProfitAndLoss = platformProfitAndLoss - (totalAmountUsdtTX == null ? 0 : Double.parseDouble(totalAmountUsdtTX));
      List<MemberDataInfoVo> records = selectMemberListInPage.getRecords();
      for(MemberDataInfoVo memberDataInfoVo : records) {
         memberDataInfoVo.setChargeUsdt(totalAmountUsdtCZ == null ? 0 : Double.parseDouble(totalAmountUsdtCZ));
         memberDataInfoVo.setAppealUsdt(totalAmountUsdtTX == null ? 0 : Double.parseDouble(totalAmountUsdtTX));
         memberDataInfoVo.setChargeCoin(totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
         memberDataInfoVo.setAppealCoin(totalAmountUsdtS == null ? 0 : Double.parseDouble(totalAmountUsdtS));
         memberDataInfoVo.setAppealCoin(totalAmountUsdtS == null ? 0 : (Double.parseDouble(totalAmountUsdtS)-6780));
         memberDataInfoVo.setClosingPrice(closingpriceByMid == null ? "0" : closingpriceByMid);
         memberDataInfoVo.setSellClosingPrice(sellClosingpriceByMid == null ? "0" : sellClosingpriceByMid);
         memberDataInfoVo.setFee(returnMoneyByMid == null ? "0" : returnMoneyByMid);
@@ -1269,6 +1329,7 @@
         memberDataInfoVo.setWalletNum(walletNum == null ? "0" : walletNum);
         memberDataInfoVo.setWalletCoinNum(walletCoinNum == null ? "0" : walletCoinNum);
         memberDataInfoVo.setAgentNum(agentNum == null ? "0" : agentNum);
         memberDataInfoVo.setAllCoin(allCoin);
      }
      selectMemberListInPage.setTotal(1);
        return selectMemberListInPage;
@@ -1327,4 +1388,43 @@
      return memberInfoDetailVo;
   }
   @Override
   public IPage<MemberEntity> memberDataInfoListSearchs(MemberEntity member, QueryRequest request) {
        Page<MemberEntity> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<MemberEntity> selectMemberListInPage = this.baseMapper.selectDataInfoListSearchs(page, member);
        List<MemberEntity> records = selectMemberListInPage.getRecords();
        Set<MemberEntity> set = new HashSet<>();
        if(CollUtil.isNotEmpty(records)) {
           if(StrUtil.isNotBlank(member.getAccount())) {
              MemberEntity memberEntity = records.get(0);
              //当前查询下级关系
              String inviteId = memberEntity.getInviteId();
              List<MemberEntity> members = memberMapper.selectMemberDataInfoListSearchs(inviteId);
              if(CollUtil.isNotEmpty(members)) {
                 for(MemberEntity semberEntity : members) {
                    set.add(semberEntity);
                 }
              }
              //当前查询上级关系
              String refererIds = memberEntity.getRefererIds();
              String[] strs = refererIds.split(",");
              if(ObjectUtil.isNotEmpty(strs)) {
                 for(int i=0,len=strs.length;i<len;i++){
                    String string = strs[i].toString();
                    if(StrUtil.isNotEmpty(string)) {
                       MemberEntity mem = memberMapper.selectMemberByInviteId(string);
                       set.add(mem);
                    }
                 }
              }
           }
           if(set.size() > 0) {
              records.addAll(set);
           }
        }
        return selectMemberListInPage;
   }
}