| | |
| | | package cc.mrbird.febs.dapp.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.ShareCodeUtil; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.chain.ContractEventService; |
| | | import cc.mrbird.febs.dapp.chain.EthUsdtContract; |
| | | import cc.mrbird.febs.dapp.entity.DappFundFlowEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappOnlineTransferEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappTransferRecordEntity; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappMemberDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappMemberFundMapper; |
| | | import cc.mrbird.febs.dapp.mapper.DappOnlineTransferDao; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import cc.mrbird.febs.dapp.service.DappSystemService; |
| | | import cc.mrbird.febs.dapp.utils.OnlineTransferUtil; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Resource |
| | | private DappMemberDao dappMemberDao; |
| | | @Resource |
| | | private DappMemberFundMapper dappMemberFundMapper; |
| | | |
| | | @Resource |
| | | private DappMemberService dappMemberService; |
| | |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(e.from); |
| | | fromMember.setBalance(balance); |
| | | dappMemberService.updateById(fromMember); |
| | | } else { |
| | | fromMember = dappMemberService.insertMember(e.from, null); |
| | | } |
| | | |
| | | BigInteger tokens = e.tokens; |
| | | BigDecimal amount = BigDecimal.valueOf(tokens.intValue()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN); |
| | | BigDecimal amount = new BigDecimal(tokens.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN); |
| | | |
| | | // 如果转账对象地址不为源池地址,且对象地址在系统中存在并未激活,则激活用户 |
| | | // 如果转账对象地址不为源池地址,注册该用户并绑定上下级关系 |
| | | if (!e.to.equals(ChainEnum.BSC_TFC_SOURCE.getAddress().toLowerCase())) { |
| | | DappMemberEntity toMember = dappMemberDao.selectByAddress(e.to, null); |
| | | if (toMember == null) { |
| | | // toMember = dappMemberService.insertMember(e.to, fromMember.getInviteId()); |
| | | return; |
| | | toMember = dappMemberService.insertMember(e.to, fromMember.getInviteId()); |
| | | } |
| | | |
| | | if (toMember.getActiveStatus() == 2) { |
| | | toMember.setActiveStatus(1); |
| | | } |
| | | // if (toMember.getActiveStatus() == 2) { |
| | | // toMember.setActiveStatus(1); |
| | | // } |
| | | // 更新余额 |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(e.to); |
| | | toMember.setBalance(balance); |
| | |
| | | fundFlow.setTargetAmount(transferAmount); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | |
| | | // 划点分配 |
| | | chainProducer.sendDitribProfit(fundFlow.getId()); |
| | | |
| | | OnlineTransferUtil.addTransfer(e.from, transferAmount, fundFlow.getType(), 1, ChainEnum.BSC_USDT_SOURCE.name(), AppContants.SYMBOL_USDT, fundFlow.getId().toString()); |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void coinReward(EthUsdtContract.CoinRewardEventResponse e) { |
| | | if (e.adr == null) { |
| | | return; |
| | | } |
| | | /** |
| | | * 根据地址去查询数据库是否已经注册 |
| | | * 生成对应的产矿记录 |
| | | * 生成对应的产矿流水 |
| | | */ |
| | | String address = e.adr; |
| | | String blockHash = e.blockHash; |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectByAddress(address, null); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | int decimals = ChainService.getInstance(ChainEnum.BSC_GFA.name()).decimals(); |
| | | BigDecimal amount = new BigDecimal(e.amount.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal price = new BigDecimal(e.price.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal usdtTarget = new BigDecimal(e.usdtTarget.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal coinTarget = new BigDecimal(e.coinTarget.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal usdtCoin = new BigDecimal(e.usdtCoin.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigInteger lastMineTime = e.lastMineTime; |
| | | |
| | | QueryWrapper<DappMemberFund> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("block_hash",blockHash); |
| | | objectQueryWrapper.eq("address",address); |
| | | objectQueryWrapper.eq("price",price); |
| | | objectQueryWrapper.eq("usdt_target",usdtTarget); |
| | | objectQueryWrapper.eq("coin_target",coinTarget); |
| | | List<DappMemberFund> dappMemberFunds = dappMemberFundMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isEmpty(dappMemberFunds)){ |
| | | Long memberId = dappMemberEntity.getId(); |
| | | DappMemberFund dappMemberFund = new DappMemberFund(); |
| | | dappMemberFund.setMemberId(memberId); |
| | | dappMemberFund.setAddress(address); |
| | | dappMemberFund.setBlockHash(blockHash); |
| | | dappMemberFund.setAmount(amount); |
| | | dappMemberFund.setPrice(price); |
| | | dappMemberFund.setUsdtTarget(usdtTarget); |
| | | dappMemberFund.setCoinTarget(coinTarget); |
| | | dappMemberFund.setUsdtCoin(usdtCoin); |
| | | dappMemberFund.setLastMineTime(lastMineTime.toString()); |
| | | dappMemberFundMapper.insert(dappMemberFund); |
| | | |
| | | DappFundFlowEntity fundFlowTuiJian1 = new DappFundFlowEntity( |
| | | memberId, |
| | | usdtTarget, |
| | | FlowTypeEnum.ZHIYA_CHA_CHU.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | StrUtil.format("金本位{},价格{}。",usdtTarget,price)); |
| | | |
| | | dappFundFlowDao.insert(fundFlowTuiJian1); |
| | | |
| | | DappFundFlowEntity fundFlowTuiJian2 = new DappFundFlowEntity( |
| | | memberId, |
| | | coinTarget, |
| | | FlowTypeEnum.ZHIYA_CHA_CHU.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | StrUtil.format("币本位{},价格{}。",coinTarget,price)); |
| | | dappFundFlowDao.insert(fundFlowTuiJian2); |
| | | log.info("本地交易:{},amount-{},price-{}", e.adr,amount,price); |
| | | } |
| | | } |
| | | } |