| | |
| | | package cc.mrbird.febs.dapp.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.enumerates.DataDicEnum; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.chain.ContractChainService; |
| | | import cc.mrbird.febs.dapp.dto.SystemDto; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappMineDataEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappReturnRatioEntity; |
| | | import cc.mrbird.febs.dapp.mapper.DappReturnRatioDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappSystemDao; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.AsyncCjService; |
| | | import cc.mrbird.febs.dapp.service.DappSystemService; |
| | | import cc.mrbird.febs.dapp.utils.OnlineTransferUtil; |
| | | import cc.mrbird.febs.dapp.vo.RedisTransferPoolVo; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author |
| | |
| | | private final DappSystemDao dappSystemDao; |
| | | private final DappReturnRatioDao dappReturnRatioDao; |
| | | private final RedisUtils redisUtils; |
| | | private final DappFundFlowDao dappFundFlowDao; |
| | | private final DappMemberDao dappMemberDao; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final DappOnlineTransferDao dappOnlineTransferDao; |
| | | private final ChainProducer chainProducer; |
| | | private final DappAchieveMapper dappAchieveMapper; |
| | | private final DappAchieveItemMapper dappAchieveItemMapper; |
| | | private final DappHdRecordMapper dappHdRecordMapper; |
| | | private final AsyncCjService asyncCjService; |
| | | |
| | | private final String[] ADDRESS_PREFIX = {"T", "0x"}; |
| | | |
| | | @Override |
| | | public Map<String, Object> findTotalInComeAndList() { |
| | | DappMineDataEntity dataMine = dappSystemDao.selectMineDataForOne(); |
| | | |
| | | List<DappMemberEntity> addresses = dappMemberDao.selectList(null); |
| | | DappMemberEntity mineAddress = dappMemberDao.selectByAddress(ChainEnum.BSC_TFC.getAddress(), null); |
| | | BigDecimal coinCnt = dappMemberDao.selectAllBalance("normal"); |
| | | |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("total", 6000); |
| | | result.put("addreessCnt", 1234); |
| | | result.put("coinCnt", 4000); |
| | | result.put("total", mineAddress.getBalance()); |
| | | result.put("addreessCnt", addresses.size()); |
| | | result.put("coinCnt", coinCnt); |
| | | result.put("sourceTFC", ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(ChainEnum.BSC_TFC_SOURCE.getAddress())); |
| | | result.put("sourceUSDT", ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress())); |
| | | return result; |
| | | } |
| | | |
| | |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | |
| | | SystemDto system = new SystemDto(); |
| | | String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | | // 启动未启动 |
| | | if (!"start".equals(hasStart)) { |
| | | system.setFeeRatio(BigDecimal.TEN); |
| | | system.setUsdtRemain(BigDecimal.ZERO); |
| | | system.setUsdtTotal(BigDecimal.ZERO); |
| | | system.setSaleRemain(BigDecimal.ZERO); |
| | | system.setSaleTotal(BigDecimal.ZERO); |
| | | Object makePoolObj = redisUtils.get(AppContants.REDIS_KEY_MAKE_POOL_CNT); |
| | | BigDecimal balance; |
| | | if (makePoolObj == null) { |
| | | balance = ChainService.getInstance(ChainEnum.BSC_TFC_MAKE.name()).balanceOf(ChainEnum.BSC_TFC_MAKE.getAddress()); |
| | | redisUtils.set(AppContants.REDIS_KEY_MAKE_POOL_CNT, balance); |
| | | } else { |
| | | balance = (BigDecimal) makePoolObj; |
| | | } |
| | | system.setBuyRemain(balance); |
| | | system.setBuyTotal(balance); |
| | | |
| | | return system; |
| | | } |
| | | |
| | | RedisTransferPoolVo transferPool = (RedisTransferPoolVo) redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL); |
| | | BigDecimal poolRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN); |
| | |
| | | |
| | | ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | BigDecimal balance = instance.balanceOf(member.getAddress()); |
| | | Object o = redisUtils.get(AppContants.REDIS_KEY_COIN_REMAIN); |
| | | |
| | | BigDecimal coinTotal = balance.multiply(BigDecimal.valueOf(0.3)).setScale(instance.decimals(), RoundingMode.HALF_DOWN); |
| | | Object o = redisUtils.get(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress()); |
| | | |
| | | BigDecimal minLimit = new BigDecimal(50); |
| | | BigDecimal coinTotal; |
| | | if (balance.compareTo(minLimit) > 0) { |
| | | coinTotal = balance.multiply(BigDecimal.valueOf(0.3)).setScale(instance.decimals(), RoundingMode.HALF_DOWN); |
| | | } else { |
| | | coinTotal = new BigDecimal(50); |
| | | } |
| | | |
| | | BigDecimal remain; |
| | | if (o == null) { |
| | | DateTime tomorrow = DateUtil.beginOfDay(DateUtil.tomorrow()); |
| | | long time = DateUtil.between(new Date(), tomorrow, DateUnit.SECOND, true); |
| | | |
| | | remain = coinTotal; |
| | | redisUtils.set(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN, remain); |
| | | redisUtils.set(AppContants.REDIS_KEY_COIN_REMAIN + member.getAddress(), remain, time); |
| | | } else { |
| | | remain = (BigDecimal) o; |
| | | } |
| | |
| | | system.setFeeRatio(BigDecimal.TEN); |
| | | return system; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void tradeProfitDistribute(Long id) { |
| | | asyncCjService.tradeProfitDistribute(); |
| | | // /** |
| | | // * 获取滑点钱包的代币余额A和U余额B |
| | | // * 获取最新一条的记录C,然后A-C.A,B-C.B,获得这段时间内的滑点新增D |
| | | // * 用D来进行划定分配 |
| | | // * 并且生成一条新的记录dappHdRecord,用来下次分配参照 |
| | | // */ |
| | | // |
| | | // //当天实际当天滑点 |
| | | // |
| | | // BigDecimal gfaPrice = new BigDecimal( |
| | | // redisUtils.getString(DataDicEnum.GFA_PRICE.getValue()) |
| | | // ).setScale(2,BigDecimal.ROUND_DOWN); |
| | | // BigDecimal usdtAmount = new BigDecimal( |
| | | // redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_WALLET_USDT_AMOUNT.getValue()) |
| | | // ).setScale(2,BigDecimal.ROUND_DOWN); |
| | | // BigDecimal coinAmount = new BigDecimal( |
| | | // redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_WALLET_COIN_AMOUNT.getValue()) |
| | | // ).setScale(2,BigDecimal.ROUND_DOWN); |
| | | // if(BigDecimal.ZERO.compareTo(usdtAmount) > 0){ |
| | | // return; |
| | | // } |
| | | // if(BigDecimal.ZERO.compareTo(coinAmount) > 0){ |
| | | // return; |
| | | // } |
| | | // BigDecimal usdtAmountReal = usdtAmount; |
| | | // BigDecimal coinAmountReal = coinAmount; |
| | | // //生成一条记录 |
| | | // DappHdRecord dappHdRecordAdd = new DappHdRecord(); |
| | | // dappHdRecordAdd.setPrice(gfaPrice); |
| | | // dappHdRecordAdd.setUsdtEvery(usdtAmountReal); |
| | | // dappHdRecordAdd.setUsdtAmount(usdtAmountReal); |
| | | // dappHdRecordAdd.setCoinEvery(coinAmountReal); |
| | | // dappHdRecordAdd.setCoinAmount(coinAmountReal); |
| | | // dappHdRecordMapper.insert(dappHdRecordAdd); |
| | | // |
| | | // /** |
| | | // * 5%滑奖分配: |
| | | // * 1%用自身质押 |
| | | // * 3%用于团队业绩计算 |
| | | // * 1%用于布道者奖励 |
| | | // */ |
| | | // int selfPercent = Convert.toInt(redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_SELF.getValue())); |
| | | // int teamPercent = Convert.toInt(redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_TEAM.getValue())); |
| | | // int workPercent = Convert.toInt(redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_WORK.getValue())); |
| | | // //平分份数 |
| | | // BigDecimal totalPercent = new BigDecimal(selfPercent + teamPercent + workPercent); |
| | | // //每一份有多少 |
| | | // BigDecimal divideEveryUsdt = usdtAmountReal.divide(totalPercent, 2, BigDecimal.ROUND_DOWN); |
| | | // //每一份有多少 |
| | | // BigDecimal divideEveryCoin = coinAmountReal.divide(totalPercent, 2, BigDecimal.ROUND_DOWN); |
| | | // //1%用自身质押 |
| | | // selfHdPerk(selfPercent,divideEveryUsdt,divideEveryCoin); |
| | | // //3%用于团队业绩计算 |
| | | // teamHdPerk(teamPercent,divideEveryUsdt,divideEveryCoin); |
| | | } |
| | | |
| | | public void teamHdPerk(int teamPercent,BigDecimal divideEveryUsdt,BigDecimal divideEveryCoin){ |
| | | //3%用于团队业绩计算 |
| | | BigDecimal teamPercentMultiply = new BigDecimal(teamPercent); |
| | | BigDecimal multiplyDivideEveryUsdt = divideEveryUsdt.multiply(teamPercentMultiply); |
| | | BigDecimal multiplyDivideEveryCoin = divideEveryCoin.multiply(teamPercentMultiply); |
| | | |
| | | List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectList(null);//获取全部成员 |
| | | if(CollUtil.isEmpty(dappMemberEntities)){ |
| | | return; |
| | | } |
| | | //如果没有进行中的质押,直接返回 |
| | | QueryWrapper<DappAchieve> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("state",DappAchieve.STATUS_ING); |
| | | List<DappAchieve> dappAchieves = dappAchieveMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isEmpty(dappAchieves)){ |
| | | return; |
| | | } |
| | | //可以获取奖励的用户 |
| | | Map<Long, BigDecimal> memberPerkMap = new HashMap<>(); |
| | | //总团队业绩 |
| | | BigDecimal memberPerkTotal = BigDecimal.ZERO; |
| | | //获取全部会员 |
| | | Set<Long> allMembers = dappMemberEntities.stream().map(DappMemberEntity::getId).collect(Collectors.toSet()); |
| | | //获取正在质押的会员ID |
| | | Set<Long> achieveMembers = dappAchieves.stream().map(DappAchieve::getMemberId).collect(Collectors.toSet()); |
| | | Collection<Long> intersection = CollUtil.intersection(allMembers, achieveMembers); |
| | | for(Long memberId : intersection){ |
| | | /** |
| | | * 获取每一个成员的四级直推 |
| | | */ |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | String inviteId = dappMemberEntity.getInviteId(); |
| | | List<String> inviteIds = new ArrayList<>(); |
| | | inviteIds.add(inviteId); |
| | | //每一个账号的往下四级直推 |
| | | List<DappMemberEntity> downMembersList = new ArrayList<>(); |
| | | int teamLevel = Convert.toInt(redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_LEVEL.getValue())); |
| | | while(teamLevel >= 1){ |
| | | //获取直推用户 |
| | | List<DappMemberEntity> downMembers = dappMemberDao.selectChildMemberDirectOrNotInlist(inviteIds); |
| | | if(CollUtil.isEmpty(downMembers)){ |
| | | teamLevel = 0; |
| | | } |
| | | CollUtil.addAll(downMembersList,downMembers); |
| | | List<String> collect = downMembers.stream().map(DappMemberEntity::getInviteId).collect(Collectors.toList()); |
| | | inviteIds.clear(); |
| | | inviteIds.addAll(collect); |
| | | teamLevel = teamLevel -1; |
| | | } |
| | | if(CollUtil.isEmpty(downMembersList)){ |
| | | continue; |
| | | } |
| | | Set<Long> collect = downMembersList.stream().map(DappMemberEntity::getId).collect(Collectors.toSet()); |
| | | QueryWrapper<DappAchieve> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.in("member_id",collect); |
| | | queryWrapper.eq("state",DappAchieve.STATUS_ING); |
| | | List<DappAchieve> dappAchieveSumList = dappAchieveMapper.selectList(queryWrapper); |
| | | //个人团队总业绩 |
| | | BigDecimal teamAchieveMemberSum = dappAchieveSumList.stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if(BigDecimal.ZERO.compareTo(teamAchieveMemberSum) >= 0){ |
| | | continue; |
| | | } |
| | | memberPerkTotal = memberPerkTotal.add(teamAchieveMemberSum); |
| | | memberPerkMap.put(memberId,teamAchieveMemberSum); |
| | | } |
| | | |
| | | BigDecimal everyUsdt = multiplyDivideEveryUsdt.divide(memberPerkTotal,4,BigDecimal.ROUND_DOWN); |
| | | BigDecimal everyCoin = multiplyDivideEveryCoin.divide(memberPerkTotal,4,BigDecimal.ROUND_DOWN); |
| | | Set<Long> set = memberPerkMap.keySet(); // 得到所有key的集合 |
| | | for (Long memberId : set) { |
| | | //当前生效中的团队业绩 |
| | | BigDecimal amountMember = memberPerkMap.get(memberId); |
| | | //这个人实际可以分到的数量USDT |
| | | BigDecimal multiplyUsdt = amountMember.multiply(everyUsdt).setScale(2, BigDecimal.ROUND_DOWN); |
| | | //这个人实际可以分到的数量COIN |
| | | BigDecimal multiplyCoin = divideEveryCoin.multiply(everyCoin).setScale(2, BigDecimal.ROUND_DOWN); |
| | | |
| | | createFlow( |
| | | multiplyUsdt, |
| | | memberId, |
| | | FlowTypeEnum.HUA_DIAN_TUANDUI_USDT.getValue(), |
| | | FlowTypeEnum.HUA_DIAN_TUANDUI_USDT.getDescrition(), |
| | | 4, |
| | | 1, |
| | | ChainEnum.BSC_TFC_REWARD.name(), |
| | | DataDicEnum.USDT_COIN.getValue(), |
| | | 2); |
| | | createFlow( |
| | | multiplyCoin, |
| | | memberId, |
| | | FlowTypeEnum.HUA_DIAN_TUANDUI_DAIBI.getValue(), |
| | | FlowTypeEnum.HUA_DIAN_TUANDUI_DAIBI.getDescrition(), |
| | | 4, |
| | | 1, |
| | | ChainEnum.BSC_TFC_REWARD.name(), |
| | | DataDicEnum.USDT_COIN.getValue(), |
| | | 1); |
| | | |
| | | } |
| | | } |
| | | |
| | | public void selfHdPerk(int selfPercent,BigDecimal divideEveryUsdt,BigDecimal divideEveryCoin){ |
| | | QueryWrapper<DappAchieve> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("state",DappAchieve.STATUS_ING); |
| | | List<DappAchieve> dappAchieves = dappAchieveMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isEmpty(dappAchieves)){ |
| | | return; |
| | | } |
| | | BigDecimal selfPercentMultiply = new BigDecimal(selfPercent); |
| | | BigDecimal multiplyDivideEveryUsdt = divideEveryUsdt.multiply(selfPercentMultiply); |
| | | BigDecimal multiplyDivideEveryCoin = divideEveryCoin.multiply(selfPercentMultiply); |
| | | //当前生效中的质押总数 |
| | | BigDecimal amountMemberTotal = dappAchieves.stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal everyUsdt = multiplyDivideEveryUsdt.divide(amountMemberTotal,4,BigDecimal.ROUND_DOWN); |
| | | BigDecimal everyCoin = multiplyDivideEveryCoin.divide(amountMemberTotal,4,BigDecimal.ROUND_DOWN); |
| | | |
| | | Map<Long, List<DappAchieve>> collect = dappAchieves.stream().collect(Collectors.groupingBy(DappAchieve::getMemberId)); |
| | | Set<Long> set = collect.keySet(); // 得到所有key的集合 |
| | | for (Long memberId : set) { |
| | | //当前每个人生效中的质押总数 |
| | | BigDecimal amountMember = collect.get(memberId).stream().map(DappAchieve::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | //这个人实际可以分到的数量USDT |
| | | BigDecimal multiplyUsdt = amountMember.multiply(everyUsdt).setScale(2, BigDecimal.ROUND_DOWN); |
| | | //这个人实际可以分到的数量COIN |
| | | BigDecimal multiplyCoin = divideEveryCoin.multiply(everyCoin).setScale(2, BigDecimal.ROUND_DOWN); |
| | | |
| | | createFlow( |
| | | multiplyUsdt, |
| | | memberId, |
| | | FlowTypeEnum.HUA_DIAN_GEREN.getValue(), |
| | | FlowTypeEnum.HUA_DIAN_GEREN.getDescrition(), |
| | | 4, |
| | | 1, |
| | | ChainEnum.BSC_TFC_REWARD.name(), |
| | | DataDicEnum.USDT_COIN.getValue(), |
| | | 2); |
| | | createFlow( |
| | | multiplyCoin, |
| | | memberId, |
| | | FlowTypeEnum.HUA_DIAN_GEREN.getValue(), |
| | | FlowTypeEnum.HUA_DIAN_GEREN.getDescrition(), |
| | | 4, |
| | | 1, |
| | | ChainEnum.BSC_TFC_REWARD.name(), |
| | | DataDicEnum.GFA_COIN.getValue(), |
| | | 1); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 插入流水记录,增加转账记录,发送线上转账的消息 |
| | | * @param multiplyUsdt |
| | | * @param memberId |
| | | * @param type |
| | | * @param description |
| | | * @param typeTransfer |
| | | * @param targetType |
| | | * @param chainEnumName |
| | | * @param coinType |
| | | */ |
| | | public void createFlow(BigDecimal multiplyUsdt,Long memberId,Integer type,String description,Integer typeTransfer, |
| | | Integer targetType,String chainEnumName,String coinType,Integer typeadd){ |
| | | if (BigDecimal.ZERO.compareTo(multiplyUsdt) < 0) { |
| | | DappFundFlowEntity fundFlowTuiJian = new DappFundFlowEntity( |
| | | memberId, |
| | | multiplyUsdt, |
| | | type, |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | description); |
| | | dappFundFlowDao.insert(fundFlowTuiJian); |
| | | |
| | | Integer systemFlag = Integer.parseInt(redisUtils.getString(DataDicEnum.GFA_ZHUAN_ZHANG_KAI_GUAN.getValue())); |
| | | if (1 == systemFlag) { |
| | | //生成转账记录 |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if (ObjectUtil.isNotEmpty(dappMemberEntity)) { |
| | | OnlineTransferUtil.addTransfer( |
| | | dappMemberEntity.getAddress(), |
| | | multiplyUsdt, |
| | | typeTransfer,//挖矿 |
| | | targetType,//普通账户 |
| | | chainEnumName, |
| | | coinType, |
| | | fundFlowTuiJian.getId().toString()); |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", fundFlowTuiJian.getId().toString()); |
| | | map.put("type", AppContants.SYMBOL_FLOW_TYPE_BATCH); |
| | | //发送链上转账消息 |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | }else{ |
| | | asyncCjService.updateAmount(typeadd,memberId,multiplyUsdt); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void mining() { |
| | | ContractChainService contract = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | // 发行量 |
| | | BigInteger totalSupply = contract.totalSupply(); |
| | | |
| | | BigDecimal totalUnHold = contract.balanceOf(AppContants.DESTROY_ADDRESS); |
| | | List<DappMemberEntity> admin = dappMemberDao.selectMemberByAccountType("admin"); |
| | | for (DappMemberEntity member : admin) { |
| | | totalUnHold = totalUnHold.add(contract.balanceOf(member.getAddress())); |
| | | } |
| | | |
| | | Object transferPoolObj = redisUtils.get(AppContants.REDIS_KEY_MINE_TRANSFER_POOL_TRADE_CNT); |
| | | |
| | | // 全网持币量 |
| | | BigDecimal allInternet = new BigDecimal(totalSupply).subtract(totalUnHold); |
| | | // 中转池交易量 |
| | | BigDecimal transferPoll = (BigDecimal) transferPoolObj; |
| | | |
| | | List<DappMemberEntity> allMembers = dappMemberDao.selectList(null); |
| | | if (CollUtil.isEmpty(allMembers)) { |
| | | return; |
| | | } |
| | | DataDictionaryCustom miniHoldCoin = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MINI_HOLD_COIN_LIMIT); |
| | | |
| | | String batchNo = RandomUtil.randomString(32); |
| | | ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | for (DappMemberEntity member : allMembers) { |
| | | if ("admin".equals(member.getAccountType())) { |
| | | continue; |
| | | } |
| | | |
| | | BigDecimal balance = instance.balanceOf(member.getAddress()); |
| | | if (balance.compareTo(new BigDecimal(miniHoldCoin.getValue())) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | // 挖矿数量 |
| | | BigDecimal mine = transferPoll.multiply(balance.divide(allInternet, instance.decimals(), RoundingMode.HALF_UP)); |
| | | if (mine.compareTo(BigDecimal.ZERO) < 1) { |
| | | continue; |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), mine, 3, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | OnlineTransferUtil.addTransfer(member.getAddress(), mine, 3, 1, ChainEnum.BSC_TFC.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | member.setBalance(balance); |
| | | dappMemberDao.updateById(member); |
| | | } |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", batchNo); |
| | | map.put("type", AppContants.SYMBOL_FLOW_TYPE_BATCH); |
| | | |
| | | // 发送转账消息 |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | |
| | | @Override |
| | | public void onlineTransfer(String str) { |
| | | JSONObject jsonObject = JSONObject.parseObject(str); |
| | | String batchNo = jsonObject.getString("batchNo"); |
| | | List<DappOnlineTransferEntity> transferList = dappOnlineTransferDao.selectByBatchNo(batchNo); |
| | | |
| | | if (CollUtil.isEmpty(transferList)) { |
| | | return; |
| | | } |
| | | |
| | | for (DappOnlineTransferEntity transfer : transferList) { |
| | | if (transfer.getHasFinish() == 1) { |
| | | continue; |
| | | } |
| | | |
| | | String txHash = ChainService.getInstance(transfer.getFromType()).transfer(transfer.getAddress(), transfer.getAmount()); |
| | | int retryTime = 0;//重试次数 |
| | | while (StrUtil.isEmpty(txHash)) { |
| | | // 休眠2s |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if(retryTime < 3){ |
| | | txHash = ChainService.getInstance(transfer.getFromType()).transfer(transfer.getAddress(), transfer.getAmount()); |
| | | } |
| | | retryTime ++ ; |
| | | } |
| | | if(StrUtil.isEmpty(txHash)){ |
| | | return; |
| | | } |
| | | |
| | | transfer.setTxHash(txHash); |
| | | transfer.setHasFinish(1); |
| | | transfer.setUpdateTime(new Date()); |
| | | dappOnlineTransferDao.updateById(transfer); |
| | | |
| | | if (AppContants.SYMBOL_FLOW_TYPE_FLOW.equals(jsonObject.getString("type"))) { |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(Long.parseLong(batchNo)); |
| | | fundFlow.setToHash(txHash); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void userBuyReward(Long id) { |
| | | // 系统未启动不参与 |
| | | String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | | if (!"start".equals(hasStart)) { |
| | | return; |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id); |
| | | |
| | | DappMemberEntity member = dappMemberDao.selectById(fundFlow.getMemberId()); |
| | | DappMemberEntity referer = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | if (referer == null || "admin".equals(referer.getAccountType())) { |
| | | return; |
| | | } |
| | | |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_USER_BUY_REWARD); |
| | | BigDecimal prop = new BigDecimal(dic.getValue()).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP); |
| | | BigDecimal reward = fundFlow.getAmount().multiply(prop); |
| | | |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC_REWARD.name()).balanceOf(ChainEnum.BSC_TFC_REWARD.getAddress()); |
| | | if (balance.compareTo(reward) < 1) { |
| | | return; |
| | | } |
| | | |
| | | DappFundFlowEntity rewardFlow = new DappFundFlowEntity(referer.getId(), reward, 4, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(rewardFlow); |
| | | |
| | | OnlineTransferUtil.addTransfer(referer.getAddress(), reward, 4, 1, ChainEnum.BSC_TFC_REWARD.name(), AppContants.SYMBOL_COIN, rewardFlow.getId().toString()); |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", rewardFlow.getId().toString()); |
| | | map.put("type", "batch"); |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | |
| | | // @Autowired |
| | | // private SystemTradeJob systemTradeJob; |
| | | |
| | | @Override |
| | | public void startSystem() { |
| | | log.info("启动系统"); |
| | | |
| | | // Thread thread = new Thread(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // systemTradeJob.transferPoolVol(); |
| | | // systemTradeJob.sourcePoolUsdtOutLimit(); |
| | | // } |
| | | // }); |
| | | // |
| | | // thread.start(); |
| | | } |
| | | |
| | | @Override |
| | | public void getZhiYaDelayMsg(Long achieveId) { |
| | | DappAchieve dappAchieve = dappAchieveMapper.selectById(achieveId); |
| | | if(ObjectUtil.isEmpty(dappAchieve)){ |
| | | return; |
| | | } |
| | | if(DappAchieve.STATUS_DONE == dappAchieve.getState()){ |
| | | return; |
| | | } |
| | | Long memberId = dappAchieve.getMemberId(); |
| | | BigDecimal amountDone = dappAchieve.getAmountDone(); |
| | | BigDecimal amountDay = dappAchieve.getAmountDay(); |
| | | BigDecimal amountMax = dappAchieve.getAmountMax(); |
| | | |
| | | BigDecimal amountReal = BigDecimal.ZERO;//本次产出数量 |
| | | int flag = amountMax.compareTo(amountDone.add(amountDay)); |
| | | int state = DappAchieve.STATUS_ING;//判断质押任务是否继续 |
| | | if( flag > 0){ |
| | | amountReal = amountDay; |
| | | amountDone = amountDone.add(amountDay); |
| | | }else if (flag == 0){ |
| | | amountReal = amountDay; |
| | | amountDone = amountMax; |
| | | state = DappAchieve.STATUS_DONE; |
| | | }else{ |
| | | amountReal = amountMax.subtract(amountDone); |
| | | amountDone = amountMax; |
| | | state = DappAchieve.STATUS_DONE; |
| | | } |
| | | if(BigDecimal.ZERO.compareTo(amountReal) < 0){ |
| | | /** |
| | | * 更新主表记录 |
| | | * 插入一条子表记录 |
| | | * 插入一条流水记录 |
| | | * 发送链上转账记录 |
| | | */ |
| | | dappAchieve.setAmountDone(amountDone); |
| | | dappAchieve.setState(state); |
| | | dappAchieve.setUpdateTime(new Date()); |
| | | dappAchieveMapper.updateById(dappAchieve); |
| | | |
| | | DappAchieveItem dappAchieveItem = new DappAchieveItem(); |
| | | dappAchieveItem.setType(DappAchieveItem.TYPE_ZHI_YA); |
| | | dappAchieveItem.setState(DappAchieveItem.STATUS_AGREE); |
| | | dappAchieveItem.setAchieveId(achieveId); |
| | | dappAchieveItem.setMemberId(memberId); |
| | | dappAchieveItem.setAmount(amountReal); |
| | | dappAchieveItemMapper.insert(dappAchieveItem); |
| | | |
| | | DappFundFlowEntity fundFlowTuiJian = new DappFundFlowEntity( |
| | | memberId, |
| | | amountReal, |
| | | FlowTypeEnum.ZHIYA_CHA_CHU.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | FlowTypeEnum.ZHIYA_CHA_CHU.getDescrition()); |
| | | dappFundFlowDao.insert(fundFlowTuiJian); |
| | | |
| | | //生成转账记录 |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isNotEmpty(dappMemberEntity)){ |
| | | OnlineTransferUtil.addTransfer( |
| | | dappMemberEntity.getAddress(), |
| | | amountReal, |
| | | 3,//挖矿 |
| | | 1,//普通账户 |
| | | ChainEnum.BSC_TFC_REWARD.name(), |
| | | DataDicEnum.GFA_COIN.getValue(), |
| | | fundFlowTuiJian.getId().toString()); |
| | | } |
| | | Integer systemFlag = Integer.parseInt(redisUtils.getString(DataDicEnum.GFA_ZHUAN_ZHANG_KAI_GUAN.getValue())); |
| | | if(1 == systemFlag){ |
| | | //生成转账记录 |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", fundFlowTuiJian.getId().toString()); |
| | | map.put("type", AppContants.SYMBOL_FLOW_TYPE_FLOW); |
| | | //发送链上转账消息 |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | |
| | | //发送一个延时队列消息。24小时之后产生下一次的质押产出 |
| | | // chainProducer.sendZhiYaDelayMsg(dappAchieve.getId(), 24 * 60 * 60 * 1000L); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void getZhiYaDelayMsgFlow(Long flowId) { |
| | | |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(flowId); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | Integer type = dappFundFlowEntity.getType(); |
| | | if(FlowTypeEnum.ZHI_YA.getValue() != type){ |
| | | return; |
| | | } |
| | | Integer status = dappFundFlowEntity.getStatus(); |
| | | if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == status){ |
| | | return; |
| | | } |
| | | if(StrUtil.isNotEmpty(dappFundFlowEntity.getFromHash())){ |
| | | return; |
| | | } |
| | | dappFundFlowDao.deleteById(flowId); |
| | | } |
| | | } |