xiaoyong931011
2022-10-31 a9f4c56ae7529a1f543aa1494daa55dbc5acd1d5
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -28,7 +28,9 @@
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -65,6 +67,8 @@
    private final DappNftActivationDao dappNftActivationDao;
    private final DappMemberService dappMemberService;
    private final MemberCoinWithdrawDao memberCoinWithdrawDao;
    private final IgtOnHookPlanOrderItemDao igtOnHookPlanOrderItemdao;
    private final DappBankDao dappBankDao;
    private final RedisTemplate<String, Object> redisTemplate;
@@ -563,15 +567,8 @@
            return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_006"));
        }
        //判断内部转账规则
        DataDictionaryCustom withdrawTimesDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WITHDRAW_TIMES.getType(), DataDictionaryEnum.WITHDRAW_TIMES.getCode());
//
//        DataDictionaryCustom outAccountProfitDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.OUT_ACCOUNT_PROFIT.getType(), DataDictionaryEnum.OUT_ACCOUNT_PROFIT.getCode());
//        //todo 获取用户的总收益
//        BigDecimal totalProfitOut = new BigDecimal("0.3");
//        BigDecimal outAccountProfit = outAccountProfitDic.getValue() == null ? new BigDecimal("0.3") : new BigDecimal(outAccountProfitDic.getValue());
//        if(outAccountProfit.compareTo(totalProfitOut) > 0){
//            return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_004"));
//        }
        DataDictionaryCustom accountRelationDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.ACCOUNT_RELATION.getType(), DataDictionaryEnum.ACCOUNT_RELATION.getCode());
        Integer accountRelation = Integer.parseInt(accountRelationDic.getValue());
        if(1 == accountRelation){
@@ -580,14 +577,36 @@
                return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_005"));
            }
        }
//        DataDictionaryCustom serviceFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SERVICE_FEE.getType(), DataDictionaryEnum.SERVICE_FEE.getCode());
//        Integer serviceFee = Integer.parseInt(serviceFeeDic.getValue());
        //查询转出会员
        //转出会员当前余额要大于等于划转金额
        DappWalletCoinEntity dappWalletCoinEntityOut = dappWalletCoinDao.selectByMemberId(memberIdOut);
        BigDecimal availableAmountOut = dappWalletCoinEntityOut.getAvailableAmount().setScale(4,BigDecimal.ROUND_DOWN);
        if(availableAmountOut.compareTo(balance) < 0){
            return new FebsResponse().fail().message(MessageSourceUtils.getString("balance_err_002"));
        }
        /**
         * 提取金额小于收益,则不受限制
         * 否则,计算收益占本金的比例。符合条件允许提现
         */
        //获取用户的总收益
        BigDecimal totalProfitOut = igtOnHookPlanOrderItemdao.selectTotalProfitByMemberIdAndStateAndIsgoal(memberIdOut,1,2);
        if(balance.compareTo(totalProfitOut) > 0){
            BigDecimal totalAmount = dappWalletCoinEntityOut.getTotalAmount();
            //用户总收益率
            BigDecimal divide = totalProfitOut.divide(totalAmount);
            //提现条件收益率
            DataDictionaryCustom outAccountProfitDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.OUT_ACCOUNT_PROFIT.getType(), DataDictionaryEnum.OUT_ACCOUNT_PROFIT.getCode());
            BigDecimal outAccountProfit = outAccountProfitDic.getValue() == null ? new BigDecimal("0.3") : new BigDecimal(outAccountProfitDic.getValue());
            if(divide.compareTo(outAccountProfit) < 0){
                return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_004"));
            }
        }
        //提现次数
        DataDictionaryCustom withdrawTimesDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WITHDRAW_TIMES.getType(), DataDictionaryEnum.WITHDRAW_TIMES.getCode());
        Integer withdrawTimes = Integer.parseInt(withdrawTimesDic.getValue());
        Integer withdrawTimesReal = memberCoinWithdrawDao.selectByMemberIdAndCreateTime(memberIdOut,DateUtil.format(DateUtil.date(),"yyyy-MM-dd"),"Y");
        if(withdrawTimesReal >= withdrawTimes){
            return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_0016"));
        }
        //转出账户,余额减少,冻结增加
        Integer countOut = dappWalletCoinDao.addFrozenAndDelAvailableById(dappWalletCoinEntityOut.getId(), balance);
@@ -662,14 +681,35 @@
        if(!aBoolean){
            return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_006"));
        }
        //提现条件收益率
        DataDictionaryCustom outAccountProfitDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.OUT_ACCOUNT_PROFIT.getType(), DataDictionaryEnum.OUT_ACCOUNT_PROFIT.getCode());
        //todo 获取用户的总收益
        BigDecimal totalProfitOut = new BigDecimal("0.3");
        BigDecimal outAccountProfit = outAccountProfitDic.getValue() == null ? new BigDecimal("0.3") : new BigDecimal(outAccountProfitDic.getValue());
        if(outAccountProfit.compareTo(totalProfitOut) > 0){
            return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_004"));
        /**
         * 提取金额小于收益,则不受限制
         * 否则,计算收益占本金的比例。符合条件允许提现
         */
        //获取用户的总收益
        BigDecimal totalProfit = igtOnHookPlanOrderItemdao.selectTotalProfitByMemberIdAndStateAndIsgoal(memberId,1,2);
        if(balance.compareTo(totalProfit) >= 0){
            BigDecimal totalAmount = dappWalletCoinEntity.getTotalAmount();
            //用户总收益率
            BigDecimal divide = totalProfit.divide(totalAmount);
            //提现条件收益率
            DataDictionaryCustom outAccountProfitDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.OUT_ACCOUNT_PROFIT.getType(), DataDictionaryEnum.OUT_ACCOUNT_PROFIT.getCode());
            BigDecimal outAccountProfit = outAccountProfitDic.getValue() == null ? new BigDecimal("0.3") : new BigDecimal(outAccountProfitDic.getValue());
            if(divide.compareTo(outAccountProfit) < 0){
                return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_004"));
            }
        }
        //(2)每24小时只能提现一次
        // 提现次数
        DataDictionaryCustom withdrawOutTimesDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.WITHDRAW_OUT_TIMES.getType()
                , DataDictionaryEnum.WITHDRAW_OUT_TIMES.getCode());
        String withdrawOutTimesStr = withdrawOutTimesDic.getValue() == null ? "1" : withdrawOutTimesDic.getValue();
        int withdrawOutTimes = Integer.parseInt(withdrawOutTimesStr);
        Integer withdrawTimesReal = memberCoinWithdrawDao.selectByMemberIdAndCreateTime(memberId,DateUtil.format(DateUtil.date(),"yyyy-MM-dd"),"N");
        if(withdrawOutTimes <= withdrawTimesReal){
            return new FebsResponse().fail().message(MessageSourceUtils.getString("member_err_0014"));
        }
        //余额减少冻结增加
        Integer count = dappWalletCoinDao.addFrozenAndDelAvailableById(memberId, balance);
        if(1 != count){
@@ -678,13 +718,14 @@
        DataDictionaryCustom serviceFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SERVICE_FEE.getType(), DataDictionaryEnum.SERVICE_FEE.getCode());
        BigDecimal serviceFee = new BigDecimal(serviceFeeDic.getValue());
        //转出账户生成一条内部转账记录
        //转出账户生成一条记录
        MemberCoinWithdrawEntity memberCoinWithdrawEntity = new MemberCoinWithdrawEntity();
        memberCoinWithdrawEntity.setAddress(address);
        memberCoinWithdrawEntity.setAmount(balance);
        memberCoinWithdrawEntity.setFeeAmount(serviceFee);
        if(1 == apiTransferOutsideDto.getType()){
            memberCoinWithdrawEntity.setTag("银行卡");
            DappBank dappBank = dappBankDao.selectBankListByMemberIdAndBankNo(memberId, address);
            memberCoinWithdrawEntity.setTag(dappBank.getMemberName()+"-银行卡");
            memberCoinWithdrawEntity.setSymbol("$");
        }else{
            memberCoinWithdrawEntity.setTag("钱包");
@@ -824,5 +865,303 @@
        return new FebsResponse().success().message(MessageSourceUtils.getString("Operation_001"));
    }
    @Override
    public BigDecimal updateLSYJYLFC(List<String> refererIdList,BigDecimal totalProfit) {
        //计算盈利分成
        BigDecimal profitSharingTotal = BigDecimal.ZERO;
        if(CollUtil.isNotEmpty(refererIdList)){
            String LEVEL_IB = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_IB.getCode());
            if(!DataDictionaryEnum.LEVEL_IB.getCode().equals(LEVEL_IB)){
                BigDecimal multiply = totalProfit.multiply(getProfitSharing(DataDictionaryEnum.LEVEL_IB.getCode()));
                DappMemberEntity dappMemberEntityLEVEL_IB = dappMemberDao.selectMemberInfoByInviteId(LEVEL_IB);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_IB.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_IB.getId(), multiply, "盈利分成", 8);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_FIB = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_FIB.getCode());
            if(!DataDictionaryEnum.LEVEL_FIB.getCode().equals(LEVEL_FIB)){
                BigDecimal multiply = BigDecimal.ZERO;
                if(!DataDictionaryEnum.LEVEL_IB.getCode().equals(LEVEL_IB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_FIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_IB.getCode()));
                }else{
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_FIB.getCode());
                }
                multiply = totalProfit.multiply(multiply);
                DappMemberEntity dappMemberEntityLEVEL_FIB = dappMemberDao.selectMemberInfoByInviteId(LEVEL_FIB);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_FIB.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_FIB.getId(), multiply, "盈利分成", 8);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_CIB = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_CIB.getCode());
            if(!DataDictionaryEnum.LEVEL_CIB.getCode().equals(LEVEL_CIB)){
                BigDecimal multiply = BigDecimal.ZERO;
                if(!DataDictionaryEnum.LEVEL_FIB.getCode().equals(LEVEL_FIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_CIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_FIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_IB.getCode().equals(LEVEL_IB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_CIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_IB.getCode()));
                }else{
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_CIB.getCode());
                }
                multiply = totalProfit.multiply(multiply);
                DappMemberEntity dappMemberEntityLEVEL_CIB = dappMemberDao.selectMemberInfoByInviteId(LEVEL_CIB);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_CIB.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_CIB.getId(), multiply, "盈利分成", 8);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_AIB = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_AIB.getCode());
            if(!DataDictionaryEnum.LEVEL_AIB.getCode().equals(LEVEL_AIB)){
                BigDecimal multiply = BigDecimal.ZERO;
                if(!DataDictionaryEnum.LEVEL_CIB.getCode().equals(LEVEL_CIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_AIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_CIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_FIB.getCode().equals(LEVEL_FIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_AIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_FIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_IB.getCode().equals(LEVEL_IB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_AIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_IB.getCode()));
                }else{
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_AIB.getCode());
                }
                multiply = totalProfit.multiply(multiply);
                DappMemberEntity dappMemberEntityLEVEL_AIB = dappMemberDao.selectMemberInfoByInviteId(LEVEL_AIB);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_AIB.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_AIB.getId(), multiply, "盈利分成", 8);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_GIB = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_GIB.getCode());
            if(!DataDictionaryEnum.LEVEL_GIB.getCode().equals(LEVEL_GIB)){
                BigDecimal multiply = BigDecimal.ZERO;
                if(!DataDictionaryEnum.LEVEL_AIB.getCode().equals(LEVEL_AIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_AIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_CIB.getCode().equals(LEVEL_CIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_CIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_FIB.getCode().equals(LEVEL_FIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_FIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_IB.getCode().equals(LEVEL_IB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GIB.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_IB.getCode()));
                }else{
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GIB.getCode());
                }
                multiply = totalProfit.multiply(multiply);
                DappMemberEntity dappMemberEntityLEVEL_GIB = dappMemberDao.selectMemberInfoByInviteId(LEVEL_GIB);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_GIB.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_GIB.getId(), multiply, "盈利分成", 8);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_BP = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_BP.getCode());
            if(!DataDictionaryEnum.LEVEL_BP.getCode().equals(LEVEL_BP)){
                BigDecimal multiply = BigDecimal.ZERO;
                if(!DataDictionaryEnum.LEVEL_GIB.getCode().equals(LEVEL_GIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_BP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_GIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_AIB.getCode().equals(LEVEL_AIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_BP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_AIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_CIB.getCode().equals(LEVEL_CIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_BP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_CIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_FIB.getCode().equals(LEVEL_FIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_BP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_FIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_IB.getCode().equals(LEVEL_IB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_BP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_IB.getCode()));
                }else{
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_BP.getCode());
                }
                multiply = totalProfit.multiply(multiply);
                DappMemberEntity dappMemberEntityLEVEL_BP = dappMemberDao.selectMemberInfoByInviteId(LEVEL_BP);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_BP.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_BP.getId(), multiply, "盈利分成", 8);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_SP = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_SP.getCode());
            if(!DataDictionaryEnum.LEVEL_SP.getCode().equals(LEVEL_SP)){
                BigDecimal multiply = BigDecimal.ZERO;
                if(!DataDictionaryEnum.LEVEL_BP.getCode().equals(LEVEL_BP)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_SP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_BP.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_GIB.getCode().equals(LEVEL_GIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_SP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_GIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_AIB.getCode().equals(LEVEL_AIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_SP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_AIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_CIB.getCode().equals(LEVEL_CIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_SP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_CIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_FIB.getCode().equals(LEVEL_FIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_SP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_FIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_IB.getCode().equals(LEVEL_IB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_SP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_IB.getCode()));
                }else{
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_SP.getCode());
                }
                multiply = totalProfit.multiply(multiply);
                DappMemberEntity dappMemberEntityLEVEL_SP = dappMemberDao.selectMemberInfoByInviteId(LEVEL_SP);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_SP.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_SP.getId(), multiply, "盈利分成", 8);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_GP = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_GP.getCode());
            if(!DataDictionaryEnum.LEVEL_GP.getCode().equals(LEVEL_GP)){
                BigDecimal multiply = BigDecimal.ZERO;
                if(!DataDictionaryEnum.LEVEL_SP.getCode().equals(LEVEL_SP)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_SP.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_BP.getCode().equals(LEVEL_BP)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_BP.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_GIB.getCode().equals(LEVEL_GIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_GIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_AIB.getCode().equals(LEVEL_AIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_AIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_CIB.getCode().equals(LEVEL_CIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_CIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_FIB.getCode().equals(LEVEL_FIB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_FIB.getCode()));
                }else if(!DataDictionaryEnum.LEVEL_IB.getCode().equals(LEVEL_IB)){
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GP.getCode()).subtract(getProfitSharing(DataDictionaryEnum.LEVEL_IB.getCode()));
                }else{
                    multiply = getProfitSharing(DataDictionaryEnum.LEVEL_GP.getCode());
                }
                multiply = totalProfit.multiply(multiply);
                DappMemberEntity dappMemberEntityLEVEL_GP = dappMemberDao.selectMemberInfoByInviteId(LEVEL_GP);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_GP.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_GP.getId(), multiply, "盈利分成", 8);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
        }
        //计算流水佣金
        if(CollUtil.isNotEmpty(refererIdList)){
            String LEVEL_AIB = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_AIB.getCode());
            if(!DataDictionaryEnum.LEVEL_AIB.getCode().equals(LEVEL_AIB)){
                BigDecimal multiply = totalProfit.multiply(getRunningCommission(DataDictionaryEnum.LEVEL_AIB.getCode()));
                DappMemberEntity dappMemberEntityLEVEL_AIB = dappMemberDao.selectMemberInfoByInviteId(LEVEL_AIB);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_AIB.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_AIB.getId(), multiply, "流水佣金", 7);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_GIB = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_GIB.getCode());
            if(!DataDictionaryEnum.LEVEL_GIB.getCode().equals(LEVEL_GIB)){
                BigDecimal multiply = totalProfit.multiply(getRunningCommission(DataDictionaryEnum.LEVEL_GIB.getCode()));
                DappMemberEntity dappMemberEntityLEVEL_GIB = dappMemberDao.selectMemberInfoByInviteId(LEVEL_GIB);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_GIB.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_GIB.getId(), multiply, "流水佣金", 7);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_BP = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_BP.getCode());
            if(!DataDictionaryEnum.LEVEL_BP.getCode().equals(LEVEL_BP)){
                BigDecimal multiply = totalProfit.multiply(getRunningCommission(DataDictionaryEnum.LEVEL_BP.getCode()));
                DappMemberEntity dappMemberEntityLEVEL_BP = dappMemberDao.selectMemberInfoByInviteId(LEVEL_BP);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_BP.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_BP.getId(), multiply, "流水佣金", 7);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_SP = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_SP.getCode());
            if(!DataDictionaryEnum.LEVEL_SP.getCode().equals(LEVEL_SP)){
                BigDecimal multiply = totalProfit.multiply(getRunningCommission(DataDictionaryEnum.LEVEL_SP.getCode()));
                DappMemberEntity dappMemberEntityLEVEL_SP = dappMemberDao.selectMemberInfoByInviteId(LEVEL_SP);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_SP.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_SP.getId(), multiply, "流水佣金", 7);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
            String LEVEL_GP = isIdentity(refererIdList, DataDictionaryEnum.LEVEL_GP.getCode());
            if(!DataDictionaryEnum.LEVEL_GP.getCode().equals(LEVEL_GP)){
                BigDecimal multiply = totalProfit.multiply(getRunningCommission(DataDictionaryEnum.LEVEL_GP.getCode()));
                DappMemberEntity dappMemberEntityLEVEL_GP = dappMemberDao.selectMemberInfoByInviteId(LEVEL_GP);
                dappWalletCoinDao.addTotalAndaddAvailableByMemberId(dappMemberEntityLEVEL_GP.getId(),multiply);
                DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                        dappMemberEntityLEVEL_GP.getId(), multiply, "流水佣金", 7);
                dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
                profitSharingTotal = profitSharingTotal.add(multiply);
            }
        }
        return profitSharingTotal;
    }
    @Override
    public BigDecimal updatePTFC(Long memberId, BigDecimal totalProfit) {
        BigDecimal multiply = totalProfit.multiply(new BigDecimal(0.05));
        DappAccountMoneyChangeEntity dappAccountMoneyChangeEntity = new DappAccountMoneyChangeEntity(
                memberId, multiply.negate(), "系统", 9);
        dappAccountMoneyChangeDao.insert(dappAccountMoneyChangeEntity);
        return multiply;
    }
    @Override
    public Integer isGoal(String num) {
        Set set = new HashSet();
        num = StrUtil.subSuf(num,1);
        char[] chars = num.toCharArray();
        for(char c:chars) {
            set.add(c);
        }
        if(set.size()==num.length()){
            return 1;
        }else{
            return 2;
        }
    }
    public static void main(String[] args) {
        String num = StrUtil.subSuf("01234",1);
        System.out.print(num);
    }
    private String isIdentity(List<String> refererIds,String levelCode){
        String flag = levelCode;
        for(String str : refererIds){
            DappMemberEntity dappMemberEntity = dappMemberDao.selectMemberInfoByInviteId(str);
            if(ObjectUtil.isNotEmpty(dappMemberEntity)){
                String identity = dappMemberEntity.getIdentity();
                if(levelCode.equals(identity)){
                    flag = str;
                    return flag;
                }
            }
        }
        return flag;
    }
    private BigDecimal getRunningCommission(String identity){
        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.LEVEL_MB.getType(), identity);
        String dataDictionaryCustomValue = dataDictionaryCustom.getValue();
        cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(dataDictionaryCustomValue);
        String runningCommission = jsonObject.get("runningCommission").toString();
        return new BigDecimal(runningCommission).multiply(new BigDecimal(0.01));
    }
    private BigDecimal getProfitSharing(String identity){
        DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.LEVEL_MB.getType(), identity);
        String dataDictionaryCustomValue = dataDictionaryCustom.getValue();
        cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(dataDictionaryCustomValue);
        String profitSharing = jsonObject.get("profitSharing").toString();
        return new BigDecimal(profitSharing).multiply(new BigDecimal(0.01));
    }
}