| | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.SpringContextUtil; |
| | | 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.contract.ContractMain; |
| | | import cc.mrbird.febs.dapp.dto.SystemDto; |
| | | import cc.mrbird.febs.dapp.dto.TransferDto; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.enumerate.CardPeriod; |
| | | import cc.mrbird.febs.dapp.enumerate.*; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | 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.dapp.vo.SlipSettingVo; |
| | | import cc.mrbird.febs.job.SystemTradeJob; |
| | | import cc.mrbird.febs.dapp.service.DappWalletService; |
| | | import cc.mrbird.febs.dapp.vo.AKLineLimitVo; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cc.mrbird.febs.tree.MatrixTree; |
| | | import cc.mrbird.febs.tree.MemberNode; |
| | | import cc.mrbird.febs.tree.TreeConstants; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUnit; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.core.date.Week; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.nodes.Element; |
| | | import org.jsoup.select.Elements; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.web3j.utils.Convert; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author |
| | |
| | | public class DappSystemServiceImpl implements DappSystemService { |
| | | |
| | | 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 DappSymbolDailyPriceMapper dappSymbolDailyPriceMapper; |
| | | private final DappMemberBoxRecordMapper dappMemberBoxRecordMapper; |
| | | private final DappWalletCoinDao dappWalletCoinDao; |
| | | |
| | | private final DappAchieveTreeDao dappAchieveTreeDao; |
| | | private final DappAchieveMemberTreeDao dappAchieveMemberTreeDao; |
| | | private final DappWalletService dappWalletService; |
| | | private final DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private final DappSystemProfitDao dappSystemProfitDao; |
| | | private final ChainProducer chainProducer; |
| | | private final ContractMain contractMain; |
| | | |
| | | private final DappMemberNodeMapper dappMemberNodeMapper; |
| | | private final DappChargeUsdtMapper dappChargeUsdtMapper; |
| | | private final DappUsdtPerkEntityMapper dappUsdtPerkEntityMapper; |
| | | private final DappWalletCoinDao dappWalletCoinDao; |
| | | private final DappWalletMineDao dappWalletMineDao; |
| | | private final DappAKlineMapper dappAKlineMapper; |
| | | |
| | | |
| | | @Override |
| | | public Map<String, Object> findTotalInComeAndList() { |
| | | 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", 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())); |
| | | result.put("cardCnt", 1000); |
| | | result.put("nftPrice", AppContants.NFT_ACTIVE_PRICE); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> globalSetting() { |
| | | BigDecimal newPrice = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_ETH_NEW_PRICE); |
| | | Integer changeFee = (Integer) redisUtils.get(AppContants.REDIS_KEY_CHANGE_FEE); |
| | | |
| | | List<DappReturnRatioEntity> ratios = dappReturnRatioDao.selectList(null); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("newPrice", newPrice); |
| | | result.put("changeFee", changeFee); |
| | | result.put("ratio", ratios); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public SystemDto system() { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | |
| | | SystemDto system = new SystemDto(); |
| | | String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | | // 启动未启动 |
| | | if (!"start".equals(hasStart)) { |
| | | system.setFeeRatio(new BigDecimal("7")); |
| | | system.setBuyFeeRatio(new BigDecimal("3")); |
| | | 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.name()).balanceOf(ChainEnum.BSC_TFC.getAddress()); |
| | | redisUtils.set(AppContants.REDIS_KEY_MAKE_POOL_CNT, balance); |
| | | } else { |
| | | balance = (BigDecimal) makePoolObj; |
| | | } |
| | | system.setBuyRemain(balance); |
| | | system.setBuyTotal(balance); |
| | | |
| | | |
| | | Object maxDailyBuy = redisUtils.get(AppContants.REDIS_KEY_IDO_USDT_MAX_BUY_DAILY + member.getAddress()); |
| | | if (maxDailyBuy == null) { |
| | | DateTime tomorrow = DateUtil.beginOfDay(DateUtil.tomorrow()); |
| | | long time = DateUtil.between(new Date(), tomorrow, DateUnit.SECOND, true); |
| | | |
| | | redisUtils.set(AppContants.REDIS_KEY_IDO_USDT_MAX_BUY_DAILY + member.getAddress(), new BigDecimal("1000"), time); |
| | | } |
| | | |
| | | 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); |
| | | // 买币数量 |
| | | system.setBuyTotal(transferPool.getTodayVol()); |
| | | system.setBuyRemain(poolRemain); |
| | | |
| | | ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | BigDecimal balance = instance.balanceOf(member.getAddress()); |
| | | |
| | | 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_COIN_REMAIN + member.getAddress(), remain, time); |
| | | } else { |
| | | remain = (BigDecimal) o; |
| | | } |
| | | // 卖币数量 |
| | | system.setSaleTotal(coinTotal); |
| | | system.setSaleRemain(remain); |
| | | |
| | | BigDecimal usdtRemain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN); |
| | | BigDecimal usdtTotal = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_USDT_OUT_LIMIT); |
| | | |
| | | // usdt数量 |
| | | system.setUsdtTotal(usdtTotal); |
| | | system.setUsdtRemain(usdtRemain); |
| | | |
| | | system.setFeeRatio(new BigDecimal("7")); |
| | | system.setBuyFeeRatio(new BigDecimal("3")); |
| | | system.setBuyAmount(new BigDecimal("100")); |
| | | return system; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void tradeProfitDistribute(Long id) { |
| | | DappFundFlowEntity fundflow = dappFundFlowDao.selectById(id); |
| | | String batchNo = RandomUtil.randomString(16) + id.toString(); |
| | | |
| | | BigDecimal fee = fundflow.getFee(); |
| | | DappMemberEntity member = dappMemberDao.selectById(fundflow.getMemberId()); |
| | | |
| | | List<DappMemberEntity> parents; |
| | | if (StrUtil.isBlank(member.getRefererId()) || "0".equals(member.getRefererId())) { |
| | | parents = new ArrayList<>(); |
| | | } else { |
| | | List<String> inviteIds = StrUtil.split(member.getRefererId(), ','); |
| | | parents = dappMemberDao.selectParentsList(inviteIds, 6); |
| | | ; |
| | | } |
| | | |
| | | DataDictionaryCustom miniHoldCoin = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MINI_HOLD_COIN_LIMIT); |
| | | DataDictionaryCustom slipPointSetting = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SLIP_POINT_SETTING, AppContants.DIC_TYPE_SLIP_POINT_SETTING); |
| | | SlipSettingVo slipSetting = JSONObject.parseObject(slipPointSetting.getValue(), SlipSettingVo.class); |
| | | |
| | | // 源池 |
| | | ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC_SOURCE.name()); |
| | | BigDecimal destroy = slipSetting.getDestroyPoint().divide(slipSetting.getAllPoint(), 2, RoundingMode.HALF_DOWN).multiply(fee); |
| | | log.info("销毁数量:{}, 比例:{}", destroy, slipSetting.getDestroyPoint()); |
| | | |
| | | // 销毁 |
| | | OnlineTransferUtil.addTransfer(AppContants.DESTROY_ADDRESS, destroy, fundflow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | // 总分发金额 |
| | | BigDecimal distrbAmount = fee.subtract(destroy); |
| | | // 技术金额 |
| | | BigDecimal techAmount = distrbAmount.multiply(slipSetting.getTechProp().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)); |
| | | // 节点金额 |
| | | BigDecimal nodeAmount = distrbAmount.subtract(techAmount); |
| | | log.info("总分发金额:{}, 技术:{}, 节点:{}", distrbAmount, techAmount, nodeAmount); |
| | | |
| | | if (CollUtil.isNotEmpty(parents)) { |
| | | int i = 1; |
| | | for (DappMemberEntity parent : parents) { |
| | | BigDecimal balance = instance.balanceOf(parent.getAddress()); |
| | | log.info("地址:{}, 余额:{}", parent.getAddress(), balance); |
| | | |
| | | // 若地址持币少了指定数量 |
| | | if (balance.compareTo(new BigDecimal(miniHoldCoin.getValue())) < 0) { |
| | | continue; |
| | | } |
| | | |
| | | DataDictionaryCustom distribDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_DISTRIBUTE_PROP, String.valueOf(i)); |
| | | if (distribDic == null) { |
| | | break; |
| | | } |
| | | |
| | | BigDecimal total = distrbAmount.multiply(new BigDecimal(distribDic.getValue()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)); |
| | | OnlineTransferUtil.addTransfer(parent.getAddress(), total, fundflow.getType(), 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | DappFundFlowEntity distribFlow = new DappFundFlowEntity(parent.getId(), total, 4, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(distribFlow); |
| | | |
| | | nodeAmount = nodeAmount.subtract(total); |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | // 铸池滑点金额 |
| | | BigDecimal makerAmount = distrbAmount.multiply(slipSetting.getMakeProp().divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP)); |
| | | log.info("铸池滑点金额:{}", makerAmount); |
| | | if (makerAmount.compareTo(BigDecimal.ZERO) > 0) { |
| | | List<DappMemberEntity> makerAddress = dappMemberDao.selectMakerAddress(); |
| | | if (CollUtil.isNotEmpty(makerAddress)) { |
| | | BigDecimal totalMaker = BigDecimal.ZERO; |
| | | Map<String, BigDecimal> map = new HashMap<>(); |
| | | Map<String, Long> addressAndId = new HashMap<>(); |
| | | for (DappMemberEntity maker : makerAddress) { |
| | | BigDecimal balance = instance.balanceOf(maker.getAddress()); |
| | | map.put(maker.getAddress(), balance); |
| | | addressAndId.put(maker.getAddress(), maker.getId()); |
| | | |
| | | totalMaker = totalMaker.add(balance); |
| | | } |
| | | |
| | | for (Map.Entry<String, BigDecimal> entry : map.entrySet()) { |
| | | BigDecimal target = makerAmount.multiply(entry.getValue().divide(totalMaker, 2, RoundingMode.HALF_UP)); |
| | | |
| | | OnlineTransferUtil.addTransfer(entry.getKey(), target, fundflow.getType(), 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | DappFundFlowEntity distribFlow = new DappFundFlowEntity(addressAndId.get(entry.getKey()), target, 4, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(distribFlow); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | // 若节点金额还有剩余,则进入技术金额 |
| | | techAmount = techAmount.add(nodeAmount); |
| | | OnlineTransferUtil.addTransfer(ChainEnum.BSC_TFC_TECH.getAddress(), techAmount, fundflow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("batchNo", batchNo); |
| | | map.put("type", "batch"); |
| | | |
| | | // 发送转账消息 |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | |
| | | @Override |
| | | public void tradeNftProfitDistribute(Long id) { |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id); |
| | | String batchNo = RandomUtil.randomString(16) + id.toString(); |
| | | |
| | | ContractChainService instance = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | BigDecimal preNFTAmount; |
| | | BigDecimal distribAmount = fundFlow.getFee(); |
| | | if (fundFlow.getType() == 1) { |
| | | preNFTAmount = distribAmount.divide(new BigDecimal("5000"), 2, RoundingMode.HALF_UP); |
| | | |
| | | } else if (fundFlow.getType() == 2) { |
| | | BigDecimal destroyAmount = fundFlow.getFee().multiply(new BigDecimal("2").divide(new BigDecimal("7"), instance.decimals(), RoundingMode.HALF_UP)); |
| | | // 销毁 |
| | | OnlineTransferUtil.addTransfer(AppContants.DESTROY_ADDRESS, destroyAmount, fundFlow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | distribAmount = fundFlow.getFee().subtract(destroyAmount); |
| | | |
| | | preNFTAmount = distribAmount.divide(new BigDecimal("5000"), 2, RoundingMode.HALF_UP); |
| | | |
| | | } else { |
| | | return; |
| | | } |
| | | |
| | | List<DappMemberEntity> allMembers = dappMemberDao.selectList(null); |
| | | if (CollUtil.isEmpty(allMembers)) { |
| | | return; |
| | | } |
| | | |
| | | BigDecimal total = BigDecimal.ZERO; |
| | | for (DappMemberEntity member : allMembers) { |
| | | BigDecimal balance = instance.balanceOf(member.getAddress()); |
| | | BigDecimal memberProfit = balance.multiply(preNFTAmount); |
| | | |
| | | // 返利 |
| | | OnlineTransferUtil.addTransfer(member.getAddress(), memberProfit, fundFlow.getType(), 1, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | |
| | | DappFundFlowEntity distribFlow = new DappFundFlowEntity(member.getId(), memberProfit, 4, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(distribFlow); |
| | | |
| | | total = total.add(memberProfit); |
| | | } |
| | | |
| | | BigDecimal remain = distribAmount.subtract(total); |
| | | // 剩余的 |
| | | OnlineTransferUtil.addTransfer(ChainEnum.BSC_TFC_TECH.getAddress(), remain, fundFlow.getType(), 3, ChainEnum.BSC_TFC_SOURCE.name(), AppContants.SYMBOL_COIN, batchNo); |
| | | } |
| | | |
| | | // public static void main(String[] args) throws IOException { |
| | | // Document parse = Jsoup.parse(new URL("https://bscscan.com/token/generic-tokenholders2?a=0x03c7d3f141c5f03971604958170e253362e13be6"), 10000000); |
| | | // |
| | | // Elements tbodys = parse.getElementsByTag("tbody"); |
| | | // |
| | | // Element tbody = tbodys.get(0); |
| | | // |
| | | // Elements elements = tbody.getElementsMatchingOwnText("^0x.*$"); |
| | | // |
| | | // String text = elements.get(0).text(); |
| | | // System.out.println(1111); |
| | | // } |
| | | |
| | | @Override |
| | | public void mining() { |
| | | ContractChainService contract = ChainService.getInstance(ChainEnum.BSC_TFC.name()); |
| | | // 发行量 |
| | | BigInteger totalSupply = contract.totalSupply(); |
| | | |
| | | if (!systemHasStart()) { |
| | | return; |
| | | } |
| | | |
| | | 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; |
| | | |
| | | // 判断今日价格比前一日价格是否跌了,若是,则今天挖矿减半 |
| | | BigDecimal downReduce = BigDecimal.ONE; |
| | | if (symbolPriceUpOrDown()) { |
| | | downReduce = new BigDecimal("0.5"); |
| | | } |
| | | |
| | | BigDecimal totalMineCnt = transferPoll.multiply(new BigDecimal("0.2")).multiply(downReduce); |
| | | |
| | | 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 = totalMineCnt.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", "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()); |
| | | while (StrUtil.isEmpty(txHash)) { |
| | | // 休眠2s |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | txHash = ChainService.getInstance(transfer.getFromType()).transfer(transfer.getAddress(), transfer.getAmount()); |
| | | } |
| | | |
| | | transfer.setTxHash(txHash); |
| | | transfer.setHasFinish(1); |
| | | transfer.setUpdateTime(new Date()); |
| | | dappOnlineTransferDao.updateById(transfer); |
| | | |
| | | if ("flow".equals(jsonObject.getString("type"))) { |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(Long.parseLong(batchNo)); |
| | | fundFlow.setToHash(txHash); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | } |
| | | } |
| | | |
| | | // 判断系统是否启动,如满足条件则启动系统 |
| | | // String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | | // if (!"start".equals(hasStart)) { |
| | | // DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_SYSTEM_START_TARGET); |
| | | // BigDecimal target = new BigDecimal(dic.getValue()); |
| | | // |
| | | // // 若源池中的USDT达到或超过8万U,则启动整个系统 |
| | | // BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_USDT_SOURCE.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress()); |
| | | // if (target.compareTo(balance) < 1) { |
| | | // redisUtils.set(AppContants.SYSTEM_START_FLAG, "start"); |
| | | // |
| | | // // 启动系统 |
| | | // startSystem(); |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | @Override |
| | | public void userBuyReward(Long id) { |
| | | // 系统未启动不参与 |
| | | if (!systemHasStart()) { |
| | | 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; |
| | | } |
| | | |
| | | if (!hasProfit(referer.getAddress())) { |
| | | 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)); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void startSystem() { |
| | | log.info("启动系统"); |
| | | |
| | | Thread thread = new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | transferPoolSetting(); |
| | | sourcePoolUsdtOutLimitSetting(); |
| | | } |
| | | }); |
| | | |
| | | thread.start(); |
| | | } |
| | | |
| | | // 最低容量(百分比) |
| | | private final BigDecimal volProp = new BigDecimal("2"); |
| | | // 每日增/减百分比 |
| | | private final BigDecimal changeProp = new BigDecimal("1"); |
| | | |
| | | @Override |
| | | public void transferPoolSetting() { |
| | | String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | | if (!"start".equals(hasStart)) { |
| | | log.info("系统未启动"); |
| | | return; |
| | | } |
| | | |
| | | // 源池初始化容量 |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_SYSTEM_SOURCE_POOL_VOL); |
| | | BigDecimal basicVol = new BigDecimal(dic.getValue()); |
| | | |
| | | Object o = redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL); |
| | | if (o == null) { |
| | | RedisTransferPoolVo transferPool = new RedisTransferPoolVo(); |
| | | BigDecimal total = basicVol.multiply(volProp.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP)); |
| | | transferPool.setTodayVol(total); |
| | | transferPool.setTodayProp(volProp); |
| | | transferPool.setFinishCnt(0); |
| | | transferPool.setUnFinishCnt(0); |
| | | redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL, transferPool); |
| | | redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, total); |
| | | |
| | | redisUtils.set(AppContants.REDIS_KEY_MINE_TRANSFER_POOL_TRADE_CNT, BigDecimal.ZERO); |
| | | return; |
| | | } |
| | | |
| | | RedisTransferPoolVo transferPool = (RedisTransferPoolVo) o; |
| | | BigDecimal remain = (BigDecimal) redisUtils.get(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN); |
| | | |
| | | // 设置当日成交量 |
| | | redisUtils.set(AppContants.REDIS_KEY_MINE_TRANSFER_POOL_TRADE_CNT, transferPool.getTodayVol().subtract(remain)); |
| | | |
| | | // 全卖了 |
| | | if (remain.compareTo(BigDecimal.ZERO) == 0) { |
| | | int finishCnt = transferPool.getFinishCnt() + 1; |
| | | BigDecimal targetProp = transferPool.getTodayProp(); |
| | | if (finishCnt == 1) { |
| | | targetProp = transferPool.getTodayVol().add(changeProp); |
| | | transferPool.setTodayProp(targetProp); |
| | | transferPool.setFinishCnt(0); |
| | | } else { |
| | | transferPool.setFinishCnt(finishCnt); |
| | | } |
| | | |
| | | BigDecimal total = basicVol.multiply(targetProp.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP)); |
| | | transferPool.setTodayVol(total); |
| | | transferPool.setUnFinishCnt(0); |
| | | redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, total); |
| | | |
| | | } else { |
| | | int unFinishCnt = transferPool.getUnFinishCnt() + 1; |
| | | BigDecimal targetProp = transferPool.getTodayProp(); |
| | | if (unFinishCnt >= 1) { |
| | | targetProp = transferPool.getTodayProp().compareTo(volProp) == 0 ? volProp : transferPool.getTodayProp().subtract(changeProp); |
| | | transferPool.setTodayProp(targetProp); |
| | | transferPool.setUnFinishCnt(0); |
| | | } else { |
| | | transferPool.setUnFinishCnt(unFinishCnt); |
| | | } |
| | | BigDecimal aa = targetProp.divide(BigDecimal.valueOf(100), 4, RoundingMode.HALF_UP); |
| | | BigDecimal total = basicVol.multiply(aa); |
| | | transferPool.setTodayVol(total); |
| | | redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL_REMAIN, total); |
| | | } |
| | | |
| | | redisUtils.set(AppContants.REDIS_KEY_TRANSFER_POOL_VOL, transferPool); |
| | | } |
| | | |
| | | @Override |
| | | public void sourcePoolUsdtOutLimitSetting() { |
| | | String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | | if (!"start".equals(hasStart)) { |
| | | log.info("系统未启动"); |
| | | return; |
| | | } |
| | | BigDecimal sourceBalance = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress()); |
| | | |
| | | BigDecimal total = sourceBalance.multiply(BigDecimal.valueOf(0.1)).setScale(4, RoundingMode.HALF_DOWN); |
| | | redisUtils.set(AppContants.REDIS_KEY_USDT_OUT_LIMIT, total); |
| | | redisUtils.set(AppContants.REDIS_KEY_USDT_OUT_LIMIT_REMAIN, total); |
| | | } |
| | | |
| | | private boolean symbolPriceUpOrDown() { |
| | | String dailyPrice = redisUtils.getString(AppContants.REDIS_KEY_SYMBOL_DAILY_PRICE); |
| | | BigDecimal lastDayPrice = BigDecimal.ZERO; |
| | | if (StrUtil.isNotBlank(dailyPrice)) { |
| | | lastDayPrice = new BigDecimal(dailyPrice); |
| | | } |
| | | |
| | | ContractChainService tfcInstance = ChainService.getInstance(ChainEnum.BSC_TFC_SOURCE.name()); |
| | | // 源池币种数量 |
| | | BigDecimal tfcBalance = tfcInstance.balanceOf(ChainEnum.BSC_TFC_SOURCE.getAddress()); |
| | | |
| | | // 源池USDT数量 |
| | | BigDecimal usdtBalance = ChainService.getInstance(ChainEnum.BSC_USDT_SOURCE.name()).balanceOf(ChainEnum.BSC_USDT_SOURCE.getAddress()); |
| | | |
| | | BigDecimal todayPrice = tfcBalance.divide(usdtBalance, tfcInstance.decimals(), RoundingMode.HALF_UP); |
| | | |
| | | DappSymbolDailyPriceEntity dailyPriceEntity = new DappSymbolDailyPriceEntity(); |
| | | dailyPriceEntity.setPrice(todayPrice); |
| | | this.dappSymbolDailyPriceMapper.insert(dailyPriceEntity); |
| | | |
| | | redisUtils.set(AppContants.REDIS_KEY_SYMBOL_DAILY_PRICE, todayPrice.toString()); |
| | | |
| | | // 如果价格有跌幅,则挖矿减半 |
| | | return todayPrice.compareTo(lastDayPrice) < 0; |
| | | } |
| | | |
| | | @Override |
| | | public void boxCnt(Long id) { |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(id); |
| | | |
| | | DappMemberEntity member = dappMemberDao.selectById(fundFlow.getMemberId()); |
| | | DappMemberEntity parent = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | if (parent == null) { |
| | | return; |
| | | } |
| | | |
| | | DappMemberBoxRecordEntity memberBox = dappMemberBoxRecordMapper.selectByFromMemberId(fundFlow.getMemberId()); |
| | | if (memberBox != null) { |
| | | return; |
| | | } |
| | | |
| | | if (!hasProfit(parent.getAddress())) { |
| | | return; |
| | | } |
| | | |
| | | BigInteger totalSupply = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).totalSupplyNFT(); |
| | | int box = 0; |
| | | // 需要第一次购买,才在推荐中加1 |
| | | Object parentRecommend = redisUtils.hget(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress()); |
| | | if (parentRecommend == null) { |
| | | redisUtils.hset(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress(), 1); |
| | | } else { |
| | | int i = (int) parentRecommend; |
| | | |
| | | // 如果超过10个,则新增一个盲盒,并重置推荐人数 |
| | | if (++i == CardPeriod.ONE.recommendCnt(totalSupply.intValue())) { |
| | | box = 1; |
| | | redisUtils.hset(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress(), 0); |
| | | } else { |
| | | redisUtils.hset(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress(), i); |
| | | } |
| | | } |
| | | |
| | | if (box > 0) { |
| | | DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(parent.getId()); |
| | | walletCoin.setBoxCnt(walletCoin.getBoxCnt() + box); |
| | | dappWalletCoinDao.updateById(walletCoin); |
| | | |
| | | DappMemberBoxRecordEntity memberBoxRecordEntity = new DappMemberBoxRecordEntity(); |
| | | memberBoxRecordEntity.setMemberId(parent.getId()); |
| | | memberBoxRecordEntity.setAddress(parent.getAddress()); |
| | | memberBoxRecordEntity.setFromMemberId(member.getId()); |
| | | memberBoxRecordEntity.setFromAddress(member.getAddress()); |
| | | this.dappMemberBoxRecordMapper.insert(memberBoxRecordEntity); |
| | | |
| | | DappFundFlowEntity boxFundFlow = new DappFundFlowEntity(parent.getId(), new BigDecimal(box), 5, 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(boxFundFlow); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public boolean systemHasStart() { |
| | | String hasStart = redisUtils.getString(AppContants.SYSTEM_START_FLAG); |
| | | if (!"start".equals(hasStart)) { |
| | | log.info("系统未启动"); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal newestPrice() { |
| | | if (systemHasStart()) { |
| | | String dailyPrice = redisUtils.getString(AppContants.REDIS_KEY_SYMBOL_DAILY_PRICE); |
| | | return StrUtil.isNotBlank(dailyPrice) ? new BigDecimal(dailyPrice) : BigDecimal.ZERO; |
| | | } else { |
| | | return new BigDecimal("0.05"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public boolean hasProfit(String address) { |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(address); |
| | | BigDecimal usdtBalance = balance.multiply(newestPrice()); |
| | | |
| | | DataDictionaryCustom data = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_MINI_HOLD_COIN_LIMIT); |
| | | BigDecimal miniLimit = new BigDecimal(data.getValue()); |
| | | if (usdtBalance.compareTo(miniLimit) < 0) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | |
| | | public synchronized void achieveTree(Long memberId) { |
| | | DappMemberEntity member = dappMemberDao.selectById(memberId); |
| | | |
| | | int batchNo = 0; |
| | | DappAchieveTreeEntity newestTreeNode = dappAchieveTreeDao.selectNewestTreeNode(); |
| | | if (newestTreeNode != null) { |
| | | if (newestTreeNode.getValidState() == 2) { |
| | | batchNo = newestTreeNode.getBatchNo() + 1; |
| | | } else { |
| | | batchNo = newestTreeNode.getBatchNo(); |
| | | } |
| | | } |
| | | |
| | | // 在大树中,插入当前节点 |
| | | DappAchieveTreeEntity achieveTree = new DappAchieveTreeEntity(); |
| | | achieveTree.setMidNode(memberId); |
| | | achieveTree.setValidState(1); |
| | | achieveTree.setBatchNo(batchNo); |
| | | dappAchieveTreeDao.insert(achieveTree); |
| | | |
| | | // 在内存树(大树)中插入当前节点,并返回父节点 |
| | | MemberNode node = new MemberNode(member.getId(), member.getAddress(), member.getInviteId(), member.getRefererId()); |
| | | |
| | | MatrixTree tree = MatrixTree.getInstance(); |
| | | MemberNode exist = tree.getNode(member.getId()); |
| | | if (exist != null) { |
| | | return; |
| | | } |
| | | |
| | | MemberNode parentNode = tree.addNode(node); |
| | | |
| | | // 创建该节点的矩阵 |
| | |
| | | achieveMemberTree.setTopNode(memberId); |
| | | achieveMemberTree.setDeep(1); |
| | | achieveMemberTree.setHasMoney(1); |
| | | achieveMemberTree.setParentNode(parentNode.getMemberId()); |
| | | if (parentNode != null) { |
| | | achieveMemberTree.setParentNode(parentNode.getMemberId()); |
| | | } |
| | | dappAchieveMemberTreeDao.insert(achieveMemberTree); |
| | | |
| | | // 激活用户状态 |
| | | member.setActiveStatus(1); |
| | | dappMemberDao.updateById(member); |
| | | |
| | | putIntoProfit(memberId, 2); |
| | | if (parentNode == null) { |
| | | return; |
| | | } |
| | | |
| | | // 修改父节点在数据库中的左/右节点数据 |
| | | DappAchieveTreeEntity treeMidNode = dappAchieveTreeDao.selectByMidNode(parentNode.getMemberId()); |
| | |
| | | |
| | | // 完成矩阵树,并重置矩阵且重入 |
| | | public void finishMatrixTree(Long memberId) { |
| | | List<DappAchieveMemberTreeEntity> matrixTree = dappAchieveMemberTreeDao.selectMatrixTreeByTopNode(memberId); |
| | | List<DappAchieveMemberTreeEntity> matrixTree = dappAchieveMemberTreeDao.selectMatrixTreeByTopNode(memberId, 1); |
| | | // 如果达到标准,则重置该矩阵树 |
| | | if (matrixTree.size() == 7) { |
| | | dappAchieveMemberTreeDao.resetMatrixTree(memberId); |
| | | dappAchieveMemberTreeDao.reentryMoney(memberId); |
| | | |
| | | putIntoProfit(memberId, 1); |
| | | DappAchieveMemberTreeEntity bottomNode = dappAchieveMemberTreeDao.selectNodeByDeep(memberId, 3); |
| | | if (bottomNode != null) { |
| | | finishMatrixTree(bottomNode.getTopNode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void putIntoProfit(Long memberId, int isReIn) { |
| | | DappMemberEntity member = dappMemberDao.selectById(memberId); |
| | | DappMemberEntity parent = dappMemberDao.selectMemberInfoByInviteId(member.getRefererId()); |
| | | |
| | | if (parent != null) { |
| | | BigDecimal directProfit = TreeConstants.PUT_IN_AMOUNT.multiply(new BigDecimal("0.1")); |
| | | dappWalletService.updateWalletCoinWithLock(directProfit, parent.getId(), 1); |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(parent.getId(), directProfit, 3, 2, null, null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | } |
| | | |
| | | // 如果是复投的,则需奖励 |
| | | if (isReIn == 1) { |
| | | List<DappMemberEntity> directCnt = dappMemberDao.selectChildMemberDirectOrNot(member.getInviteId(), 1, 1); |
| | | |
| | | /** |
| | | * 复投后,推一个拿一轮,推两个拿两轮,推三个后终身有效。 |
| | | * 200u单。 |
| | | * 无直推则收益200U |
| | | * 一人加一轮400u,二人二轮 |
| | | * 三人永久。 |
| | | */ |
| | | if (directCnt.size() < 3 && member.getOutCnt() != 0 && member.getOutCnt() - 1 == directCnt.size()) { |
| | | return; |
| | | } else { |
| | | BigDecimal amount = null; |
| | | if (directCnt.size() < 1) { |
| | | amount = TreeConstants.PUT_IN_AMOUNT; |
| | | } else { |
| | | amount = TreeConstants.FULL_PROFIT_AMOUNT; |
| | | } |
| | | |
| | | member.setOutCnt(member.getOutCnt() + 1); |
| | | dappMemberDao.updateById(member); |
| | | |
| | | dappWalletService.updateWalletCoinWithLock(amount, member.getId(), 1); |
| | | |
| | | DappFundFlowEntity matrixProfitFlow = new DappFundFlowEntity(memberId, amount, 2, 2, null, null); |
| | | dappFundFlowDao.insert(matrixProfitFlow); |
| | | } |
| | | |
| | | DappFundFlowEntity rePutInFlow = new DappFundFlowEntity(memberId, TreeConstants.PUT_IN_AMOUNT.negate(), 1, 2, null, null); |
| | | dappFundFlowDao.insert(rePutInFlow); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void tfcNewPrice(String data) { |
| | | // redisUtils.set(AppContants.REDIS_KEY_TFC_NEW_PRICE, new BigDecimal(data)); |
| | | } |
| | | |
| | | @Override |
| | | public void resetMatrix() { |
| | | DappAchieveTreeEntity node = dappAchieveTreeDao.selectNewestTreeNode(); |
| | | if (node.getValidState() == 2) { |
| | | return; |
| | | } |
| | | |
| | | long days = DateUtil.between(node.getCreateTime(), new Date(), DateUnit.DAY); |
| | | if (days < 7) { |
| | | return; |
| | | } |
| | | DappMineDataEntity mineDataEntity = dappSystemDao.selectMineDataForOne(); |
| | | |
| | | List<DappAchieveTreeEntity> list = dappAchieveTreeDao.selectLastCountTreeNode(500); |
| | | if (CollUtil.isNotEmpty(list)) { |
| | | BigDecimal preAmount = mineDataEntity.getSafePool().divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP); |
| | | |
| | | list.forEach(item -> { |
| | | dappWalletService.updateWalletCoinWithLock(preAmount, item.getMidNode(), 1); |
| | | DappFundFlowEntity flow = new DappFundFlowEntity(item.getMidNode(), preAmount, 8, 2, null, null); |
| | | dappFundFlowDao.insert(flow); |
| | | }); |
| | | } |
| | | |
| | | mineDataEntity.setSafePool(BigDecimal.ZERO); |
| | | dappSystemDao.updateMineData(mineDataEntity); |
| | | |
| | | dappAchieveTreeDao.updateNodeValidState(); |
| | | dappAchieveMemberTreeDao.emptyTable(); |
| | | dappMemberDao.updateMemberActive(); |
| | | } |
| | | |
| | | @Override |
| | | public void feeDistribute(String data) { |
| | | if (StrUtil.isBlank(data)) { |
| | | return; |
| | | } |
| | | |
| | | Long flowId = Long.parseLong(data); |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectById(flowId); |
| | | if (fundFlow == null) { |
| | | return; |
| | | } |
| | | |
| | | DataDictionaryCustom memberFeeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.MEMBER_FEE.getType(), DataDictionaryEnum.MEMBER_FEE.getCode()); |
| | | if (memberFeeDic == null) { |
| | | log.info("未设置手续费返利比例"); |
| | | return; |
| | | } |
| | | List<DappMemberEntity> memberList = dappMemberDao.selectMemberListNeedProfit(); |
| | | if (CollUtil.isEmpty(memberList)) { |
| | | return; |
| | | } |
| | | |
| | | BigDecimal feeReturnRatio = new BigDecimal(memberFeeDic.getValue()); |
| | | int size = memberList.size(); |
| | | BigDecimal totalProfit = fundFlow.getFee().multiply(feeReturnRatio.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_DOWN)); |
| | | BigDecimal perProfit = totalProfit.divide(BigDecimal.valueOf(size), 8, RoundingMode.HALF_DOWN); |
| | | |
| | | memberList.forEach(item -> { |
| | | dappWalletService.updateWalletMineWithLock(perProfit, item.getId(), 1); |
| | | |
| | | DappFundFlowEntity profitFlow = new DappFundFlowEntity(item.getId(), perProfit, 12, 2, null, null); |
| | | dappFundFlowDao.insert(profitFlow); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void levelProfit(Long id) { |
| | | DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(dappSystemProfit)){ |
| | | return; |
| | | } |
| | | Integer levelProfitState = dappSystemProfit.getLevelProfit(); |
| | | |
| | | if(DappSystemProfit.ENUM_YES == levelProfitState){ |
| | | return; |
| | | } |
| | | Long memberId = dappSystemProfit.getMemberId(); |
| | | //获取用户的上级用户信息 |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | String refererIds = dappMemberEntity.getRefererIds(); |
| | | if(StrUtil.isEmpty(refererIds)){ |
| | | return; |
| | | } |
| | | DataDictionaryCustom levelProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.LEVEL_PROFIT.getType(), DataDictionaryEnum.LEVEL_PROFIT.getCode()); |
| | | BigDecimal levelProfit = new BigDecimal(StrUtil.isEmpty(levelProfitSet.getValue()) ? "0.3" : levelProfitSet.getValue()); |
| | | //投入金额减去技术方收益 |
| | | DataDictionaryCustom systemProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.SYSTEM_PROFIT.getType(), DataDictionaryEnum.SYSTEM_PROFIT.getCode()); |
| | | BigDecimal systemProfit = new BigDecimal(StrUtil.isEmpty(systemProfitSet.getValue()) ? "0.05" : systemProfitSet.getValue()); |
| | | BigDecimal amount = dappSystemProfit.getAmount().subtract(systemProfit); |
| | | //层级奖励总奖金 |
| | | BigDecimal levelProfitTotal = amount.multiply(levelProfit); |
| | | //实发层级奖励 -- 如果还有剩余给技术方 |
| | | BigDecimal systemProfitTotal = BigDecimal.ZERO; |
| | | //返回十层 |
| | | List<String> refererIdList = StrUtil.split(refererIds, ','); |
| | | //i:计数层数,同时i也为对应层数应推广的人数,当达到对应的直推人数时,才能获取对应层级奖励 |
| | | if(CollUtil.isEmpty(refererIdList)){ |
| | | return; |
| | | } |
| | | //层级奖励最大循环次数 |
| | | int maxLevel = 10; |
| | | if(maxLevel > refererIdList.size()){ |
| | | maxLevel = refererIdList.size(); |
| | | } |
| | | for(int i = 0;i < maxLevel; i++){ |
| | | if(systemProfitTotal.compareTo(levelProfitTotal) < 0){ |
| | | String inviteId = refererIdList.get(i); |
| | | //获取每层用户的直推人数,判断能否获得这个层级的层级奖励 |
| | | DappMemberEntity refererMember = dappMemberDao.selectMemberInfoByInviteId(inviteId); |
| | | //获取直推用户数量 |
| | | QueryWrapper<DappMemberEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("referer_id",refererMember.getInviteId()); |
| | | Integer selectCount = dappMemberDao.selectCount(objectQueryWrapper); |
| | | if(i >= selectCount){ |
| | | continue; |
| | | } |
| | | //获取对应层级奖励 |
| | | BigDecimal profit = LevelProfitEnum.YI.getProfit(i+1); |
| | | String accountType = refererMember.getAccountType(); |
| | | //根据会员的等级类型,获取对应的百分比收益 |
| | | DataDictionaryCustom memberLevelSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode("MEMBER_LEVEL", accountType); |
| | | BigDecimal memberLevel = new BigDecimal(memberLevelSet.getValue()); |
| | | |
| | | // BigDecimal memberLevelProfit = levelProfitTotal.multiply(profit).multiply(memberLevel); |
| | | |
| | | BigDecimal memberLevelProfit = profit.multiply(memberLevel); |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(refererMember.getId(), memberLevelProfit, 4, 1, BigDecimal.ZERO,null,dappSystemProfit.getId()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | //发送转币消息 |
| | | chainProducer.sendBnbTransferMsg(fundFlow.getId()); |
| | | systemProfitTotal = systemProfitTotal.add(memberLevelProfit); |
| | | } |
| | | } |
| | | //如果还有剩余给技术方 |
| | | if(levelProfitTotal.compareTo(systemProfitTotal) > 0){ |
| | | BigDecimal avaProfit = levelProfitTotal.subtract(systemProfitTotal); |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(2L, avaProfit, 5, 1, BigDecimal.ZERO,null,dappSystemProfit.getId()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | //发送转币消息 |
| | | chainProducer.sendBnbTransferMsg(fundFlow.getId()); |
| | | } |
| | | |
| | | dappSystemProfitDao.updateLevelProfitById(DappSystemProfit.ENUM_YES,dappSystemProfit.getId()); |
| | | } |
| | | |
| | | @Override |
| | | public void memberOut(Long id) { |
| | | //验证是否已经加入动能队列 |
| | | DappSystemProfit systemProfit = dappSystemProfitDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(systemProfit)){ |
| | | return; |
| | | } |
| | | //获取当前是第几轮队列 |
| | | String redisKey = "QUEUE_COUNT"; |
| | | String memberOutCount = redisUtils.getString(redisKey); |
| | | DataDictionaryCustom queueCountSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.QUEUE_COUNT.getType(), DataDictionaryEnum.QUEUE_COUNT.getCode()); |
| | | String queueCount = queueCountSet.getValue(); |
| | | if(StrUtil.isBlank(memberOutCount) || !queueCount.equals(memberOutCount)){ |
| | | redisUtils.set(redisKey,queueCount,0L); |
| | | memberOutCount = queueCount; |
| | | } |
| | | //出局条件的人数 |
| | | /** |
| | | * 初始大小 5+4*0 |
| | | * 1 1,2,3,4,5 1出局 5+4*0 |
| | | * 2 2,3,4,5,1(复投),7,8,9,10 2出局 5+4*1 |
| | | * 3 3,4,5,1(复投),7,8,9,10,2(复投),12,13,14,15 3出局 5+4*2 |
| | | * 4 4,5,1(复投),7,8,9,10,2(复投),12,13,14,15,3(复投),17,18,19,20 4出局 5+4*3 |
| | | */ |
| | | Integer memberCount = Integer.parseInt(memberOutCount) * 4 + 5; |
| | | //判断当前是否符合出局条件 |
| | | QueryWrapper<DappSystemProfit> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("state",DappSystemProfit.STATE_IN); |
| | | //实际投资人数 |
| | | Integer selectCount = dappSystemProfitDao.selectCount(objectQueryWrapper); |
| | | //实际投资人数小于出局条件人数 |
| | | if(selectCount < memberCount){ |
| | | return; |
| | | } |
| | | //符合则出局 实际投资人数等于出局条件人数 |
| | | DappSystemProfit dappSystemProfit = dappSystemProfitDao.selectSystemProfitByState(DappSystemProfit.STATE_IN); |
| | | if(ObjectUtil.isEmpty(dappSystemProfit)){ |
| | | return; |
| | | } |
| | | //符合则出局,轮数+1 |
| | | Integer realCount = (Integer.parseInt(queueCount) + 1); |
| | | queueCountSet.setValue(realCount.toString()); |
| | | dataDictionaryCustomMapper.updateById(queueCountSet); |
| | | redisUtils.set(redisKey,realCount,0L); |
| | | |
| | | DappSystemProfit dappSystemProfitNow = dappSystemProfitDao.selectByIdForUpdate(dappSystemProfit.getId(),DappSystemProfit.STATE_IN); |
| | | dappSystemProfitDao.updateStateById(DappSystemProfit.STATE_OUT,dappSystemProfitNow.getId()); |
| | | |
| | | // 直接拿走0.95ge |
| | | |
| | | DataDictionaryCustom investAmountProfitSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INVEST_AMOUNT_PROFIT.getType(), DataDictionaryEnum.INVEST_AMOUNT_PROFIT.getCode()); |
| | | BigDecimal investAmountProfit = new BigDecimal(investAmountProfitSet.getValue()); |
| | | DappFundFlowEntity fundFlowOut = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmountProfit, 7, 1, BigDecimal.ZERO, null,dappSystemProfitNow.getId()); |
| | | dappFundFlowDao.insert(fundFlowOut); |
| | | //发送转币消息 |
| | | chainProducer.sendBnbTransferMsg(fundFlowOut.getId()); |
| | | //复投 成功{type: 1, txHash: result.transactionHash, id: res.data, flag: 'success', buyType: 2} |
| | | DataDictionaryCustom investAmountSet = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.INVEST_AMOUNT.getType(), DataDictionaryEnum.INVEST_AMOUNT.getCode()); |
| | | BigDecimal investAmount = new BigDecimal(investAmountSet.getValue()); |
| | | //todo 直接运行转账 |
| | | String txHash = "复投"; |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(dappSystemProfitNow.getMemberId(), investAmount, 6, 1, BigDecimal.ZERO, txHash); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | |
| | | TransferDto transferDto = new TransferDto(); |
| | | transferDto.setType(1); |
| | | transferDto.setTxHash(txHash); |
| | | transferDto.setBuyType(2); |
| | | transferDto.setId(fundFlow.getId()); |
| | | transferDto.setFlag("success"); |
| | | transferDto.setAmount(investAmount); |
| | | transferDto.setMemberId(dappSystemProfitNow.getMemberId()); |
| | | dappWalletService.transferAgain(transferDto); |
| | | } |
| | | |
| | | @Override |
| | | public void bnbTransfer(Long id) { |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | if(DappFundFlowEntity.WITHDRAW_STATUS_AGREE == dappFundFlowEntity.getStatus()){ |
| | | return; |
| | | } |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | Integer count = dappFundFlowDao.updateStatusById(DappFundFlowEntity.WITHDRAW_STATUS_AGREE,dappFundFlowEntity.getId()); |
| | | if(count > 0){ |
| | | /** |
| | | * 转账直推收益 |
| | | */ |
| | | DappFundFlowEntity dappFundFlow = dappFundFlowDao.selectById(id); |
| | | //金额 |
| | | BigDecimal amount = dappFundFlow.getAmount(); |
| | | //目标地址 |
| | | String address = dappMemberEntity.getAddress(); |
| | | /** |
| | | * 发起USDT转账 |
| | | */ |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(address, amount); |
| | | if(StrUtil.isEmpty(hash)){ |
| | | return; |
| | | } |
| | | log.info("{},{}",id,hash); |
| | | dappFundFlow.setFromHash(hash); |
| | | dappFundFlowDao.updateById(dappFundFlow); |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void agentUp(Long id) { |
| | | //根据邀请码获取用户信息 |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(id); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | //所有上级(不包含直属上级) |
| | | String refererIds = dappMemberEntity.getRefererIds(); |
| | | List<String> refererIdList = StrUtil.split(refererIds, ','); |
| | | if(CollUtil.isNotEmpty(refererIdList)){ |
| | | for(String inviteIdStr : refererIdList){ |
| | | DappMemberEntity dappMemberEntityUp = dappMemberDao.selectMemberInfoByInviteId(inviteIdStr); |
| | | if(ObjectUtil.isEmpty(dappMemberEntityUp)){ |
| | | continue; |
| | | } |
| | | String accountType = dappMemberEntityUp.getAccountType(); |
| | | if(DataDictionaryEnum.BIG_BOSS.getCode().equals(accountType)){ |
| | | continue; |
| | | } |
| | | //当前为BOSS,且直推中有两个BOSS以上,则升级BIG_BOSS |
| | | if(DataDictionaryEnum.BOSS.getCode().equals(accountType)){ |
| | | Integer bossCount = dappMemberDao.selectCountByAccountTypeAndRefererId(DataDictionaryEnum.BOSS.getCode(),dappMemberEntityUp.getInviteId()); |
| | | if(2 <= bossCount){ |
| | | dappMemberDao.updateMemberAccountType(DataDictionaryEnum.BIG_BOSS.getCode(),dappMemberEntityUp.getId()); |
| | | } |
| | | continue; |
| | | } |
| | | //当前为AGENT,且直推中有两个以上,则升级BOSS |
| | | if(DataDictionaryEnum.AGENT.getCode().equals(accountType)){ |
| | | Integer bossCount = dappMemberDao.selectCountByAccountTypeAndRefererId(null,dappMemberEntityUp.getInviteId()); |
| | | if(2 <= bossCount){ |
| | | dappMemberDao.updateMemberAccountType(DataDictionaryEnum.BOSS.getCode(),dappMemberEntityUp.getId()); |
| | | } |
| | | continue; |
| | | } |
| | | } |
| | | } |
| | | //直属上级 |
| | | String accountType = dappMemberEntity.getAccountType(); |
| | | if(DataDictionaryEnum.BIG_BOSS.getCode().equals(accountType)){ |
| | | return; |
| | | } |
| | | //当前为BOSS,且直推中有两个BOSS以上,则升级BIG_BOSS |
| | | if(DataDictionaryEnum.BOSS.getCode().equals(accountType)){ |
| | | Integer bossCount = dappMemberDao.selectCountByAccountTypeAndRefererId(DataDictionaryEnum.BOSS.getCode(),dappMemberEntity.getInviteId()); |
| | | if(2 <= bossCount){ |
| | | dappMemberDao.updateMemberAccountType(DataDictionaryEnum.BIG_BOSS.getCode(),dappMemberEntity.getId()); |
| | | } |
| | | return; |
| | | } |
| | | //当前为AGENT,且直推中有两个以上,则升级BOSS |
| | | if(DataDictionaryEnum.AGENT.getCode().equals(accountType)){ |
| | | Integer bossCount = dappMemberDao.selectCountByAccountTypeAndRefererId(null,dappMemberEntity.getInviteId()); |
| | | if(2 <= bossCount){ |
| | | dappMemberDao.updateMemberAccountType(DataDictionaryEnum.BOSS.getCode(),dappMemberEntity.getId()); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void bnbTransferTest(Long id) { |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | if(AppContants.ADDRESS_PEOJECT.equals(dappMemberEntity.getAddress())){ |
| | | DappFundFlowEntity dappFundFlow = dappFundFlowDao.selectById(id); |
| | | //金额 |
| | | BigDecimal amount = dappFundFlow.getAmount(); |
| | | //目标地址 |
| | | String address = dappMemberEntity.getAddress(); |
| | | /** |
| | | * 发起USDT转账 |
| | | */ |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(address, amount); |
| | | if(StrUtil.isEmpty(hash)){ |
| | | return; |
| | | } |
| | | log.info("{},{}",id,hash); |
| | | dappFundFlow.setFromHash(hash); |
| | | dappFundFlowDao.updateById(dappFundFlow); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void AntACoinInMsg(Long id) { |
| | | /** |
| | | * 获取对应的流水记录 |
| | | */ |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | /** |
| | | * 会员充值金额 |
| | | */ |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | /** |
| | | * A币的当前价格 |
| | | */ |
| | | DataDictionaryCustom coinAPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_PRICE.getType(), |
| | | PoolEnum.COIN_A_PRICE.getCode() |
| | | ); |
| | | BigDecimal coinAPrice = new BigDecimal(StrUtil.isEmpty(coinAPriceDic.getValue()) ? "0" : coinAPriceDic.getValue()).setScale(8,BigDecimal.ROUND_DOWN); |
| | | /** |
| | | * 会员充值USDT买入A币记录的ID |
| | | */ |
| | | Long chergeRecordId = dappFundFlowEntity.getSystemProfitId(); |
| | | DappChargeUsdtEntity dappChargeUsdtEntity = dappChargeUsdtMapper.selectById(chergeRecordId); |
| | | if(2 != dappChargeUsdtEntity.getStatus()){ |
| | | return; |
| | | } |
| | | if(StrUtil.isEmpty(dappChargeUsdtEntity.getMemberHash())){ |
| | | return; |
| | | } |
| | | /** |
| | | * 金本位的三倍额度,增加业绩,增加对应的NFT的值 |
| | | */ |
| | | DappUsdtPerkEntity dappUsdtPerkEntity = dappUsdtPerkEntityMapper.selectByMemberId(memberId); |
| | | if(ObjectUtil.isEmpty(dappUsdtPerkEntity)){ |
| | | dappUsdtPerkEntity = new DappUsdtPerkEntity(); |
| | | dappUsdtPerkEntity.setAmount(amount.multiply(new BigDecimal(3))); |
| | | dappUsdtPerkEntity.setNftDevote(amount); |
| | | dappUsdtPerkEntity.setMemberId(memberId); |
| | | dappUsdtPerkEntityMapper.insert(dappUsdtPerkEntity); |
| | | } |
| | | //金本位的三倍额度 |
| | | BigDecimal amountPerk = dappUsdtPerkEntity.getAmount(); |
| | | amountPerk = amountPerk.add(amount.multiply(new BigDecimal(3))); |
| | | dappUsdtPerkEntity.setAmount(amountPerk); |
| | | //增加业绩 |
| | | BigDecimal achieveAmount = dappUsdtPerkEntity.getAchieveAmount(); |
| | | achieveAmount = achieveAmount.add(amount); |
| | | dappUsdtPerkEntity.setAchieveAmount(achieveAmount); |
| | | //增加对应的NFT的值 |
| | | BigDecimal nftDevote = dappUsdtPerkEntity.getNftDevote(); |
| | | nftDevote = nftDevote.add(amount); |
| | | dappUsdtPerkEntity.setNftDevote(nftDevote); |
| | | dappUsdtPerkEntityMapper.updateById(dappUsdtPerkEntity); |
| | | /** |
| | | * 90%进入A币底池 10%进入B币LP薄饼底池 |
| | | */ |
| | | DataDictionaryCustom usdtAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.USDT_A_PERCENT.getType(), |
| | | PoolEnum.USDT_A_PERCENT.getCode() |
| | | ); |
| | | BigDecimal usdtAPercent = new BigDecimal(StrUtil.isEmpty(usdtAPercentDic.getValue()) ? "0.9" : usdtAPercentDic.getValue()); |
| | | BigDecimal usdtAAmount = amount.multiply(usdtAPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | //生成一条进行中的90%进入A币底池的资金流水记录 |
| | | DappFundFlowEntity fundFlowToA = new DappFundFlowEntity( |
| | | 1L, |
| | | usdtAAmount, |
| | | FundFlowEnum.USDT_IN_A_POOL.getCode(), |
| | | 1, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(fundFlowToA); |
| | | //90%进入A币底池 |
| | | chainProducer.sendAntACoinInAPoolMsg(fundFlowToA.getId()); |
| | | |
| | | DataDictionaryCustom usdtBPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.USDT_B_PERCENT.getType(), |
| | | PoolEnum.USDT_B_PERCENT.getCode() |
| | | ); |
| | | BigDecimal usdtBPercent = new BigDecimal(StrUtil.isEmpty(usdtBPercentDic.getValue()) ? "0.1" : usdtBPercentDic.getValue()); |
| | | BigDecimal usdtBAmount = amount.multiply(usdtBPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | //生成一条进行中的10%进入B币底池的资金流水记录 |
| | | DappFundFlowEntity fundFlowToB = new DappFundFlowEntity( |
| | | 1L, |
| | | usdtBAmount, |
| | | FundFlowEnum.USDT_IN_B_POOL.getCode(), |
| | | 1, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(fundFlowToB); |
| | | //10%进入B币LP薄饼底池 |
| | | chainProducer.sendAntACoinInBPoolMsg(fundFlowToB.getId()); |
| | | /** |
| | | * 1.90%底池的USDT做成100%溢价,铸造出70%金本位价值的A币。 |
| | | */ |
| | | DataDictionaryCustom produceAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.PRODUCE_A_PERCENT.getType(), |
| | | PoolEnum.PRODUCE_A_PERCENT.getCode() |
| | | ); |
| | | BigDecimal produceAPercent = new BigDecimal(StrUtil.isEmpty(produceAPercentDic.getValue()) ? "0.7" : produceAPercentDic.getValue()); |
| | | //购买数量 |
| | | BigDecimal totalCnt = amount.divide(coinAPrice, 4, BigDecimal.ROUND_DOWN); |
| | | /** |
| | | * 铸造出70%金本位价值的A币。实际产生数量 |
| | | */ |
| | | BigDecimal realCnt = totalCnt.multiply(produceAPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | dappChargeUsdtEntity.setTotalCnt(totalCnt); |
| | | dappChargeUsdtEntity.setRealCnt(realCnt); |
| | | dappChargeUsdtMapper.updateById(dappChargeUsdtEntity); |
| | | /** |
| | | * 重新计算A币的价格 |
| | | */ |
| | | DataDictionaryCustom coinACntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_CNT.getType(), |
| | | PoolEnum.COIN_A_CNT.getCode() |
| | | ); |
| | | //A币币本位底池-A币的数量 |
| | | BigDecimal coinACntDicCnt = new BigDecimal(coinACntDic.getValue()); |
| | | coinACntDicCnt = coinACntDicCnt.add(realCnt); |
| | | coinACntDic.setValue(coinACntDicCnt.toString()); |
| | | dataDictionaryCustomMapper.updateById(coinACntDic); |
| | | |
| | | DataDictionaryCustom coinAUsdtPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_USDT_PRICE.getType(), |
| | | PoolEnum.COIN_A_USDT_PRICE.getCode() |
| | | ); |
| | | //A币金本位底池-usdt数量 |
| | | BigDecimal coinAUsdtPriceDicCnt = new BigDecimal(coinAUsdtPriceDic.getValue()); |
| | | coinAUsdtPriceDicCnt = coinAUsdtPriceDicCnt.add(amount); |
| | | coinAUsdtPriceDic.setValue(coinAUsdtPriceDicCnt.toString()); |
| | | dataDictionaryCustomMapper.updateById(coinAUsdtPriceDic); |
| | | |
| | | BigDecimal divide = coinAUsdtPriceDicCnt.divide(coinACntDicCnt, 8, BigDecimal.ROUND_DOWN); |
| | | coinAPriceDic.setValue(divide.toString()); |
| | | dataDictionaryCustomMapper.updateById(coinAPriceDic); |
| | | |
| | | chainProducer.sendAntKLineMsg(0); |
| | | /** |
| | | * A币的分配 walletMine |
| | | * 【70%换算100%分配】 |
| | | * 50%客户秒到 |
| | | * 20%全网加权分红(按20%释放递减) |
| | | * 10%直推 |
| | | * 5%节点 |
| | | * 5%基金会 |
| | | * 10%级差奖 |
| | | */ |
| | | /** |
| | | * 50%客户秒到 |
| | | */ |
| | | DataDictionaryCustom memberGetAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.MEMBER_GET_A_PERCENT.getType(), |
| | | PoolEnum.MEMBER_GET_A_PERCENT.getCode() |
| | | ); |
| | | BigDecimal memberGetAPercent = new BigDecimal(StrUtil.isEmpty(memberGetAPercentDic.getValue()) ? "0.5" : memberGetAPercentDic.getValue()); |
| | | BigDecimal memberGetACnt = realCnt.multiply(memberGetAPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal fundFlowToMemberFlag = this.getAndUpdateMemberPerk(dappFundFlowEntity.getMemberId(), memberGetACnt); |
| | | if(fundFlowToMemberFlag.compareTo(BigDecimal.ZERO) > 0){ |
| | | //生成一条50%客户秒到的资金流水记录 |
| | | DappFundFlowEntity fundFlowToMember = new DappFundFlowEntity( |
| | | dappFundFlowEntity.getMemberId(), |
| | | fundFlowToMemberFlag, |
| | | FundFlowEnum.MEMBER_GET_A_CNT.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(fundFlowToMember); |
| | | //用户的A币账户增加memberGetACnt数量 |
| | | dappWalletService.updateWalletMineWithLock(fundFlowToMemberFlag,dappFundFlowEntity.getMemberId(),1); |
| | | } |
| | | /** |
| | | * 20%全网加权分红(按20%释放递减)进入加权分红底池 |
| | | */ |
| | | DataDictionaryCustom poolAllMemberAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.POOL_ALL_MEMBER_A_PERCENT.getType(), |
| | | PoolEnum.POOL_ALL_MEMBER_A_PERCENT.getCode() |
| | | ); |
| | | BigDecimal poolAllMemberAPercent = new BigDecimal(StrUtil.isEmpty(poolAllMemberAPercentDic.getValue()) ? "0.2" : poolAllMemberAPercentDic.getValue()); |
| | | BigDecimal poolAllMemberAPercentCnt = realCnt.multiply(poolAllMemberAPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | DataDictionaryCustom poolAllMemberACntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.POOL_ALL_MEMBER_A_CNT.getType(), |
| | | PoolEnum.POOL_ALL_MEMBER_A_CNT.getCode() |
| | | ); |
| | | BigDecimal poolAllMemberACnt = new BigDecimal(StrUtil.isEmpty(poolAllMemberACntDic.getValue()) ? "0" : poolAllMemberACntDic.getValue()); |
| | | poolAllMemberACnt = poolAllMemberACnt.add(poolAllMemberAPercentCnt); |
| | | poolAllMemberACntDic.setValue(poolAllMemberACnt.toString()); |
| | | dataDictionaryCustomMapper.updateById(poolAllMemberACntDic); |
| | | //生成一条20%全网加权分红(按20%释放递减)进入加权分红底池的资金流水记录 |
| | | DappFundFlowEntity poolAllMemberAFundFlow = new DappFundFlowEntity( |
| | | 1L, |
| | | poolAllMemberAPercentCnt, |
| | | FundFlowEnum.POOL_ALL_MEMBER_A_CNT.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(poolAllMemberAFundFlow); |
| | | |
| | | BigDecimal poolAllMemberAPercentCntAva = nodePoolPerk(poolAllMemberAPercentCnt, MemberLevelEnum.MEMBER.getType(), FundFlowEnum.POOL_MEMBER_A_CNT.getCode()); |
| | | DappFundFlowEntity poolAllMemberAFundFlowAva = new DappFundFlowEntity( |
| | | 1L, |
| | | poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva), |
| | | FundFlowEnum.POOL_MEMBER_A_CNT.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(poolAllMemberAFundFlowAva); |
| | | dappWalletService.updateWalletMineWithLock(poolAllMemberAPercentCnt.subtract(poolAllMemberAPercentCntAva), |
| | | 1L,1); |
| | | |
| | | /** |
| | | * 10%直推 |
| | | */ |
| | | DataDictionaryCustom directAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.DIRECT_A_PERCENT.getType(), |
| | | PoolEnum.DIRECT_A_PERCENT.getCode() |
| | | ); |
| | | BigDecimal directAPercent = new BigDecimal(StrUtil.isEmpty(directAPercentDic.getValue()) ? "0.1" : directAPercentDic.getValue()); |
| | | BigDecimal directAPercentCnt = realCnt.multiply(directAPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | String refererId = dappMemberEntity.getRefererId(); |
| | | DappMemberEntity directMemberEntity = dappMemberDao.selectMemberInfoByInviteId(refererId); |
| | | if(ObjectUtil.isNotEmpty(directMemberEntity)){ |
| | | /** |
| | | *推荐用户入单可享有贡献值.例.推荐100获得100贡献值 |
| | | */ |
| | | DappUsdtPerkEntity directDappUsdtPerkEntity = dappUsdtPerkEntityMapper.selectByMemberId(directMemberEntity.getId()); |
| | | if(ObjectUtil.isEmpty(directDappUsdtPerkEntity)){ |
| | | directDappUsdtPerkEntity = new DappUsdtPerkEntity(); |
| | | directDappUsdtPerkEntity.setNftDevote(amount); |
| | | directDappUsdtPerkEntity.setMemberId(directMemberEntity.getId()); |
| | | dappUsdtPerkEntityMapper.insert(directDappUsdtPerkEntity); |
| | | } |
| | | |
| | | BigDecimal directNftDevote = directDappUsdtPerkEntity.getNftDevote(); |
| | | directNftDevote = directNftDevote.add(amount); |
| | | directDappUsdtPerkEntity.setNftDevote(directNftDevote); |
| | | dappUsdtPerkEntityMapper.updateById(directDappUsdtPerkEntity); |
| | | |
| | | BigDecimal directAPercentFundFlowToMemberFlag = this.getAndUpdateMemberPerk(directMemberEntity.getId(), directAPercentCnt); |
| | | if(directAPercentFundFlowToMemberFlag.compareTo(BigDecimal.ZERO) > 0){ |
| | | //生成一条10%直推的资金流水记录 |
| | | DappFundFlowEntity directAPercentFundFlowToMember = new DappFundFlowEntity( |
| | | directMemberEntity.getId(), |
| | | directAPercentFundFlowToMemberFlag, |
| | | FundFlowEnum.DIRECT_A_PERCENT.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(directAPercentFundFlowToMember); |
| | | //用户的A币账户增加directAPercentCnt数量 |
| | | dappWalletService.updateWalletMineWithLock(directAPercentFundFlowToMemberFlag,directMemberEntity.getId(),1); |
| | | } |
| | | if(directAPercentCnt.compareTo(directAPercentFundFlowToMemberFlag) > 0){ |
| | | DappFundFlowEntity directAPercentFundFlowToMemberAva = new DappFundFlowEntity( |
| | | 1L, |
| | | directAPercentCnt.subtract(directAPercentFundFlowToMemberFlag), |
| | | FundFlowEnum.DIRECT_A_PERCENT.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(directAPercentFundFlowToMemberAva); |
| | | dappWalletService.updateWalletMineWithLock(directAPercentCnt.subtract(directAPercentFundFlowToMemberFlag), |
| | | 1L,1); |
| | | } |
| | | } |
| | | /** |
| | | * 5%节点 |
| | | */ |
| | | DataDictionaryCustom nodeAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_A_PERCENT.getType(), |
| | | PoolEnum.NODE_A_PERCENT.getCode() |
| | | ); |
| | | BigDecimal nodeAPercent = new BigDecimal(StrUtil.isEmpty(nodeAPercentDic.getValue()) ? "0.05" : nodeAPercentDic.getValue()); |
| | | BigDecimal nodeAPercentCnt = realCnt.multiply(nodeAPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | //生成一条5%节点的资金流水记录 |
| | | DappFundFlowEntity nodeAPercentFundFlow = new DappFundFlowEntity( |
| | | 1L, |
| | | nodeAPercentCnt, |
| | | FundFlowEnum.NODE_A_PERCENT.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlow); |
| | | // chainProducer.sendAntACoinInNodeMsg(nodeAPercentFundFlow.getId()); |
| | | DataDictionaryCustom nodeAPercentPoolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_A_PERCENT_POOL.getType(), |
| | | PoolEnum.NODE_A_PERCENT_POOL.getCode() |
| | | ); |
| | | BigDecimal nodeAPercentPoolDicCnt = new BigDecimal(StrUtil.isEmpty(nodeAPercentPoolDic.getValue()) ? "0" : nodeAPercentPoolDic.getValue()); |
| | | nodeAPercentPoolDicCnt = nodeAPercentPoolDicCnt.add(nodeAPercentCnt); |
| | | nodeAPercentPoolDic.setValue(nodeAPercentPoolDicCnt.toString()); |
| | | dataDictionaryCustomMapper.updateById(nodeAPercentPoolDic); |
| | | |
| | | BigDecimal nodeAPercentCntAva = superNodePoolPerk(nodeAPercentCnt, NodeCodeEnum.SUPER_NODE.getCode(), FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode()); |
| | | |
| | | if(nodeAPercentCnt.compareTo(nodeAPercentCntAva) > 0){ |
| | | DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity( |
| | | 1L, |
| | | nodeAPercentCnt.subtract(nodeAPercentCntAva), |
| | | FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlowAva); |
| | | dappWalletService.updateWalletMineWithLock(nodeAPercentCnt.subtract(nodeAPercentCntAva), |
| | | 1L,1); |
| | | } |
| | | /** |
| | | * 5%基金会 |
| | | */ |
| | | DataDictionaryCustom foundationAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.FOUNDATION_A_PERCENT.getType(), |
| | | PoolEnum.FOUNDATION_A_PERCENT.getCode() |
| | | ); |
| | | BigDecimal foundationAPercent = new BigDecimal(StrUtil.isEmpty(foundationAPercentDic.getValue()) ? "0.05" : foundationAPercentDic.getValue()); |
| | | BigDecimal foundationAPercentCnt = realCnt.multiply(foundationAPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | //生成一条5%基金会的资金流水记录 |
| | | DappFundFlowEntity foundationAPercentFundFlow = new DappFundFlowEntity( |
| | | 1L, |
| | | foundationAPercentCnt, |
| | | FundFlowEnum.FOUNDATION_A_PERCENT.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(foundationAPercentFundFlow); |
| | | //用户的A币账户增加memberGetACnt数量 |
| | | dappWalletService.updateWalletMineWithLock(foundationAPercentCnt,1L,1); |
| | | /** |
| | | * 10%级差奖 |
| | | */ |
| | | DataDictionaryCustom levelAPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.LEVEL_A_PERCENT.getType(), |
| | | PoolEnum.LEVEL_A_PERCENT.getCode() |
| | | ); |
| | | BigDecimal levelAPercent = new BigDecimal(StrUtil.isEmpty(levelAPercentDic.getValue()) ? "0.1" : levelAPercentDic.getValue()); |
| | | BigDecimal levelAPercentCnt = realCnt.multiply(levelAPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | //生成一条10%级差奖进入10%级差奖底池的资金流水记录 |
| | | DappFundFlowEntity levelAPercentCntFundFlow = new DappFundFlowEntity( |
| | | 1L, |
| | | levelAPercentCnt, |
| | | FundFlowEnum.LEVEL_A_PERCENT_CNT.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | chergeRecordId); |
| | | dappFundFlowDao.insert(levelAPercentCntFundFlow); |
| | | chainProducer.sendAntACoinInLevelMsg(levelAPercentCntFundFlow.getId()); |
| | | |
| | | /** |
| | | * 更新用户为有效用户 |
| | | */ |
| | | dappMemberDao.updateMemberActiveStatus(1,memberId); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void AntACoinAPollInMsg(Long id) { |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | //金额 |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | //目标地址 |
| | | String address = AppContants.ADDRESS_A_POOL_PEOJECT; |
| | | /** |
| | | * 发起USDT转账 |
| | | */ |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(address, amount); |
| | | if(StrUtil.isEmpty(hash)){ |
| | | return; |
| | | } |
| | | log.info("{},{}",id,hash); |
| | | dappFundFlowEntity.setFromHash(hash); |
| | | dappFundFlowEntity.setStatus(2); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String address = AppContants.ADDRESS_A_POOL_PEOJECT; |
| | | /** |
| | | * 发起USDT转账 |
| | | */ |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(address, new BigDecimal("0.01")); |
| | | } |
| | | |
| | | @Override |
| | | public void AntACoinBPollInMsg(Long id) { |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | //金额 |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | //目标地址 |
| | | String address = AppContants.ADDRESS_B_POOL_PEOJECT; |
| | | /** |
| | | * 发起USDT转账 |
| | | */ |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(address, amount); |
| | | if(StrUtil.isEmpty(hash)){ |
| | | return; |
| | | } |
| | | log.info("{},{}",id,hash); |
| | | dappFundFlowEntity.setFromHash(hash); |
| | | dappFundFlowEntity.setStatus(2); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void antACoinInNodeMsg(Long id) { |
| | | /** |
| | | * 全网节点99名.享受全网5%分红 |
| | | */ |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | //金额 |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | /** |
| | | * 获取全网的超级节点个数 |
| | | */ |
| | | List<DappMemberNodeEntity> dappMemberNodeEntities = dappMemberNodeMapper.selectNodeByNodeCode(NodeCodeEnum.SUPER_NODE.getCode()); |
| | | if(CollUtil.isNotEmpty(dappMemberNodeEntities)){ |
| | | BigDecimal divide = amount.divide(new BigDecimal(dappMemberNodeEntities.size()), 4, BigDecimal.ROUND_DOWN); |
| | | for(DappMemberNodeEntity dappMemberNodeEntity : dappMemberNodeEntities){ |
| | | Long memberId = dappMemberNodeEntity.getMemberId(); |
| | | |
| | | DappFundFlowEntity nodeAPercentFundFlow = new DappFundFlowEntity( |
| | | memberId, |
| | | divide, |
| | | FundFlowEnum.NODE_A_PERCENT_TO_MEMBER.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | dappFundFlowEntity.getSystemProfitId()); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlow); |
| | | //用户的A币账户增加divide数量 |
| | | dappWalletService.updateWalletMineWithLock(divide,memberId,1); |
| | | } |
| | | dappFundFlowEntity.setFromHash("已分成"+dappMemberNodeEntities.size()+"人"); |
| | | }else{ |
| | | dappFundFlowEntity.setFromHash("已分成0人"); |
| | | dappWalletService.updateWalletMineWithLock(amount,1L,1); |
| | | } |
| | | dappFundFlowEntity.setStatus(2); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void antACoinInLevelMsg(Long id) { |
| | | /** |
| | | * DAO1.考核小区业绩5000USDT 享受团队新增业绩2% |
| | | * DAO2.伞下不同部门产生2个DAO1.享受团队新增业绩3% |
| | | * DAO3.伞下不同部门2个DAO2.享受团队新增业绩4%,全网加权分红1% |
| | | * DAO4.两个不同部门DAO3.享受团队新增业绩5%,全网1%分红。 |
| | | * DAO5.两个不同部门DAO4.享受团队新增业绩6%,全网1%加权分红 |
| | | * 平级奖.DAO5平级享受全网1%加权分红. |
| | | * |
| | | * DAO5直推DAO5平级拿一代,视为平级奖,享受原有DAO5一个点,额外再加一个点分红。享受双份收益,合计2%加权分红 |
| | | */ |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | /** |
| | | * 极差总金额 |
| | | */ |
| | | BigDecimal amountTC = dappFundFlowEntity.getAmount(); |
| | | |
| | | Long systemProfitId = dappFundFlowEntity.getSystemProfitId(); |
| | | DappChargeUsdtEntity dappChargeUsdtEntity = dappChargeUsdtMapper.selectById(systemProfitId); |
| | | Long memberId = dappChargeUsdtEntity.getMemberId(); |
| | | DappMemberEntity mallMember = dappMemberDao.selectById(memberId); |
| | | |
| | | /** |
| | | * 团队下不同代理级别获取不用的比例新增业绩补贴 |
| | | */ |
| | | if(StrUtil.isNotEmpty(mallMember.getRefererIds())){ |
| | | |
| | | String referrerIds = mallMember.getRefererIds(); |
| | | List<String> referrerIdList = StrUtil.splitTrim(referrerIds, ","); |
| | | if(CollUtil.isNotEmpty(referrerIdList)){ |
| | | List<DappMemberEntity> mallMemberTeamPerk = dappMemberDao.selectByInviteIds(referrerIdList); |
| | | |
| | | if(CollUtil.isNotEmpty(mallMemberTeamPerk)){ |
| | | //初始级别 |
| | | String levelNormal = MemberLevelEnum.NODE_1.getType(); |
| | | //初始团队新增业绩补贴 |
| | | BigDecimal teamIncomePerkNormal = BigDecimal.ZERO; |
| | | //补贴总数 |
| | | BigDecimal teamIncomePerkTotal = BigDecimal.ZERO; |
| | | |
| | | for(DappMemberEntity teamPerkMember : mallMemberTeamPerk){ |
| | | String level = teamPerkMember.getAccountType(); |
| | | //比较两个级别的大小,level大于levelNormal返回1 |
| | | int compareMin = MemberLevelEnum.NODE_1.compareLevel(level, levelNormal); |
| | | int compareMax = MemberLevelEnum.NODE_1.compareLevel(MemberLevelEnum.NODE_5.getType(), level); |
| | | if(compareMin >= 1 && compareMax >= 1){ |
| | | Long teamPerkMemberId = teamPerkMember.getId(); |
| | | DataDictionaryCustom teamPerkMemberDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | "NODE_PERK", level); |
| | | |
| | | NodePerk nodePerk = JSONObject.parseObject(teamPerkMemberDic.getValue(), NodePerk.class); |
| | | BigDecimal teamIncomePerk = nodePerk.getTeamIncomePerk(); |
| | | //极差 |
| | | teamIncomePerk = teamIncomePerk.subtract(teamIncomePerkNormal); |
| | | |
| | | BigDecimal teamIncomePerkAmount = amountTC.multiply(teamIncomePerk).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal nodeAPercentFundFlowFlag = this.getAndUpdateMemberPerk(teamPerkMemberId, teamIncomePerkAmount); |
| | | if(nodeAPercentFundFlowFlag.compareTo(BigDecimal.ZERO) > 0){ |
| | | DappFundFlowEntity nodeAPercentFundFlow = new DappFundFlowEntity( |
| | | teamPerkMemberId, |
| | | nodeAPercentFundFlowFlag, |
| | | FundFlowEnum.LEVEL_A_PERCENT_CNT_MEMBER.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | dappFundFlowEntity.getSystemProfitId()); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlow); |
| | | //用户的A币账户增加divide数量 |
| | | dappWalletService.updateWalletMineWithLock(nodeAPercentFundFlowFlag,teamPerkMemberId,1); |
| | | //累加补贴总数 |
| | | teamIncomePerkTotal = teamIncomePerkTotal.add(nodeAPercentFundFlowFlag); |
| | | } |
| | | |
| | | //初始级别变成当前遍历的会员的级别 |
| | | levelNormal = level; |
| | | //初始新增业绩补贴比例变成当前会员级别的补贴比例 |
| | | teamIncomePerkNormal = nodePerk.getTeamIncomePerk(); |
| | | } |
| | | } |
| | | //更新总数据 |
| | | dappFundFlowEntity.setFromHash("已分成"+teamIncomePerkTotal.setScale(4,BigDecimal.ROUND_DOWN)); |
| | | dappFundFlowEntity.setStatus(2); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | BigDecimal subtract = amountTC.subtract(teamIncomePerkTotal); |
| | | //用户的A币账户增加divide数量 |
| | | if(amountTC.compareTo(teamIncomePerkTotal) > 0){ |
| | | DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity( |
| | | 1L, |
| | | subtract, |
| | | FundFlowEnum.LEVEL_A_PERCENT_CNT_MEMBER.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | systemProfitId); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlowAva); |
| | | dappWalletService.updateWalletMineWithLock(subtract, |
| | | 1L,1); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 极差的dao3、dao4、dao5级别全网分红入自己的底池,每天按20%平分 |
| | | */ |
| | | //获取新增数量 |
| | | DataDictionaryCustom nodeThreeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_3.getType(), |
| | | PoolEnum.NODE_3.getCode()); |
| | | NodePerk nodePerk = JSONObject.parseObject(nodeThreeDic.getValue(), NodePerk.class); |
| | | BigDecimal averagePerk = nodePerk.getAveragePerk(); |
| | | BigDecimal averagePerkCnt = amountTC.multiply(averagePerk).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal averagePerkCntAva = nodePoolPerk(averagePerkCnt, MemberLevelEnum.NODE_3.getType(), FundFlowEnum.DAO_3_NODE_PERK.getCode()); |
| | | |
| | | //用户的A币账户增加divide数量 |
| | | if(averagePerkCnt.compareTo(averagePerkCntAva) > 0){ |
| | | DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity( |
| | | 1L, |
| | | averagePerkCnt.subtract(averagePerkCntAva), |
| | | FundFlowEnum.DAO_3_NODE_PERK.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | systemProfitId); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlowAva); |
| | | dappWalletService.updateWalletMineWithLock(averagePerkCnt.subtract(averagePerkCntAva), |
| | | 1L,1); |
| | | } |
| | | //生成流水记录 |
| | | DappFundFlowEntity nodeThreeFundFlow = new DappFundFlowEntity( |
| | | 1L, |
| | | averagePerkCnt, |
| | | FundFlowEnum.DAO_3_CNT_MEMBER.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | dappChargeUsdtEntity.getId()); |
| | | dappFundFlowDao.insert(nodeThreeFundFlow); |
| | | //更新底池 |
| | | DataDictionaryCustom nodeThreePoolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_3_POOL.getType(), |
| | | PoolEnum.NODE_3_POOL.getCode()); |
| | | BigDecimal nodeThreePool = new BigDecimal(nodeThreePoolDic.getValue()); |
| | | nodeThreePool = nodeThreePool.add(averagePerkCnt).setScale(4,BigDecimal.ROUND_DOWN); |
| | | nodeThreePoolDic.setValue(nodeThreePool.toString()); |
| | | dataDictionaryCustomMapper.updateById(nodeThreePoolDic); |
| | | |
| | | DataDictionaryCustom nodeFourDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_4.getType(), |
| | | PoolEnum.NODE_4.getCode()); |
| | | NodePerk nodeFourDicPerk = JSONObject.parseObject(nodeFourDic.getValue(), NodePerk.class); |
| | | BigDecimal averagePerkFour = nodeFourDicPerk.getAveragePerk(); |
| | | BigDecimal averagePerkFourCnt = amountTC.multiply(averagePerkFour).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal averagePerkFourCntAva = nodePoolPerk(averagePerkFourCnt, MemberLevelEnum.NODE_4.getType(), FundFlowEnum.DAO_4_NODE_PERK.getCode()); |
| | | //用户的A币账户增加divide数量 |
| | | if(averagePerkFourCnt.compareTo(averagePerkFourCntAva) > 0){ |
| | | DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity( |
| | | 1L, |
| | | averagePerkFourCnt.subtract(averagePerkFourCntAva), |
| | | FundFlowEnum.DAO_4_NODE_PERK.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | systemProfitId); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlowAva); |
| | | dappWalletService.updateWalletMineWithLock(averagePerkFourCnt.subtract(averagePerkFourCntAva), |
| | | 1L,1); |
| | | } |
| | | DappFundFlowEntity nodeFourFundFlow = new DappFundFlowEntity( |
| | | 1L, |
| | | averagePerkFourCnt, |
| | | FundFlowEnum.DAO_4_CNT_MEMBER.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | dappChargeUsdtEntity.getId()); |
| | | dappFundFlowDao.insert(nodeFourFundFlow); |
| | | DataDictionaryCustom nodeFourPoolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_4_POOL.getType(), |
| | | PoolEnum.NODE_4_POOL.getCode()); |
| | | BigDecimal nodeFourPool = new BigDecimal(nodeFourPoolDic.getValue()); |
| | | nodeFourPool = nodeFourPool.add(averagePerkFourCnt).setScale(4,BigDecimal.ROUND_DOWN); |
| | | nodeFourPoolDic.setValue(nodeFourPool.toString()); |
| | | dataDictionaryCustomMapper.updateById(nodeFourPoolDic); |
| | | |
| | | DataDictionaryCustom nodeFiveDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_5.getType(), |
| | | PoolEnum.NODE_5.getCode()); |
| | | NodePerk nodeFiveDicPerk = JSONObject.parseObject(nodeFiveDic.getValue(), NodePerk.class); |
| | | BigDecimal averagePerkFive = nodeFiveDicPerk.getAveragePerk(); |
| | | BigDecimal averagePerkFiveCnt = amountTC.multiply(averagePerkFive).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal averagePerkFiveCntAva = nodePoolPerk(averagePerkFiveCnt, MemberLevelEnum.NODE_5.getType(), FundFlowEnum.DAO_5_NODE_PERK.getCode()); |
| | | //用户的A币账户增加divide数量 |
| | | if(averagePerkFiveCnt.compareTo(averagePerkFiveCntAva) > 0){ |
| | | DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity( |
| | | 1L, |
| | | averagePerkFiveCnt.subtract(averagePerkFiveCntAva), |
| | | FundFlowEnum.DAO_5_NODE_PERK.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | systemProfitId); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlowAva); |
| | | dappWalletService.updateWalletMineWithLock(averagePerkFiveCnt.subtract(averagePerkFiveCntAva), |
| | | 1L,1); |
| | | } |
| | | DappFundFlowEntity nodeFiveFundFlow = new DappFundFlowEntity( |
| | | 1L, |
| | | averagePerkFiveCnt, |
| | | FundFlowEnum.DAO_5_CNT_MEMBER.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | dappChargeUsdtEntity.getId()); |
| | | dappFundFlowDao.insert(nodeFiveFundFlow); |
| | | DataDictionaryCustom nodeFivePoolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_5_POOL.getType(), |
| | | PoolEnum.NODE_5_POOL.getCode()); |
| | | BigDecimal nodeFivePool = new BigDecimal(nodeFivePoolDic.getValue()); |
| | | nodeFivePool = nodeFivePool.add(averagePerkFiveCnt).setScale(4,BigDecimal.ROUND_DOWN); |
| | | nodeFivePoolDic.setValue(nodeFivePool.toString()); |
| | | dataDictionaryCustomMapper.updateById(nodeFivePoolDic); |
| | | |
| | | /** |
| | | * DAO5直推DAO5平级拿一代,视为平级奖,享受原有DAO5一个点,额外再加一个点分红。享受双份收益,合计2%加权分红 |
| | | */ |
| | | DataDictionaryCustom nodeFiveEqualsDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_5_EQUALS.getType(), |
| | | PoolEnum.NODE_5_EQUALS.getCode()); |
| | | BigDecimal nodeFiveEquals = new BigDecimal(nodeFiveEqualsDic.getValue()); |
| | | BigDecimal nodeFiveEqualsCnt = amountTC.multiply(nodeFiveEquals).setScale(4, BigDecimal.ROUND_DOWN); |
| | | |
| | | BigDecimal nodeFiveEqualsCntAva = nodePoolEqualsPerk(nodeFiveEqualsCnt, MemberLevelEnum.NODE_5.getType(), FundFlowEnum.DAO_5_NODE_EQUALS_PERK.getCode()); |
| | | //用户的A币账户增加divide数量 |
| | | if(nodeFiveEqualsCnt.compareTo(nodeFiveEqualsCntAva) > 0){ |
| | | DappFundFlowEntity nodeAPercentFundFlowAva = new DappFundFlowEntity( |
| | | 1L, |
| | | nodeFiveEqualsCnt.subtract(nodeFiveEqualsCntAva), |
| | | FundFlowEnum.DAO_5_NODE_EQUALS_PERK.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | systemProfitId); |
| | | dappFundFlowDao.insert(nodeAPercentFundFlowAva); |
| | | dappWalletService.updateWalletMineWithLock(nodeFiveEqualsCnt.subtract(nodeFiveEqualsCntAva), |
| | | 1L,1); |
| | | } |
| | | DappFundFlowEntity nodeFiveEqualsFundFlow = new DappFundFlowEntity( |
| | | 1L, |
| | | nodeFiveEqualsCnt, |
| | | FundFlowEnum.DAO_5_CNT_EQUALS_MEMBER.getCode(), |
| | | 2, |
| | | BigDecimal.ZERO, |
| | | null, |
| | | dappChargeUsdtEntity.getId()); |
| | | dappFundFlowDao.insert(nodeFiveEqualsFundFlow); |
| | | DataDictionaryCustom nodeFiveEqualsPoolDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.NODE_5_EQUALS_POOL.getType(), |
| | | PoolEnum.NODE_5_EQUALS_POOL.getCode()); |
| | | BigDecimal nodeFiveEqualsPool = new BigDecimal(nodeFiveEqualsPoolDic.getValue()); |
| | | nodeFiveEqualsPool = nodeFiveEqualsPool.add(nodeFiveEqualsCnt).setScale(4,BigDecimal.ROUND_DOWN); |
| | | nodeFiveEqualsPoolDic.setValue(nodeFiveEqualsPool.toString()); |
| | | dataDictionaryCustomMapper.updateById(nodeFiveEqualsPoolDic); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getAndUpdateMemberPerk(Long memberId, BigDecimal amount) { |
| | | /** |
| | | * 把币本位换算成金本位 |
| | | */ |
| | | DataDictionaryCustom coinAPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_PRICE.getType(), |
| | | PoolEnum.COIN_A_PRICE.getCode() |
| | | ); |
| | | BigDecimal coinAPrice = new BigDecimal(coinAPriceDic.getValue()); |
| | | //实际补贴的USDT数量 = 币的数量 * 当前A币的价格 |
| | | BigDecimal realUsdtAmount = amount.multiply(coinAPrice); |
| | | //实际补贴额度USDT |
| | | BigDecimal perkAmount = BigDecimal.ZERO; |
| | | DappUsdtPerkEntity dappUsdtPerkEntity = dappUsdtPerkEntityMapper.selectByMemberId(memberId); |
| | | if(ObjectUtil.isEmpty(dappUsdtPerkEntity)){ |
| | | return BigDecimal.ZERO; |
| | | } |
| | | //用户剩余补贴额度 |
| | | BigDecimal amountSurplus = dappUsdtPerkEntity.getAmount(); |
| | | if(BigDecimal.ZERO.compareTo(amountSurplus) >= 0){ |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | if(realUsdtAmount.compareTo(amountSurplus) >= 0){ |
| | | perkAmount = amountSurplus; |
| | | }else{ |
| | | perkAmount = realUsdtAmount; |
| | | } |
| | | if(BigDecimal.ZERO.compareTo(perkAmount) < 0){ |
| | | amountSurplus = amountSurplus.subtract(perkAmount); |
| | | dappUsdtPerkEntity.setAmount(amountSurplus); |
| | | dappUsdtPerkEntityMapper.updateById(dappUsdtPerkEntity); |
| | | }else{ |
| | | return BigDecimal.ZERO; |
| | | } |
| | | |
| | | /** |
| | | * 把金本位换算成币本位 |
| | | */ |
| | | perkAmount = perkAmount.divide(coinAPrice,4,BigDecimal.ROUND_DOWN); |
| | | return perkAmount; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal nodePoolPerk(BigDecimal nodeThreePoolDicCnt, String type, int typeFlow) { |
| | | BigDecimal realPerkAmount = BigDecimal.ZERO; |
| | | List<DappMemberEntity> dappMemberEntities = new ArrayList<>(); |
| | | //获取type级别的会员 |
| | | if(MemberLevelEnum.MEMBER.getType().equals(type)){ |
| | | dappMemberEntities = dappMemberDao.selectMemberByNotAccountType(type); |
| | | }else{ |
| | | dappMemberEntities = dappMemberDao.selectMemberByAccountType(type); |
| | | } |
| | | //每日补贴总数 |
| | | BigDecimal nodePerk = nodeThreePoolDicCnt; |
| | | // BigDecimal nodePerk = nodeThreePoolDicCnt.multiply(AppContants.NODE_PERK_PERCENT); |
| | | if(CollUtil.isNotEmpty(dappMemberEntities)){ |
| | | //每人的补贴 |
| | | BigDecimal averagePerk = nodePerk.divide(new BigDecimal(dappMemberEntities.size()), 4, BigDecimal.ROUND_DOWN); |
| | | |
| | | for(DappMemberEntity dappMemberEntity : dappMemberEntities){ |
| | | BigDecimal fundFlowToMemberFlag = this.getAndUpdateMemberPerk(dappMemberEntity.getId(), averagePerk); |
| | | if(fundFlowToMemberFlag.compareTo(BigDecimal.ZERO) > 0){ |
| | | //生成一条50%客户秒到的资金流水记录 |
| | | DappFundFlowEntity fundFlowToMember = new DappFundFlowEntity( |
| | | dappMemberEntity.getId(), |
| | | fundFlowToMemberFlag, |
| | | typeFlow, |
| | | 2, |
| | | BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(fundFlowToMember); |
| | | //用户的A币账户增加memberGetACnt数量 |
| | | dappWalletService.updateWalletMineWithLock(fundFlowToMemberFlag,dappMemberEntity.getId(),1); |
| | | |
| | | realPerkAmount = realPerkAmount.add(fundFlowToMemberFlag); |
| | | } |
| | | } |
| | | } |
| | | return realPerkAmount; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal nodePoolEqualsPerk(BigDecimal nodeFivePoolDicCnt, String type, int code) { |
| | | |
| | | BigDecimal realPerkAmount = BigDecimal.ZERO; |
| | | //获取type级别的会员 |
| | | List<DappMemberEntity> dappMemberEntities = dappMemberDao.selectMemberByAccountTypeAnd(type); |
| | | //每日补贴总数 |
| | | BigDecimal nodePerk = nodeFivePoolDicCnt.multiply(AppContants.NODE_PERK_PERCENT); |
| | | if(CollUtil.isNotEmpty(dappMemberEntities)){ |
| | | //每人的补贴 |
| | | BigDecimal averagePerk = nodePerk.divide(new BigDecimal(dappMemberEntities.size()), 4, BigDecimal.ROUND_DOWN); |
| | | |
| | | for(DappMemberEntity dappMemberEntity : dappMemberEntities){ |
| | | BigDecimal fundFlowToMemberFlag = this.getAndUpdateMemberPerk(dappMemberEntity.getId(), averagePerk); |
| | | if(fundFlowToMemberFlag.compareTo(BigDecimal.ZERO) > 0){ |
| | | DappFundFlowEntity fundFlowToMember = new DappFundFlowEntity( |
| | | dappMemberEntity.getId(), |
| | | fundFlowToMemberFlag, |
| | | code, |
| | | 2, |
| | | BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(fundFlowToMember); |
| | | //用户的A币账户增加memberGetACnt数量 |
| | | dappWalletService.updateWalletMineWithLock(fundFlowToMemberFlag,dappMemberEntity.getId(),1); |
| | | |
| | | realPerkAmount = realPerkAmount.add(fundFlowToMemberFlag); |
| | | } |
| | | } |
| | | } |
| | | return realPerkAmount; |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal superNodePoolPerk(BigDecimal nodeFivePoolDicCnt, String code, int code1) { |
| | | BigDecimal realPerkAmount = BigDecimal.ZERO; |
| | | //获取type级别的会员 |
| | | List<DappMemberNodeEntity> dappMemberNodeEntities = dappMemberNodeMapper.selectNodeByNodeCode(NodeCodeEnum.SUPER_NODE.getCode()); |
| | | //每日补贴总数 |
| | | // BigDecimal nodePerk = nodeFivePoolDicCnt.multiply(AppContants.NODE_PERK_PERCENT); |
| | | BigDecimal nodePerk = nodeFivePoolDicCnt; |
| | | if(CollUtil.isNotEmpty(dappMemberNodeEntities)){ |
| | | //每人的补贴 |
| | | BigDecimal averagePerk = nodePerk.divide(new BigDecimal(dappMemberNodeEntities.size()), 4, BigDecimal.ROUND_DOWN); |
| | | |
| | | for(DappMemberNodeEntity dappMemberNodeEntity : dappMemberNodeEntities){ |
| | | |
| | | DappFundFlowEntity fundFlowToMember = new DappFundFlowEntity( |
| | | dappMemberNodeEntity.getMemberId(), |
| | | averagePerk, |
| | | code1, |
| | | 2, |
| | | BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(fundFlowToMember); |
| | | //用户的A币账户增加memberGetACnt数量 |
| | | dappWalletService.updateWalletMineWithLock(averagePerk,dappMemberNodeEntity.getMemberId(),1); |
| | | |
| | | realPerkAmount = realPerkAmount.add(averagePerk); |
| | | } |
| | | } |
| | | return realPerkAmount; |
| | | } |
| | | |
| | | @Override |
| | | public void selectAndInsertDics() { |
| | | selectAndInsertDic(PoolEnum.TRANSFER_A_AUSD_PRICE.getType(),PoolEnum.TRANSFER_A_AUSD_PRICE.getCode(),"0.01","AUSD价格"); |
| | | selectAndInsertDic(PoolEnum.TRANSFER_A_AUSD_PERCENT.getType(),PoolEnum.TRANSFER_A_AUSD_PERCENT.getCode(),"0.1","买入A,10%的AUSD比例"); |
| | | selectAndInsertDic(PoolEnum.WALLET_COIN_OUT_PERCENT.getType(),PoolEnum.WALLET_COIN_OUT_PERCENT.getCode(),"0.3","30%回流底池溢价"); |
| | | selectAndInsertDic(PoolEnum.WALLET_COIN_TO_USDT_PERCENT.getType(),PoolEnum.WALLET_COIN_TO_USDT_PERCENT.getCode(),"0.01","闪对钱包USDT提现1%手续费.(扣USDT)"); |
| | | selectAndInsertDic(PoolEnum.WALLET_MINE_TO_COIN_PERCENT.getType(),PoolEnum.WALLET_MINE_TO_COIN_PERCENT.getCode(),"0.03","资产转闪对钱包 3%扣币"); |
| | | selectAndInsertDic(PoolEnum.NODE_5_EQUALS_POOL.getType(),PoolEnum.NODE_5_EQUALS_POOL.getCode(),"0","节点5的平级奖励底池"); |
| | | selectAndInsertDic(PoolEnum.NODE_5_EQUALS.getType(),PoolEnum.NODE_5_EQUALS.getCode(),"0.1","节点5的平级奖励比例"); |
| | | selectAndInsertDic( |
| | | PoolEnum.NODE_5.getType(), |
| | | PoolEnum.NODE_5.getCode(), |
| | | JSONObject.toJSONString(new NodePerk(BigDecimal.ZERO,2,new BigDecimal("0.6"),new BigDecimal("0.1"))), |
| | | "节点5的奖励"); |
| | | selectAndInsertDic( |
| | | PoolEnum.NODE_4.getType(), |
| | | PoolEnum.NODE_4.getCode(), |
| | | JSONObject.toJSONString(new NodePerk(BigDecimal.ZERO,2,new BigDecimal("0.5"),new BigDecimal("0.1"))), |
| | | "节点4的奖励"); |
| | | selectAndInsertDic( |
| | | PoolEnum.NODE_3.getType(), |
| | | PoolEnum.NODE_3.getCode(), |
| | | JSONObject.toJSONString(new NodePerk(BigDecimal.ZERO,2,new BigDecimal("0.4"),new BigDecimal("0.1"))), |
| | | "节点3的奖励"); |
| | | selectAndInsertDic( |
| | | PoolEnum.NODE_2.getType(), |
| | | PoolEnum.NODE_2.getCode(), |
| | | JSONObject.toJSONString(new NodePerk(BigDecimal.ZERO,2,new BigDecimal("0.3"),new BigDecimal("0.1"))), |
| | | "节点2的奖励"); |
| | | selectAndInsertDic( |
| | | PoolEnum.NODE_1.getType(), |
| | | PoolEnum.NODE_1.getCode(), |
| | | JSONObject.toJSONString(new NodePerk(new BigDecimal(5000),3,new BigDecimal("0.2"),new BigDecimal("0.1"))), |
| | | "节点1的奖励"); |
| | | |
| | | selectAndInsertDic(PoolEnum.NODE_5_POOL.getType(),PoolEnum.NODE_5_POOL.getCode(),"0","节点5的奖励底池"); |
| | | selectAndInsertDic(PoolEnum.NODE_4_POOL.getType(),PoolEnum.NODE_4_POOL.getCode(),"0","节点4的奖励底池"); |
| | | selectAndInsertDic(PoolEnum.NODE_3_POOL.getType(),PoolEnum.NODE_3_POOL.getCode(),"0","节点3的奖励底池"); |
| | | |
| | | selectAndInsertDic(PoolEnum.COIN_A_CNT.getType(),PoolEnum.COIN_A_CNT.getCode(),"0","A币币本位底池 -A币的数量"); |
| | | selectAndInsertDic(PoolEnum.COIN_A_USDT_PRICE.getType(),PoolEnum.COIN_A_USDT_PRICE.getCode(),"0","A币金本位底池-usdt数量"); |
| | | selectAndInsertDic(PoolEnum.COIN_A_PRICE.getType(),PoolEnum.COIN_A_PRICE.getCode(),"0","A币的价格"); |
| | | |
| | | selectAndInsertDic(PoolEnum.LEVEL_A_PERCENT.getType(),PoolEnum.LEVEL_A_PERCENT.getCode(),"0.1","10%极差奖"); |
| | | selectAndInsertDic(PoolEnum.FOUNDATION_A_PERCENT.getType(),PoolEnum.FOUNDATION_A_PERCENT.getCode(),"0.05","5%基金会"); |
| | | selectAndInsertDic(PoolEnum.NODE_A_PERCENT_POOL.getType(),PoolEnum.NODE_A_PERCENT_POOL.getCode(),"0","5%节点资金池"); |
| | | selectAndInsertDic(PoolEnum.NODE_A_PERCENT.getType(),PoolEnum.NODE_A_PERCENT.getCode(),"0.05","5%节点"); |
| | | selectAndInsertDic(PoolEnum.DIRECT_A_PERCENT.getType(),PoolEnum.DIRECT_A_PERCENT.getCode(),"0.1","10%直推"); |
| | | selectAndInsertDic(PoolEnum.POOL_MEMBER_A_PERCENT.getType(),PoolEnum.POOL_MEMBER_A_PERCENT.getCode(),"0.2","每日所有人平分的底池20%,即底池总数 * 比例"); |
| | | selectAndInsertDic(PoolEnum.POOL_ALL_MEMBER_A_CNT.getType(),PoolEnum.POOL_ALL_MEMBER_A_CNT.getCode(),"0","所有人平分的底池"); |
| | | selectAndInsertDic(PoolEnum.POOL_ALL_MEMBER_A_PERCENT.getType(),PoolEnum.POOL_ALL_MEMBER_A_PERCENT.getCode(),"0","全网加权分红20%,即所有人平分的底池"); |
| | | selectAndInsertDic(PoolEnum.MEMBER_GET_A_PERCENT.getType(),PoolEnum.MEMBER_GET_A_PERCENT.getCode(),"0.5","客户秒到50%的A币比例"); |
| | | selectAndInsertDic(PoolEnum.PRODUCE_A_PERCENT.getType(),PoolEnum.PRODUCE_A_PERCENT.getCode(),"0.7","实际产生A币的数量的比例"); |
| | | selectAndInsertDic(PoolEnum.USDT_B_PERCENT.getType(),PoolEnum.USDT_B_PERCENT.getCode(),"0.1","10%进入B底池的比例"); |
| | | selectAndInsertDic(PoolEnum.USDT_A_PERCENT.getType(),PoolEnum.USDT_A_PERCENT.getCode(),"0.9","90%进入A底池的比例"); |
| | | } |
| | | |
| | | @Override |
| | | public void selectAndInsertDic(String type, String code, String value, String description) { |
| | | DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(type, code); |
| | | if(ObjectUtil.isEmpty(dic)){ |
| | | dic = new DataDictionaryCustom(type,code,value,description); |
| | | dataDictionaryCustomMapper.insert(dic); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void antACoinOutMsg(Long id) { |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | //金额 |
| | | BigDecimal amount = dappFundFlowEntity.getAmount(); |
| | | |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | //目标地址 |
| | | String address = dappMemberEntity.getAddress(); |
| | | /** |
| | | * 发起USDT转账 |
| | | */ |
| | | log.info("amount:{},address:{}",amount,address); |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT_W_POOL.name()).transfer(address, amount); |
| | | if(StrUtil.isEmpty(hash)){ |
| | | return; |
| | | } |
| | | log.info("{},{}",id,hash); |
| | | dappFundFlowEntity.setFromHash(hash); |
| | | dappFundFlowEntity.setStatus(2); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void aCoinFire() { |
| | | /** |
| | | * A币技术做到资产钱包燃烧,闪兑钱包也要燃烧0.1%每小时 |
| | | */ |
| | | BigDecimal totalCnt = BigDecimal.ZERO; |
| | | //闪兑钱包 |
| | | List<DappWalletCoinEntity> walletCoinEntities = dappWalletCoinDao.selectAmountThanZero(); |
| | | if(CollUtil.isNotEmpty(walletCoinEntities)){ |
| | | for(DappWalletCoinEntity dappWalletCoinEntity : walletCoinEntities){ |
| | | BigDecimal availableAmount = dappWalletCoinEntity.getAvailableAmount(); |
| | | BigDecimal fireCnt = availableAmount.multiply(new BigDecimal("0.001")).setScale(4,BigDecimal.ROUND_DOWN); |
| | | dappWalletService.updateWalletCoinWithLock(fireCnt,dappWalletCoinEntity.getMemberId(),2); |
| | | totalCnt = totalCnt.add(fireCnt); |
| | | } |
| | | } |
| | | //资产钱包 |
| | | List<DappWalletMineEntity> walletMineEntities = dappWalletMineDao.selectAmountThanZero(); |
| | | if(CollUtil.isNotEmpty(walletMineEntities)){ |
| | | for(DappWalletMineEntity dappWalletMineEntity : walletMineEntities){ |
| | | BigDecimal availableAmount = dappWalletMineEntity.getAvailableAmount(); |
| | | BigDecimal fireCnt = availableAmount.multiply(new BigDecimal("0.001")).setScale(4,BigDecimal.ROUND_DOWN); |
| | | dappWalletService.updateWalletMineWithLock(fireCnt,dappWalletMineEntity.getMemberId(),2); |
| | | totalCnt = totalCnt.add(fireCnt); |
| | | } |
| | | } |
| | | if(BigDecimal.ZERO.compareTo(totalCnt) >= 0){ |
| | | return; |
| | | } |
| | | |
| | | totalCnt = totalCnt.setScale(4,BigDecimal.ROUND_DOWN); |
| | | /** |
| | | * 插入每小时燃烧的资金流水 |
| | | */ |
| | | DappFundFlowEntity dappFundFlowEntity = new DappFundFlowEntity(1L, totalCnt, FundFlowEnum.A_COIN_FIRE.getCode(), 2, BigDecimal.ZERO); |
| | | dappFundFlowDao.insert(dappFundFlowEntity); |
| | | /** |
| | | * 更新A币的价格 |
| | | */ |
| | | DataDictionaryCustom coinACntDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_CNT.getType(), |
| | | PoolEnum.COIN_A_CNT.getCode()); |
| | | BigDecimal coinACnt = new BigDecimal(coinACntDic.getValue()); |
| | | coinACnt = coinACnt.subtract(totalCnt); |
| | | coinACntDic.setValue(coinACnt.toString()); |
| | | dataDictionaryCustomMapper.updateById(coinACntDic); |
| | | |
| | | DataDictionaryCustom coinAUsdtDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_USDT_PRICE.getType(), |
| | | PoolEnum.COIN_A_USDT_PRICE.getCode()); |
| | | BigDecimal coinAUsdt = new BigDecimal(coinAUsdtDic.getValue()); |
| | | |
| | | DataDictionaryCustom coinAPriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_PRICE.getType(), |
| | | PoolEnum.COIN_A_PRICE.getCode()); |
| | | BigDecimal coinAPrice = coinAUsdt.divide(coinACnt,8,BigDecimal.ROUND_DOWN); |
| | | coinAPriceDic.setValue(coinAPrice.toString()); |
| | | dataDictionaryCustomMapper.updateById(coinAPriceDic); |
| | | |
| | | chainProducer.sendAntKLineMsg(0); |
| | | } |
| | | |
| | | @Override |
| | | public void antMemberLevelMsg(Long memberId) { |
| | | DappMemberEntity member = dappMemberDao.selectById(memberId); |
| | | if(StrUtil.isBlank(member.getRefererIds())) { |
| | | return; |
| | | } |
| | | |
| | | List<String> ids = StrUtil.split(member.getRefererIds(), ','); |
| | | List<DappMemberEntity> parentMembers = dappMemberDao.selectByInviteIds(ids); |
| | | for (DappMemberEntity parent : parentMembers) { |
| | | //DAO5不能再升级了 |
| | | if(parent.getAccountType().equals(MemberLevelEnum.NODE_5.getType())){ |
| | | continue; |
| | | } |
| | | /** |
| | | * 升级到董事就无法升级了 |
| | | */ |
| | | String nextLevelName = MemberLevelEnum.MEMBER.getNextLevel(parent.getAccountType()); |
| | | int levelCode = MemberLevelEnum.MEMBER.getLevelCode(nextLevelName); |
| | | |
| | | DataDictionaryCustom newLevelDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode("NODE_PERK", nextLevelName); |
| | | if(ObjectUtil.isEmpty(newLevelDic)){ |
| | | continue; |
| | | } |
| | | NodePerk nodeFiveDicPerk = JSONObject.parseObject(newLevelDic.getValue(), NodePerk.class); |
| | | |
| | | //需要判断小区业绩 |
| | | if( MemberLevelEnum.NODE_1.getType().equals(nextLevelName)){ |
| | | if (!directMemberCnt(parent, nodeFiveDicPerk)) { |
| | | continue; |
| | | } |
| | | if (!teamIncome(parent, nodeFiveDicPerk)) { |
| | | continue; |
| | | } |
| | | }else{ |
| | | if (!agentCntFinish(parent, nodeFiveDicPerk)) { |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | parent.setAccountType(nextLevelName); |
| | | dappMemberDao.updateById(parent); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void aKlineJobHour() { |
| | | DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_PRICE.getType(), |
| | | PoolEnum.COIN_A_PRICE.getCode() |
| | | ); |
| | | |
| | | BigDecimal coinAPrice = new BigDecimal(dataDictionaryCustom.getValue()); |
| | | DateTime dateTime = DateUtil.offsetHour(DateUtil.date(), -1); |
| | | String format = DateUtil.format(dateTime, "yyyy-MM-dd HH"); |
| | | List<String> dataDayStrList = new ArrayList<>(); |
| | | dataDayStrList.add(format); |
| | | List<DappAKlineEntity> dappAKlineEntities = dappAKlineMapper.selectListByTypeAndHour(dataDayStrList); |
| | | |
| | | DappAKlineEntity dappAKlineEntity = new DappAKlineEntity(); |
| | | dappAKlineEntity.setType(1); |
| | | if(CollUtil.isNotEmpty(dappAKlineEntities)){ |
| | | |
| | | List<BigDecimal> openPriceList = dappAKlineEntities.stream().map(DappAKlineEntity::getOpenPrice).collect(Collectors.toList()); |
| | | BigDecimal openPrice = openPriceList.stream().min(BigDecimal::compareTo).get(); |
| | | dappAKlineEntity.setOpenPrice(openPrice); |
| | | //获取最高价 |
| | | List<BigDecimal> highestPriceList = dappAKlineEntities.stream().map(DappAKlineEntity::getHighestPrice).collect(Collectors.toList()); |
| | | BigDecimal highestPrice = highestPriceList.stream().max(BigDecimal::compareTo).get(); |
| | | dappAKlineEntity.setHighestPrice(highestPrice); |
| | | |
| | | List<BigDecimal> lowestPriceList = dappAKlineEntities.stream().map(DappAKlineEntity::getLowestPrice).collect(Collectors.toList()); |
| | | BigDecimal lowestPrice = lowestPriceList.stream().min(BigDecimal::compareTo).get(); |
| | | dappAKlineEntity.setLowestPrice(lowestPrice); |
| | | }else{ |
| | | dappAKlineEntity.setOpenPrice(coinAPrice); |
| | | dappAKlineEntity.setHighestPrice(coinAPrice); |
| | | dappAKlineEntity.setLowestPrice(coinAPrice); |
| | | } |
| | | DappAKlineEntity oldOne = dappAKlineMapper.selectOneByType(); |
| | | if(ObjectUtil.isNotEmpty(oldOne)){ |
| | | dappAKlineEntity.setClosePrice(oldOne.getClosePrice()); |
| | | }else{ |
| | | dappAKlineEntity.setClosePrice(coinAPrice); |
| | | } |
| | | dappAKlineMapper.insert(dappAKlineEntity); |
| | | |
| | | chainProducer.sendAntKLineMsg(1); |
| | | } |
| | | |
| | | @Override |
| | | public void aKlineJobDay() { |
| | | DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_PRICE.getType(), |
| | | PoolEnum.COIN_A_PRICE.getCode() |
| | | ); |
| | | BigDecimal coinAPrice = new BigDecimal(dataDictionaryCustom.getValue()); |
| | | /** |
| | | * 当前时间往前推12小时,得到前一天的所有时间的yyyy-MM-dd格式的所有小时的记录 |
| | | */ |
| | | DappAKlineEntity dappAKlineEntity = new DappAKlineEntity(); |
| | | dappAKlineEntity.setType(2); |
| | | DateTime dateTime = DateUtil.offsetHour(DateUtil.date(), -12); |
| | | String format = DateUtil.format(dateTime, "yyyy-MM-dd"); |
| | | List<String> dataDayStrList = new ArrayList<>(); |
| | | dataDayStrList.add(format); |
| | | List<DappAKlineEntity> dappAKlineEntities = dappAKlineMapper.selectListByTypeAndTime(1,dataDayStrList); |
| | | if(CollUtil.isNotEmpty(dappAKlineEntities)){ |
| | | List<BigDecimal> openPriceList = dappAKlineEntities.stream().map(DappAKlineEntity::getOpenPrice).collect(Collectors.toList()); |
| | | BigDecimal openPrice = openPriceList.stream().min(BigDecimal::compareTo).get(); |
| | | dappAKlineEntity.setOpenPrice(openPrice); |
| | | //获取最高价 |
| | | List<BigDecimal> highestPriceList = dappAKlineEntities.stream().map(DappAKlineEntity::getHighestPrice).collect(Collectors.toList()); |
| | | BigDecimal highestPrice = highestPriceList.stream().max(BigDecimal::compareTo).get(); |
| | | dappAKlineEntity.setHighestPrice(highestPrice); |
| | | |
| | | List<BigDecimal> lowestPriceList = dappAKlineEntities.stream().map(DappAKlineEntity::getLowestPrice).collect(Collectors.toList()); |
| | | BigDecimal lowestPrice = lowestPriceList.stream().min(BigDecimal::compareTo).get(); |
| | | dappAKlineEntity.setLowestPrice(lowestPrice); |
| | | }else{ |
| | | dappAKlineEntity.setOpenPrice(coinAPrice); |
| | | dappAKlineEntity.setHighestPrice(coinAPrice); |
| | | dappAKlineEntity.setLowestPrice(coinAPrice); |
| | | } |
| | | dappAKlineEntity.setClosePrice(coinAPrice); |
| | | dappAKlineMapper.insert(dappAKlineEntity); |
| | | |
| | | chainProducer.sendAntKLineMsg(2); |
| | | //周 |
| | | String week = DateUtil.dayOfWeekEnum(DateUtil.date()).toChinese(); |
| | | if("星期日".equals(week)){ |
| | | /** |
| | | * 当前时间往前推6天,得到前一周的所有时间的yyyy-MM-dd格式的所有type为日的记录 |
| | | */ |
| | | DappAKlineEntity dappAKlineEntityDay = new DappAKlineEntity(); |
| | | dappAKlineEntityDay.setType(3); |
| | | |
| | | List<String> dataWeekStrList = new ArrayList<>(); |
| | | String one = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -6), "yyyy-MM-dd"); |
| | | String two = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -5), "yyyy-MM-dd"); |
| | | String three = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -4), "yyyy-MM-dd"); |
| | | String four = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -3), "yyyy-MM-dd"); |
| | | String five = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -2), "yyyy-MM-dd"); |
| | | String six = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -1), "yyyy-MM-dd"); |
| | | dataWeekStrList.add(one); |
| | | dataWeekStrList.add(two); |
| | | dataWeekStrList.add(three); |
| | | dataWeekStrList.add(four); |
| | | dataWeekStrList.add(five); |
| | | dataWeekStrList.add(six); |
| | | List<DappAKlineEntity> dappAKlineEntitieDays = dappAKlineMapper.selectListByTypeAndTime(2,dataWeekStrList); |
| | | if(CollUtil.isNotEmpty(dappAKlineEntitieDays)){ |
| | | |
| | | List<BigDecimal> openPriceList = dappAKlineEntitieDays.stream().map(DappAKlineEntity::getOpenPrice).collect(Collectors.toList()); |
| | | BigDecimal openPrice = openPriceList.stream().min(BigDecimal::compareTo).get(); |
| | | dappAKlineEntityDay.setOpenPrice(openPrice); |
| | | //获取最高价 |
| | | List<BigDecimal> highestPriceList = dappAKlineEntitieDays.stream().map(DappAKlineEntity::getHighestPrice).collect(Collectors.toList()); |
| | | BigDecimal highestPrice = highestPriceList.stream().max(BigDecimal::compareTo).get(); |
| | | dappAKlineEntityDay.setHighestPrice(highestPrice); |
| | | |
| | | List<BigDecimal> lowestPriceList = dappAKlineEntitieDays.stream().map(DappAKlineEntity::getLowestPrice).collect(Collectors.toList()); |
| | | BigDecimal lowestPrice = lowestPriceList.stream().min(BigDecimal::compareTo).get(); |
| | | dappAKlineEntityDay.setLowestPrice(lowestPrice); |
| | | }else{ |
| | | dappAKlineEntityDay.setOpenPrice(coinAPrice); |
| | | dappAKlineEntityDay.setHighestPrice(coinAPrice); |
| | | dappAKlineEntityDay.setLowestPrice(coinAPrice); |
| | | } |
| | | dappAKlineEntityDay.setClosePrice(coinAPrice); |
| | | dappAKlineMapper.insert(dappAKlineEntityDay); |
| | | |
| | | chainProducer.sendAntKLineMsg(3); |
| | | } |
| | | //月 |
| | | int month = DateUtil.dayOfMonth(DateUtil.date()); |
| | | if(1 == month){ |
| | | /** |
| | | * 当前时间往前推10天,得到前一月的所有时间的yyyy-MM-dd格式的所有type为周的记录 |
| | | */ |
| | | DappAKlineEntity dappAKlineEntityWeek = new DappAKlineEntity(); |
| | | dappAKlineEntityWeek.setType(4); |
| | | |
| | | List<String> dataMonthStrList = new ArrayList<>(); |
| | | String one = DateUtil.format(DateUtil.offsetDay(DateUtil.date(), -10), "yyyy-MM-dd"); |
| | | dataMonthStrList.add(one); |
| | | List<DappAKlineEntity> dappAKlineEntitieWeeks = dappAKlineMapper.selectListByTypeAndTime(3,dataMonthStrList); |
| | | if(CollUtil.isNotEmpty(dappAKlineEntitieWeeks)){ |
| | | List<BigDecimal> openPriceList = dappAKlineEntitieWeeks.stream().map(DappAKlineEntity::getOpenPrice).collect(Collectors.toList()); |
| | | BigDecimal openPrice = openPriceList.stream().min(BigDecimal::compareTo).get(); |
| | | dappAKlineEntityWeek.setOpenPrice(openPrice); |
| | | //获取最高价 |
| | | List<BigDecimal> highestPriceList = dappAKlineEntitieWeeks.stream().map(DappAKlineEntity::getHighestPrice).collect(Collectors.toList()); |
| | | BigDecimal highestPrice = highestPriceList.stream().max(BigDecimal::compareTo).get(); |
| | | dappAKlineEntityWeek.setHighestPrice(highestPrice); |
| | | |
| | | List<BigDecimal> lowestPriceList = dappAKlineEntitieWeeks.stream().map(DappAKlineEntity::getLowestPrice).collect(Collectors.toList()); |
| | | BigDecimal lowestPrice = lowestPriceList.stream().min(BigDecimal::compareTo).get(); |
| | | dappAKlineEntityWeek.setLowestPrice(lowestPrice); |
| | | }else{ |
| | | dappAKlineEntityWeek.setOpenPrice(coinAPrice); |
| | | dappAKlineEntityWeek.setHighestPrice(coinAPrice); |
| | | dappAKlineEntityWeek.setLowestPrice(coinAPrice); |
| | | } |
| | | dappAKlineEntityWeek.setClosePrice(coinAPrice); |
| | | dappAKlineMapper.insert(dappAKlineEntityWeek); |
| | | |
| | | chainProducer.sendAntKLineMsg(4); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void antKLineMsg(int type) { |
| | | /** |
| | | * 根据类型去更新redis的K线数据 |
| | | */ |
| | | String redisKey = null; |
| | | if(1 == type){ |
| | | redisKey = AppContants.K_LINE_HOUR; |
| | | }else if(2 == type){ |
| | | redisKey = AppContants.K_LINE_DAY; |
| | | }else if(3 == type){ |
| | | redisKey = AppContants.K_LINE_WEEK; |
| | | }else if(4 == type){ |
| | | redisKey = AppContants.K_LINE_MONTH; |
| | | }else if(0 == type){ |
| | | createKDate(); |
| | | return; |
| | | }else{ |
| | | return; |
| | | } |
| | | List<cn.hutool.json.JSONObject> objects = new ArrayList<>(); |
| | | List<AKLineLimitVo> akLineLimitVos = dappAKlineMapper.selectListByTypeAndLimit(type, AppContants.K_LINE_LIMIT); |
| | | if(CollUtil.isNotEmpty(akLineLimitVos)){ |
| | | Collections.reverse(akLineLimitVos); |
| | | for(AKLineLimitVo akLineLimitVo : akLineLimitVos){ |
| | | cn.hutool.json.JSONObject parseObj = JSONUtil.parseObj(akLineLimitVo); |
| | | objects.add(parseObj); |
| | | } |
| | | redisUtils.del(redisKey); |
| | | redisUtils.set(redisKey, objects.toString()); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void antKLineABMsg(Long id) { |
| | | log.info("{}",id); |
| | | //获取对应的流水记录 |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectInfoById(id); |
| | | if(ObjectUtil.isEmpty(dappFundFlowEntity)){ |
| | | return; |
| | | } |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | DappFundFlowEntity dappFundFlow = dappFundFlowDao.selectById(id); |
| | | //金额 |
| | | BigDecimal amount = dappFundFlow.getAmount(); |
| | | //目标地址 |
| | | String address = null; |
| | | if(5 == dappFundFlowEntity.getType()){ |
| | | address = AppContants.ADDRESS_A_POOL_PEOJECT; |
| | | }else if(6 == dappFundFlowEntity.getType()){ |
| | | address = AppContants.ADDRESS_B_POOL_PEOJECT; |
| | | }else{ |
| | | return; |
| | | } |
| | | /** |
| | | * 发起USDT转账 |
| | | */ |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT_A_POOL.name()).transfer(address, amount); |
| | | if(StrUtil.isEmpty(hash)){ |
| | | return; |
| | | } |
| | | log.info("{},{}",id,hash); |
| | | dappFundFlow.setFromHash(hash); |
| | | dappFundFlowDao.updateById(dappFundFlow); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 生成当前分钟的k线数据,type为0 |
| | | */ |
| | | public void createKDate(){ |
| | | DappAKlineEntity dappAKlineEntity = new DappAKlineEntity(); |
| | | dappAKlineEntity.setType(0); |
| | | DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | PoolEnum.COIN_A_PRICE.getType(), |
| | | PoolEnum.COIN_A_PRICE.getCode() |
| | | ); |
| | | BigDecimal coinAPrice = new BigDecimal(dataDictionaryCustom.getValue()); |
| | | |
| | | /** |
| | | * 获取最新一条小时或者分钟的数据 |
| | | */ |
| | | DappAKlineEntity oldOne = dappAKlineMapper.selectOneByType(); |
| | | if(ObjectUtil.isNotEmpty(oldOne)){ |
| | | dappAKlineEntity.setOpenPrice(oldOne.getClosePrice()); |
| | | }else{ |
| | | dappAKlineEntity.setOpenPrice(coinAPrice); |
| | | } |
| | | dappAKlineEntity.setLowestPrice(coinAPrice); |
| | | dappAKlineEntity.setHighestPrice(coinAPrice); |
| | | dappAKlineEntity.setClosePrice(coinAPrice); |
| | | dappAKlineMapper.insert(dappAKlineEntity); |
| | | |
| | | } |
| | | |
| | | // public static void main(String[] args) { |
| | | // |
| | | // int month = DateUtil.dayOfMonth(DateUtil.date()); |
| | | // String s = DateUtil.dayOfWeekEnum(DateUtil.date()).toChinese(); |
| | | // System.out.println(s); |
| | | // System.out.println(month); |
| | | // } |
| | | |
| | | /** |
| | | * 判断直推人数是否达标 |
| | | * |
| | | * @param member |
| | | * @return |
| | | */ |
| | | private boolean directMemberCnt(DappMemberEntity member, NodePerk agentInfo) { |
| | | List<DappMemberEntity> childs = dappMemberDao.selectMemberInfoByRefererId(member.getInviteId()); |
| | | if (CollUtil.isEmpty(childs)) { |
| | | return false; |
| | | } |
| | | |
| | | if (childs.size() >= agentInfo.getDirectCnt()) { |
| | | return true; |
| | | } |
| | | |
| | | log.info("用户:{}直推数量未达标, 当前等级:{}, 当前数量:{}, 目标数量:{}", member.getAddress(), member.getAccountType(), childs.size(), agentInfo.getDirectCnt()); |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 判断下级代理数量是否达标 |
| | | * |
| | | * @return |
| | | */ |
| | | private boolean agentCntFinish(DappMemberEntity member, NodePerk agentInfo) { |
| | | if (agentInfo.getDirectCnt() == null || agentInfo.getDirectCnt() == 0) { |
| | | return true; |
| | | } |
| | | // 直推用户 |
| | | List<DappMemberEntity> childs = dappMemberDao.selectMemberInfoByRefererId(member.getInviteId()); |
| | | if (CollUtil.isEmpty(childs)) { |
| | | return false; |
| | | } |
| | | // 用户团队达到指定代理数量,且都不在同一条线 |
| | | int i = 0; |
| | | for (DappMemberEntity child : childs) { |
| | | List<DappMemberEntity> mallMembers = dappMemberDao.selectChildAgentListByAccountType(child.getInviteId(), member.getAccountType()); |
| | | if (CollUtil.isNotEmpty(mallMembers)) { |
| | | i++; |
| | | } |
| | | } |
| | | if (i >= agentInfo.getDirectCnt()) { |
| | | return true; |
| | | } |
| | | log.info("用户:{}代理数量未达标, 当前等级:{}, 当前数量:{}, 目标数量:{}", member.getAddress(), member.getAccountType(), i, agentInfo.getDirectCnt()); |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 团队业绩是否达标 |
| | | * 除去直属的最大的一个业绩团队,剩余的所有业绩之和 |
| | | * |
| | | * @param |
| | | * @param agentInfo |
| | | * @return |
| | | */ |
| | | private boolean teamIncome(DappMemberEntity member, NodePerk agentInfo) { |
| | | BigDecimal teamIncome = agentInfo.getTeamIncome(); |
| | | //业绩集合 |
| | | List<BigDecimal> list = new ArrayList<>(); |
| | | //总业绩 |
| | | BigDecimal teamIncomeMax = BigDecimal.ZERO; |
| | | //所有直推团队,就是这个会员的所有区域的业绩。 |
| | | |
| | | // 直推用户 |
| | | List<DappMemberEntity> childs = dappMemberDao.selectMemberInfoByRefererId(member.getInviteId()); |
| | | List<String> childsInviteIds = childs.stream().map(DappMemberEntity::getInviteId).collect(Collectors.toList()); |
| | | for(String inviteId : childsInviteIds){ |
| | | BigDecimal totalIncomeMember = dappMemberDao.selectAllAchieveByInviteId(inviteId); |
| | | teamIncomeMax = teamIncomeMax.add(totalIncomeMember); |
| | | list.add(totalIncomeMember); |
| | | } |
| | | //去掉一个最大区的业绩 |
| | | BigDecimal bigMax = list.stream().max(BigDecimal::compareTo).get(); |
| | | teamIncomeMax = teamIncomeMax.subtract(bigMax); |
| | | |
| | | if (teamIncomeMax.compareTo(teamIncome) >= 0) { |
| | | return true; |
| | | } |
| | | log.info("用户:{}团队业绩未达标, 当前等级:{}, 当前业绩:{}, 目标业绩:{}", member.getAddress(), member.getAccountType(), teamIncomeMax, teamIncome); |
| | | return false; |
| | | } |
| | | |
| | | } |