| | |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.AsyncCjService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | teamHdPerk(teamPercent,divideEveryUsdt,divideEveryCoin); |
| | | } |
| | | |
| | | @Override |
| | | public void confirmOrder(DappFundFlowEntity dappFundFlow) { |
| | | Long id = dappFundFlow.getId(); |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id); |
| | | Integer status = dappFundFlowEntity.getStatus(); |
| | | if(1 != status){ |
| | | return; |
| | | } |
| | | Integer type = dappFundFlowEntity.getType(); |
| | | BigDecimal amount = dappFundFlowEntity.getAmount().negate(); |
| | | if(BigDecimal.ZERO.compareTo(amount) >=0){ |
| | | amount = amount.negate(); |
| | | } |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | if(FlowTypeEnum.USDT_OUT.getValue() == type){ |
| | | //USDT转账 |
| | | String transfer = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(dappMemberEntity.getAddress(), amount); |
| | | int retryTime = 0;//重试次数 |
| | | while (StrUtil.isEmpty(transfer)) { |
| | | // 休眠2s |
| | | try { |
| | | Thread.sleep(2000); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if(retryTime < 3){ |
| | | transfer = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(dappMemberEntity.getAddress(), amount); |
| | | } |
| | | retryTime ++ ; |
| | | } |
| | | if(StrUtil.isNotEmpty(transfer)){ |
| | | dappFundFlowEntity.setFromHash(transfer); |
| | | dappFundFlowEntity.setStatus(2); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | }else{ |
| | | dappFundFlowEntity.setStatus(1); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | } |
| | | }else if(FlowTypeEnum.DAI_BI_OUT.getValue() == type){ |
| | | //代币转账 |
| | | String transfer = ChainService.getInstance(ChainEnum.BSC_GFA.name()).transfer(dappMemberEntity.getAddress(), amount); |
| | | if(StrUtil.isNotEmpty(transfer)){ |
| | | dappFundFlowEntity.setFromHash(transfer); |
| | | dappFundFlowEntity.setStatus(2); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | }else{ |
| | | dappFundFlowEntity.setStatus(1); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | } |
| | | }else{ |
| | | return; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void confirmCancel(DappFundFlowEntity dappFundFlow) { |
| | | Long id = dappFundFlow.getId(); |
| | | DappFundFlowEntity dappFundFlowEntity = dappFundFlowDao.selectById(id); |
| | | Integer status = dappFundFlowEntity.getStatus(); |
| | | if(1 != status){ |
| | | return; |
| | | } |
| | | Integer type = dappFundFlowEntity.getType(); |
| | | BigDecimal amount = dappFundFlowEntity.getAmount().negate(); |
| | | if(BigDecimal.ZERO.compareTo(amount) >=0){ |
| | | amount = amount.negate(); |
| | | } |
| | | Long memberId = dappFundFlowEntity.getMemberId(); |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectById(memberId); |
| | | |
| | | dappFundFlowEntity.setStatus(DappFundFlowEntity.WITHDRAW_STATUS_DISAGREE); |
| | | dappFundFlowDao.updateById(dappFundFlowEntity); |
| | | if(FlowTypeEnum.USDT_OUT.getValue() == type){ |
| | | dappMemberEntity.setUsdtBalance(dappMemberEntity.getUsdtBalance().add(amount)); |
| | | dappMemberDao.updateUsdtBalanceWithVersion(dappMemberEntity); |
| | | }else if(FlowTypeEnum.DAI_BI_OUT.getValue() == type){ |
| | | dappMemberEntity.setBalance(dappMemberEntity.getBalance().add(amount)); |
| | | dappMemberDao.updateBalanceWithVersion(dappMemberEntity); |
| | | }else{ |
| | | return; |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String transfer = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer("0xCEBfd36e03BD80c7015Cbad17eFfBc33d2923FF3", new BigDecimal("0.1")); |
| | | // BigInteger bigInteger = org.web3j.utils.Convert.toWei("35", org.web3j.utils.Convert.Unit.GWEI).toBigInteger(); |
| | | // System.out.println(bigInteger); |
| | | } |
| | | |
| | | public void teamHdPerk(int teamPercent,BigDecimal divideEveryUsdt,BigDecimal divideEveryCoin){ |
| | | //3%用于团队业绩计算 |
| | | BigDecimal teamPercentMultiply = new BigDecimal(teamPercent); |
| | |
| | | // DataDicEnum.GFA_COIN.getValue(), |
| | | // 1); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String format = StrUtil.format(FlowTypeEnum.HUA_DIAN_GEREN.getDescrition(), 100); |
| | | System.out.println(format); |
| | | } |
| | | |
| | | /** |