Helius
2020-11-03 231c4a3b97fff265545e88931d230b97290a9832
src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java
@@ -11,24 +11,8 @@
import com.xcong.excoin.common.entity.QueryRequest;
import com.xcong.excoin.modules.Sms106Send;
import com.xcong.excoin.modules.member.dto.MemberDetailConfirmDto;
import com.xcong.excoin.modules.member.entity.AgentFriendRelationEntity;
import com.xcong.excoin.modules.member.entity.MemberAccountMoneyChangeEntity;
import com.xcong.excoin.modules.member.entity.MemberAuthenticationEntity;
import com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity;
import com.xcong.excoin.modules.member.entity.MemberCoinChargeEntity;
import com.xcong.excoin.modules.member.entity.MemberCoinWithdrawEntity;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberQuickBuySaleEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.modules.member.mapper.AgentFriendRelationMapper;
import com.xcong.excoin.modules.member.mapper.MemberAccountMoneyChangeMapper;
import com.xcong.excoin.modules.member.mapper.MemberAuthenticationMapper;
import com.xcong.excoin.modules.member.mapper.MemberCoinAddressMapper;
import com.xcong.excoin.modules.member.mapper.MemberCoinChargeMapper;
import com.xcong.excoin.modules.member.mapper.MemberCoinWithdrawMapper;
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.entity.*;
import com.xcong.excoin.modules.member.mapper.*;
import com.xcong.excoin.modules.member.service.EthService;
import com.xcong.excoin.modules.member.service.IMemberService;
import com.xcong.excoin.modules.member.service.RocService;
@@ -85,6 +69,8 @@
   private final MemberAuthenticationMapper memberAuthenticationMapper;
   
   private final AgentFriendRelationMapper agentFriendRelationMapper;
   private final TdFinancialReordDao tdFinancialReordDao;
   
   @Override
   public IPage<AgentFriendRelationEntity> findAgentInfoListInPage(AgentFriendRelationEntity agentFriendRelationEntity,
@@ -447,6 +433,10 @@
            BigDecimal feeAmount = memberCoinWithdrawVo.getFeeAmount();
            BigDecimal subtract = amount.subtract(feeAmount);
            memberCoinWithdrawVo.setRealAmount(subtract);
            if("Y".equals(memberCoinWithdrawVo.getIsInside())){
               // 是内部转账 查询对应的地址
            }
         }
      }
        return findmemberQuickBuySaleListInPage;
@@ -467,9 +457,9 @@
      }
      // 转币 需要扣除手续费
      amount = amount.subtract(selectById.getFeeAmount());
      if("ROC".equals(symbol) && !"Y".equals(selectById.getIsInside())){
      if("RFNC".equals(symbol) && !"Y".equals(selectById.getIsInside())){
         // 如果是ROC  则自动转
         String transfer = RocService.transfer(amount, address, "ROC");
         String transfer = RocService.transfer(amount, address, "RFNC");
         if(!"success".equals(transfer)){
            FebsResponse febsResponse = new FebsResponse();
            return  febsResponse.fail().message(transfer);
@@ -486,36 +476,53 @@
      memberWalletCoinMapper.updateById(walletCoin);
      
      if ("Y".equals(selectById.getIsInside())) {
         Map<String, Object> columnMap = new HashMap<>();
         columnMap.put("symbol", symbol);
         columnMap.put("address", address);
         // 如果是内部转账 则需要将币加到内部地址
         List<MemberCoinAddressEntity> selectByMap = memberCoinAddressMapper.selectByMap(columnMap);
         if(selectByMap == null || selectByMap.isEmpty()) {
            return new FebsResponse().fail().message("地址有误,请拒绝!");
         // 查询算力系统中是否存在该地址
         TdCoinWallet tdCoinWallet = memberWalletCoinMapper.selectTdCoinWalletByAddress(address, "USDT");
         if (tdCoinWallet != null) {
            // 更新算力系统中用户钱包余额
            memberWalletCoinMapper.updateTdCoinWalletAvaliable(amount, address);
            TdFinancialReord tdFinancialReord = new TdFinancialReord();
            tdFinancialReord.setAmount(amount);
            tdFinancialReord.setCreateTime(new Date());
            tdFinancialReord.setMemId(tdCoinWallet.getMemId());
            tdFinancialReord.setSymbol("USDT");
            tdFinancialReord.setTitle("USDT交易所转账");
            tdFinancialReord.setContent("USDT交易所转账");
            // 插入算力系统中财务记录
            tdFinancialReordDao.insert(tdFinancialReord);
         } else {
            Map<String, Object> columnMap = new HashMap<>();
            columnMap.put("symbol", symbol);
            columnMap.put("address", address);
            // 如果是内部转账 则需要将币加到内部地址
            List<MemberCoinAddressEntity> selectByMap = memberCoinAddressMapper.selectByMap(columnMap);
            if (selectByMap == null || selectByMap.isEmpty()) {
               return new FebsResponse().fail().message("地址有误,请拒绝!");
            }
            Long aimMemberId = selectByMap.get(0).getMemberId();
            MemberWalletCoinEntity aimWalletCoin = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(aimMemberId, symbol);
            BigDecimal addTotal = aimWalletCoin.getTotalBalance().add(amount);
            BigDecimal addAvailable = aimWalletCoin.getAvailableBalance().add(amount);
            aimWalletCoin.setTotalBalance(addTotal);
            aimWalletCoin.setAvailableBalance(addAvailable);
            memberWalletCoinMapper.updateById(aimWalletCoin);
            MemberAccountMoneyChangeEntity memberAccountMoneyChangeEntity = new MemberAccountMoneyChangeEntity();
            memberAccountMoneyChangeEntity.setContent("收款");
            memberAccountMoneyChangeEntity.setMemberId(aimMemberId);
            memberAccountMoneyChangeEntity.setAmount(amount);
            memberAccountMoneyChangeEntity.setStatus(MemberAccountMoneyChangeEntity.STATUS_SUCCESS_INTEGER);
            memberAccountMoneyChangeEntity.setSymbol(selectById.getSymbol());
            memberAccountMoneyChangeEntity.setType(MemberAccountMoneyChangeEntity.TYPE_WALLET_COIN);
            memberAccountMoneyChangeEntity.setCreateBy(selectById.getCreateBy());
            memberAccountMoneyChangeEntity.setCreateTime(new Date());
            memberAccountMoneyChangeEntity.setUpdateBy(selectById.getCreateBy());
            memberAccountMoneyChangeEntity.setUpdateTime(new Date());
            memberAccountMoneyChangeMapper.insert(memberAccountMoneyChangeEntity);
         }
         Long aimMemberId = selectByMap.get(0).getMemberId();
         MemberWalletCoinEntity aimWalletCoin = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(aimMemberId, symbol);
         BigDecimal addTotal = aimWalletCoin.getTotalBalance().add(amount);
         BigDecimal addAvailable = aimWalletCoin.getAvailableBalance().add(amount);
         aimWalletCoin.setTotalBalance(addTotal);
         aimWalletCoin.setAvailableBalance(addAvailable);
         memberWalletCoinMapper.updateById(aimWalletCoin);
         MemberAccountMoneyChangeEntity memberAccountMoneyChangeEntity = new MemberAccountMoneyChangeEntity();
         memberAccountMoneyChangeEntity.setContent("收款");
         memberAccountMoneyChangeEntity.setMemberId(aimMemberId);
         memberAccountMoneyChangeEntity.setAmount(amount);
         memberAccountMoneyChangeEntity.setStatus(MemberAccountMoneyChangeEntity.STATUS_SUCCESS_INTEGER);
         memberAccountMoneyChangeEntity.setSymbol(selectById.getSymbol());
         memberAccountMoneyChangeEntity.setType(MemberAccountMoneyChangeEntity.TYPE_WALLET_COIN);
         memberAccountMoneyChangeEntity.setCreateBy(selectById.getCreateBy());
           memberAccountMoneyChangeEntity.setCreateTime(new Date());
           memberAccountMoneyChangeEntity.setUpdateBy(selectById.getCreateBy());
           memberAccountMoneyChangeEntity.setUpdateTime(new Date());
         memberAccountMoneyChangeMapper.insert(memberAccountMoneyChangeEntity);
      }
      
      Map<String, Object> columnMaps = new HashMap<>();
@@ -733,38 +740,38 @@
   @Override
   public FebsResponse addCoinConfirm(@Valid MemberEntity memberEntity) {
      
      Long memberId = memberEntity.getId();
      String walletCode = "USDT";
      BigDecimal amountUsdt = memberEntity.getCoinNumber();
      MemberEntity selectById = this.baseMapper.selectById(memberId);
      if(ObjectUtils.isEmpty(selectById)) {
         return new FebsResponse().message("用户已不存在");
      }
      //获取币币钱包
      MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(memberId,walletCode);
      BigDecimal availableBalance = memberWalletCoinEntity.getAvailableBalance();
      BigDecimal totalBalance = memberWalletCoinEntity.getTotalBalance();
      memberWalletCoinEntity.setAvailableBalance(availableBalance.add(amountUsdt));
      memberWalletCoinEntity.setTotalBalance(totalBalance.add(amountUsdt));
      // 更新
      memberWalletCoinMapper.updateById(memberWalletCoinEntity);
       //添加币币资金划转历史记录
      MemberAccountMoneyChangeEntity memberAccountMoneyChangeEntity = new MemberAccountMoneyChangeEntity();
        memberAccountMoneyChangeEntity.setContent("充值");
        memberAccountMoneyChangeEntity.setMemberId(memberId);
        memberAccountMoneyChangeEntity.setAmount(amountUsdt);
        memberAccountMoneyChangeEntity.setStatus(MemberAccountMoneyChangeEntity.STATUS_SUCCESS_INTEGER);
        memberAccountMoneyChangeEntity.setSymbol("USDT");
        memberAccountMoneyChangeEntity.setType(MemberAccountMoneyChangeEntity.TYPE_WALLET_COIN);
        memberAccountMoneyChangeEntity.setCreateBy(selectById.getCreateBy());
        memberAccountMoneyChangeEntity.setCreateTime(new Date());
        memberAccountMoneyChangeEntity.setUpdateBy(selectById.getCreateBy());
        memberAccountMoneyChangeEntity.setUpdateTime(new Date());
        memberAccountMoneyChangeMapper.insert(memberAccountMoneyChangeEntity);
//      Long memberId = memberEntity.getId();
//      String walletCode = "USDT";
//      BigDecimal amountUsdt = memberEntity.getCoinNumber();
//
//      MemberEntity selectById = this.baseMapper.selectById(memberId);
//      if(ObjectUtils.isEmpty(selectById)) {
//         return new FebsResponse().message("用户已不存在");
//      }
//      //获取币币钱包
//      MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinMapper.findWalletCoinByMemberIdAndWalletCode(memberId,walletCode);
//      BigDecimal availableBalance = memberWalletCoinEntity.getAvailableBalance();
//      BigDecimal totalBalance = memberWalletCoinEntity.getTotalBalance();
//
//      memberWalletCoinEntity.setAvailableBalance(availableBalance.add(amountUsdt));
//      memberWalletCoinEntity.setTotalBalance(totalBalance.add(amountUsdt));
//      // 更新
//      memberWalletCoinMapper.updateById(memberWalletCoinEntity);
//
//       //添加币币资金划转历史记录
//      MemberAccountMoneyChangeEntity memberAccountMoneyChangeEntity = new MemberAccountMoneyChangeEntity();
//        memberAccountMoneyChangeEntity.setContent("充值");
//        memberAccountMoneyChangeEntity.setMemberId(memberId);
//        memberAccountMoneyChangeEntity.setAmount(amountUsdt);
//        memberAccountMoneyChangeEntity.setStatus(MemberAccountMoneyChangeEntity.STATUS_SUCCESS_INTEGER);
//        memberAccountMoneyChangeEntity.setSymbol("USDT");
//        memberAccountMoneyChangeEntity.setType(MemberAccountMoneyChangeEntity.TYPE_WALLET_COIN);
//        memberAccountMoneyChangeEntity.setCreateBy(selectById.getCreateBy());
//        memberAccountMoneyChangeEntity.setCreateTime(new Date());
//        memberAccountMoneyChangeEntity.setUpdateBy(selectById.getCreateBy());
//        memberAccountMoneyChangeEntity.setUpdateTime(new Date());
//
//        memberAccountMoneyChangeMapper.insert(memberAccountMoneyChangeEntity);
        /**
         * todo
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
@@ -786,47 +793,51 @@
      MemberInfoDetailVo memberInfoDetailVo = new MemberInfoDetailVo();
   
      //USDT充币总额+USDT提币总额
       String totalAmountUsdtB = memberMapper.selectTotalAmountUsdtBForBasicRealDataBymemberId(memberId);
       String totalAmountUsdtB = memberMapper.selectTotalAmountUsdtBForBasicRealDataBymemberId(memberId,"USDT");
       String totalAmountUsdtBRoc = memberMapper.selectTotalAmountUsdtBForBasicRealDataBymemberId(memberId,"ROC");
       memberInfoDetailVo.setChargeCoin(totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
       memberInfoDetailVo.setChargeCoinRoc(totalAmountUsdtBRoc == null ? 0 : Double.parseDouble(totalAmountUsdtBRoc));
       String totalAmountUsdtS = memberMapper.selectTotalAmountUsdtSForBasicRealDataBymemberId(memberId);
       memberInfoDetailVo.setAppealCoin(totalAmountUsdtS == null ? 0 : Double.parseDouble(totalAmountUsdtS));
       //USDT充值总额+USDT提现总额
       String totalAmountUsdtCZ = memberMapper.selectTotalAmountUsdtCZForBasicRealDataBymemberId(memberId);
       memberInfoDetailVo.setChargeUsdt(totalAmountUsdtCZ == null ? 0 : Double.parseDouble(totalAmountUsdtCZ));
       String totalAmountUsdtTX = memberMapper.selectTotalAmountUsdtTXForBasicRealDataBymemberId(memberId);
       memberInfoDetailVo.setAppealUsdt(totalAmountUsdtTX == null ? 0 : Double.parseDouble(totalAmountUsdtTX));
//       String totalAmountUsdtCZ = memberMapper.selectTotalAmountUsdtCZForBasicRealDataBymemberId(memberId);
//       memberInfoDetailVo.setChargeUsdt(totalAmountUsdtCZ == null ? 0 : Double.parseDouble(totalAmountUsdtCZ));
//       String totalAmountUsdtTX = memberMapper.selectTotalAmountUsdtTXForBasicRealDataBymemberId(memberId);
//       memberInfoDetailVo.setAppealUsdt(totalAmountUsdtTX == null ? 0 : Double.parseDouble(totalAmountUsdtTX));
       //总剩余
       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 - (totalAmountUsdtTX == null ? 0 : Double.parseDouble(totalAmountUsdtTX));
       memberInfoDetailVo.setTotalCoin(platformProfitAndLoss);
//       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 - (totalAmountUsdtTX == null ? 0 : Double.parseDouble(totalAmountUsdtTX));
//       memberInfoDetailVo.setTotalCoin(platformProfitAndLoss);
      //佣金
      String returnMoneyByMid = memberMapper.selectReturnMoneyForBasicRealDataBymemberId(memberId);
      memberInfoDetailVo.setFee(returnMoneyByMid == null ? 0 : Double.parseDouble(returnMoneyByMid));
//      String returnMoneyByMid = memberMapper.selectReturnMoneyForBasicRealDataBymemberId(memberId);
//      memberInfoDetailVo.setFee(returnMoneyByMid == null ? 0 : Double.parseDouble(returnMoneyByMid));
      //开仓手续费总额
      String closingpriceByMid = memberMapper.selectClosingpriceForBasicRealDataBymemberId(memberId);
      memberInfoDetailVo.setClosingPrice(closingpriceByMid == null ? 0 : Double.parseDouble(closingpriceByMid));
//      String closingpriceByMid = memberMapper.selectClosingpriceForBasicRealDataBymemberId(memberId);
//      memberInfoDetailVo.setClosingPrice(closingpriceByMid == null ? 0 : Double.parseDouble(closingpriceByMid));
      //平仓总手续费
      String sellClosingpriceByMid = memberMapper.selectSellClosingpriceForBasicRealDataBymemberId(memberId);
      memberInfoDetailVo.setSellClosingPrice(sellClosingpriceByMid == null ? 0 : Double.parseDouble(sellClosingpriceByMid));
//      String sellClosingpriceByMid = memberMapper.selectSellClosingpriceForBasicRealDataBymemberId(memberId);
//      memberInfoDetailVo.setSellClosingPrice(sellClosingpriceByMid == null ? 0 : Double.parseDouble(sellClosingpriceByMid));
      
      //总盈亏
      String rewardratioByMid = memberMapper.selectRewardratioForBasicRealDataBymemberId(memberId);
      memberInfoDetailVo.setPlatformProfitAndLoss(rewardratioByMid == null ? 0 : Double.parseDouble(rewardratioByMid));
//      //总盈亏
//      String rewardratioByMid = memberMapper.selectRewardratioForBasicRealDataBymemberId(memberId);
//      memberInfoDetailVo.setPlatformProfitAndLoss(rewardratioByMid == null ? 0 : Double.parseDouble(rewardratioByMid));
      
      //持仓手续费
      String doingPrice = memberMapper.selectprepriceForBasicRealDataBymemberId(memberId);
      memberInfoDetailVo.setDoingPrice(doingPrice == null ? 0 : Double.parseDouble(doingPrice));
//      String doingPrice = memberMapper.selectprepriceForBasicRealDataBymemberId(memberId);
//      memberInfoDetailVo.setDoingPrice(doingPrice == null ? 0 : Double.parseDouble(doingPrice));
      
      //账户金额
      String walletNum = memberMapper.selectBBZCForBasicRealDataBymemberId(memberId);
      String walletNum = memberMapper.selectBBZCForBasicRealDataBymemberId(memberId,"USDT");
      String walletNumRoc = memberMapper.selectBBZCForBasicRealDataBymemberId(memberId,"ROC");
      memberInfoDetailVo.setWalletCoinNum(walletNum == null ? 0 : Double.parseDouble(walletNum));
      String walletCoinNum = memberMapper.selectHYZCForBasicRealDataBymemberId(memberId);
      memberInfoDetailVo.setTotalContract(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum));
      String agentNum = memberMapper.selectDLZCForBasicRealDataBymemberId(memberId);
      memberInfoDetailVo.setAgentNum(agentNum == null ? 0 : Double.parseDouble(agentNum));
      memberInfoDetailVo.setWalletCoinNumRoc(walletNumRoc == null ? 0 : Double.parseDouble(walletNumRoc));
      //String walletCoinNum = memberMapper.selectHYZCForBasicRealDataBymemberId(memberId);
      //memberInfoDetailVo.setTotalContract(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum));
      //String agentNum = memberMapper.selectDLZCForBasicRealDataBymemberId(memberId);
      //memberInfoDetailVo.setAgentNum(agentNum == null ? 0 : Double.parseDouble(agentNum));
         
      return memberInfoDetailVo;
   }
@@ -1347,7 +1358,7 @@
      MemberInfoDetailVo memberInfoDetailVo = new MemberInfoDetailVo();
   
      //USDT充币总额+USDT提币总额
       String totalAmountUsdtB = memberMapper.selectTotalAmountUsdtBForBasicRealDataBymemberId(memberId);
       String totalAmountUsdtB = memberMapper.selectTotalAmountUsdtBForBasicRealDataBymemberId(memberId,"USDT");
       memberInfoDetailVo.setChargeCoin(totalAmountUsdtB == null ? 0 : Double.parseDouble(totalAmountUsdtB));
       String totalAmountUsdtS = memberMapper.selectTotalAmountUsdtSForBasicRealDataBymemberId(memberId);
       memberInfoDetailVo.setAppealCoin(totalAmountUsdtS == null ? 0 : Double.parseDouble(totalAmountUsdtS));
@@ -1382,7 +1393,7 @@
      memberInfoDetailVo.setDoingPrice(doingPrice == null ? 0 : Double.parseDouble(doingPrice));
      
      //账户金额
      String walletNum = memberMapper.selectBBZCForBasicRealDataBymemberId(memberId);
      String walletNum = memberMapper.selectBBZCForBasicRealDataBymemberId(memberId,"USDT");
      memberInfoDetailVo.setWalletCoinNum(walletNum == null ? 0 : Double.parseDouble(walletNum));
      String walletCoinNum = memberMapper.selectHYZCForBasicRealDataBymemberId(memberId);
      memberInfoDetailVo.setTotalContract(walletCoinNum == null ? 0 : Double.parseDouble(walletCoinNum));