| | |
| | | public static final String REDIS_KEY_SYMBOL_DAILY_PRICE = "SYMBOL_DAILY_PRICE";
|
| | |
|
| | | public static final BigDecimal NFT_ACTIVE_PRICE = new BigDecimal("10");
|
| | |
|
| | | public static final String REDIS_KEY_TFC_NEW_PRICE = "TFC_NEW_PRICE";
|
| | | }
|
| | |
| | | @ApiOperation(value = "提现", notes = "提现") |
| | | @PostMapping(value = "/withdraw") |
| | | public FebsResponse withdraw(@RequestBody WithdrawDto withdrawDto) { |
| | | return new FebsResponse().success(); |
| | | dappWalletService.withdraw(withdrawDto); |
| | | return new FebsResponse().success().message("success"); |
| | | } |
| | | |
| | | @ApiOperation(value = "我的团队", notes = "我的团队") |
| | |
| | | redisUtils.hdel(AppContants.REDIS_KEY_SIGN, member.getAddress()); |
| | | return new FebsResponse().success(); |
| | | } |
| | | |
| | | @ApiOperation(value = "计算手续费", notes = "计算手续费") |
| | | @PostMapping(value = "/calPrice") |
| | | public FebsResponse calPrice(@RequestBody PriceDto priceDto) { |
| | | return new FebsResponse().success().data(dappWalletService.calPrice(priceDto)); |
| | | } |
| | | } |
| | |
| | | @ApiModelProperty(value = "每页数量") |
| | | private Integer pageSize = 10; |
| | | |
| | | @ApiModelProperty(value = "类型", example = "1-买入 2-矩阵收益 3-直推收益 4-保险池 5-提现") |
| | | @ApiModelProperty(value = "类型", example = "1-买入 2-矩阵收益 3-直推收益 4-保险池 5-提现 6-手续费充值 7-手续费扣除") |
| | | private Integer type; |
| | | } |
| | |
| | | private BigDecimal amount; |
| | | |
| | | /** |
| | | * 类型 1-买入 2-矩阵收益 3-直推收益 4-保险池 5-提现 |
| | | * 类型 1-买入 2-矩阵收益 3-直推收益 4-保险池 5-提现 6-手续费充值 7-手续费扣除 |
| | | */ |
| | | private Integer type; |
| | | |
| | |
| | | IPage<DappWalletMineEntity> selectInPage(@Param("record") DappWalletMineEntity walletMine, Page<DappWalletMineEntity> page); |
| | | |
| | | int updateBalance(@Param("totalAmount") BigDecimal totalAmount, @Param("availableAmount") BigDecimal availableAmount, @Param("memberId") Long memberId); |
| | | |
| | | int updateWithLock(@Param("record") DappWalletMineEntity dappWalletMineEntity); |
| | | } |
| | |
| | | * @param isReIn |
| | | */ |
| | | void putIntoProfit(Long memberId, int isReIn); |
| | | |
| | | void tfcNewPrice(String data); |
| | | } |
| | |
| | | |
| | | void updateWalletCoinWithLock(BigDecimal amount, Long memberId); |
| | | |
| | | void updateWalletMineWithLock(BigDecimal amount, Long memberId); |
| | | |
| | | } |
| | |
| | | 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.service.DappWalletService; |
| | | import cc.mrbird.febs.dapp.utils.OnlineTransferUtil; |
| | | import cc.mrbird.febs.rabbit.producer.ChainProducer; |
| | | import cn.hutool.core.collection.CollUtil; |
| | |
| | | public class BscCoinContractEvent implements ContractEventService { |
| | | |
| | | @Resource |
| | | private DappMemberDao dappMemberDao; |
| | | |
| | | @Resource |
| | | private DappMemberService dappMemberService; |
| | | |
| | | @Resource |
| | |
| | | @Resource |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Autowired |
| | | private DappSystemService dappSystemService; |
| | | |
| | | @Resource |
| | | private DappOnlineTransferDao dappOnlineTransferDao; |
| | | |
| | | @Resource |
| | | private ChainProducer chainProducer; |
| | | private DappWalletService dappWalletService; |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(Numeric.toBigInt("0x12e4e85")); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void compile(EthUsdtContract.TransferEventResponse e) { |
| | | if (e.to != null) { |
| | | if (e.to != null && e.to.equals(ChainEnum.BSC_TFC.getAddress().toLowerCase())) { |
| | | log.info("触发TFC监听"); |
| | | |
| | | try { |
| | |
| | | redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, e.log.getBlockNumber()); |
| | | int decimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals(); |
| | | |
| | | // 合约创建时,同时创建地址 |
| | | if ("0x0000000000000000000000000000000000000000".equals(e.from)) { |
| | | DappMemberEntity toMember = dappMemberDao.selectByAddress(e.to, null); |
| | | if (toMember == null) { |
| | | toMember = dappMemberService.insertMember(e.to, "0", "BSC", "admin"); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | // 更新余额 |
| | | DappMemberEntity fromMember = dappMemberService.findByAddress(e.from, null); |
| | | if (fromMember != null) { |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(e.from); |
| | | fromMember.setBalance(balance); |
| | | dappMemberService.updateById(fromMember); |
| | | } else { |
| | | fromMember = dappMemberService.insertMember(e.from, null); |
| | | if (fromMember == null) { |
| | | return; |
| | | } |
| | | |
| | | BigInteger tokens = e.tokens; |
| | | 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()); |
| | | } |
| | | |
| | | // if (toMember.getActiveStatus() == 2) { |
| | | // toMember.setActiveStatus(1); |
| | | // } |
| | | // 更新余额 |
| | | BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_TFC.name()).balanceOf(e.to); |
| | | toMember.setBalance(balance); |
| | | dappMemberService.updateById(toMember); |
| | | |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_ONLINE, AppContants.SYMBOL_COIN); |
| | | // 卖币 |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectByFromHash(e.log.getTransactionHash(), null); |
| | | if (fundFlow != null && fundFlow.getStatus() != 1) { |
| | | return; |
| | | } |
| | | |
| | | // 卖币 |
| | | if (e.to.equals(ChainEnum.BSC_TFC_SOURCE.getAddress().toLowerCase())) { |
| | | DappFundFlowEntity fundFlow = dappFundFlowDao.selectByFromHash(e.log.getTransactionHash(), null); |
| | | if (fundFlow != null && fundFlow.getStatus() != 1) { |
| | | if (fundFlow == null) { |
| | | List<DappFundFlowEntity> flows = dappFundFlowDao.selectFundFlowListByAddress(e.from, 1); |
| | | if (CollUtil.isEmpty(flows)) { |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_ONLINE, AppContants.SYMBOL_COIN); |
| | | log.info("本地无交易:{}", e.log.getTransactionHash()); |
| | | return; |
| | | } |
| | | |
| | | if (fundFlow == null) { |
| | | List<DappFundFlowEntity> flows = dappFundFlowDao.selectFundFlowListByAddress(e.from, 1); |
| | | if (CollUtil.isEmpty(flows)) { |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_ONLINE, AppContants.SYMBOL_COIN); |
| | | log.info("本地无交易:{}", e.log.getTransactionHash()); |
| | | return; |
| | | } |
| | | |
| | | boolean hasFlow = false; |
| | | for (DappFundFlowEntity flow : flows) { |
| | | if (flow.getStatus() == 1) { |
| | | if (amount.compareTo(flow.getAmount()) == 0) { |
| | | hasFlow = true; |
| | | fundFlow = flow; |
| | | fundFlow.setFromHash(e.log.getTransactionHash()); |
| | | break; |
| | | } |
| | | for (DappFundFlowEntity flow : flows) { |
| | | if (flow.getStatus() == 1) { |
| | | if (amount.compareTo(flow.getAmount()) == 0) { |
| | | fundFlow = flow; |
| | | fundFlow.setFromHash(e.log.getTransactionHash()); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!hasFlow) { |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_ONLINE, AppContants.SYMBOL_COIN); |
| | | return; |
| | | } |
| | | } |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_APPLICATION, AppContants.SYMBOL_COIN); |
| | | |
| | | if (fundFlow.getAmount().add(fundFlow.getFee()).compareTo(amount) != 0) { |
| | | return; |
| | | } |
| | | |
| | | BigDecimal newPrice = fundFlow.getNewestPrice(); |
| | | BigDecimal transferAmount = amount.multiply(newPrice); |
| | | |
| | | // 更改状态为已同步 |
| | | fundFlow.setStatus(2); |
| | | 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<>(); |
| | | map.put("batchNo", fundFlow.getId().toString()); |
| | | map.put("type", "flow"); |
| | | |
| | | // 发送转账消息 |
| | | chainProducer.sendOnlineTransfer(JSONObject.toJSONString(map)); |
| | | } |
| | | |
| | | if (fundFlow == null) { |
| | | return; |
| | | } |
| | | |
| | | // 更改状态为已同步 |
| | | fundFlow.setStatus(2); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | |
| | | dappWalletService.updateWalletMineWithLock(amount, fromMember.getId()); |
| | | } |
| | | } |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | boolean hasFlow = false; |
| | | for (DappFundFlowEntity flow : flows) { |
| | | if (flow.getStatus() == 1) { |
| | | if (amount.compareTo(flow.getAmount().multiply(flow.getNewestPrice()).setScale(4, RoundingMode.HALF_UP)) == 0) { |
| | | hasFlow = true; |
| | | fundFlow = flow; |
| | | fundFlow.setFromHash(e.log.getTransactionHash()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!hasFlow) { |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_ONLINE, "USDT"); |
| | | return; |
| | | } |
| | | } |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_APPLICATION, "USDT"); |
| | | |
| | | if (fundFlow == null) { |
| | | return; |
| | | } |
| | | |
| | | fundFlow.setAmount(fundFlow.getAmount().negate()); |
| | | // 更改状态为已同步 |
| | |
| | | walletCoin.setMemberId(member.getId()); |
| | | dappWalletCoinDao.insert(walletCoin); |
| | | |
| | | DappWalletMineEntity walletMine = new DappWalletMineEntity(); |
| | | walletMine.setMemberId(member.getId()); |
| | | dappWalletMineDao.insert(walletMine); |
| | | |
| | | if (StrUtil.isEmpty(refererId)) { |
| | | refererId = "0"; |
| | | // 若没有推荐人,则直接激活 |
| | |
| | | dappSystemDao.updateMineData(mineData); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void tfcNewPrice(String data) { |
| | | redisUtils.set(AppContants.REDIS_KEY_TFC_NEW_PRICE, new BigDecimal(data)); |
| | | } |
| | | } |
| | |
| | | WalletInfoVo walletInfo = new WalletInfoVo(); |
| | | List<DappMemberEntity> direct = dappMemberDao.selectChildMemberDirectOrNot(member.getInviteId(), 1); |
| | | DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(member.getId()); |
| | | DappWalletMineEntity walletMine = dappWalletMineDao.selectByMemberId(member.getId()); |
| | | |
| | | walletInfo.setDirectCnt(direct.size()); |
| | | walletInfo.setInviteId(member.getInviteId()); |
| | |
| | | walletInfo.setHasBuy(memberInfo.getActiveStatus()); |
| | | walletInfo.setOutCnt(memberInfo.getOutCnt()); |
| | | walletInfo.setProfit(dappFundFlowDao.selectProfitAmountByMemberId(member.getId())); |
| | | walletInfo.setTFCbalance(walletMine.getAvailableAmount()); |
| | | |
| | | return walletInfo; |
| | | } |
| | | |
| | |
| | | |
| | | chainProducer.sendAchieveTreeMsg(member.getId()); |
| | | } else { |
| | | int type = 1; |
| | | // 1-认购 2-充值tfc |
| | | if (transferDto.getType() == 2) { |
| | | type = 6; |
| | | } |
| | | if (transferDto.getId() == null) { |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount(), 1, 1, transferDto.getFee(), transferDto.getTxHash()); |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), transferDto.getAmount(), type, 1, transferDto.getFee(), transferDto.getTxHash()); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | return fundFlow.getId(); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public Map<String, BigDecimal> calPrice(PriceDto priceDto) { |
| | | return null; |
| | | String priceStr = redisUtils.getString(AppContants.REDIS_KEY_TFC_NEW_PRICE); |
| | | |
| | | Map<String, BigDecimal> data = new HashMap<>(); |
| | | data.put("fee", new BigDecimal(priceStr)); |
| | | return data; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public void withdraw(WithdrawDto withdrawDto) { |
| | | DappMemberEntity member = LoginUserUtil.getAppUser(); |
| | | |
| | | updateWalletCoinWithLock(withdrawDto.getAmount().negate(), member.getId()); |
| | | updateWalletMineWithLock(withdrawDto.getFee(), member.getId()); |
| | | |
| | | DappFundFlowEntity feeFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getFee().negate(), 7, 2, null, null); |
| | | dappFundFlowDao.insert(feeFlow); |
| | | |
| | | DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), withdrawDto.getAmount().negate(), 5, 2, withdrawDto.getFee(), null); |
| | | dappFundFlowDao.insert(fundFlow); |
| | | |
| | | String hash = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(member.getAddress(), withdrawDto.getAmount()); |
| | | fundFlow.setToHash(hash); |
| | | dappFundFlowDao.updateById(fundFlow); |
| | | |
| | | chainProducer.sendTfcFee(withdrawDto.getFee().toPlainString()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateWalletMineWithLock(BigDecimal amount, Long memberId) { |
| | | boolean isSuccess = false; |
| | | while(!isSuccess) { |
| | | DappWalletCoinEntity walletCoin = dappWalletCoinDao.selectByMemberId(memberId); |
| | | |
| | | walletCoin.setTotalAmount(walletCoin.getTotalAmount().add(amount)); |
| | | walletCoin.setAvailableAmount(walletCoin.getAvailableAmount().add(amount)); |
| | | |
| | | int i = dappWalletCoinDao.updateWithLock(walletCoin); |
| | | if (i > 0) { |
| | | isSuccess = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | @ApiModelProperty(value = "是否购买") |
| | | private Integer hasBuy; |
| | | |
| | | @ApiModelProperty(value = "手续费") |
| | | private BigDecimal TFCbalance; |
| | | } |
| | |
| | | |
| | | @Autowired |
| | | private ContractEventService bscUsdtContractEvent; |
| | | @Autowired |
| | | private ContractEventService bscCoinContractEvent; |
| | | |
| | | @Autowired |
| | | private RedisUtils redisUtils; |
| | |
| | | BigInteger section = BigInteger.valueOf(5000); |
| | | while (newest.subtract(block).compareTo(section) > -1) { |
| | | BigInteger end = block.add(section); |
| | | log.info("监听:[{} - {}]", block, end); |
| | | ChainService.contractEventListener(block, end, bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name()); |
| | | |
| | | BigInteger finalBlock = block; |
| | | new Thread(() -> { |
| | | log.info("监听:[{} - {}]", finalBlock, end); |
| | | ChainService.contractEventListener(finalBlock, end, bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name()); |
| | | ChainService.contractEventListener(finalBlock, bscCoinContractEvent, ChainEnum.BSC_TFC_LISTENER.name()); |
| | | }).start(); |
| | | |
| | | block = block.add(section); |
| | | if (block.compareTo(newest) > 0) { |
| | |
| | | } |
| | | } |
| | | ChainService.contractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name()); |
| | | ChainService.contractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC_LISTENER.name()); |
| | | |
| | | long end = System.currentTimeMillis(); |
| | | log.info("区块链监听启动完成, 消耗时间{}", end - start); |
| | |
| | | public static final String USER_BUY_REWARD = "queue_sdm_user_buy_reward"; |
| | | public static final String NFT_BOX = "queue_sdm_nft_box"; |
| | | public static final String ACHIEVE_TREE = "queue_sdm_achieve_tree"; |
| | | public static final String TFC_NEW_PRICE = "queue_tfc_new_price"; |
| | | } |
| | |
| | | USER_BUY_REWARD("exchange_sdm_user_buy_reward", "route_key_sdm_user_buy_reward", "queue_sdm_user_buy_reward"), |
| | | NFT_BOX("exchange_sdm_nft_box", "route_key_sdm_nft_box", "queue_sdm_nft_box"), |
| | | ACHIEVE_TREE("exchange_sdm_achieve_tree", "route_key_sdm_achieve_tree", "queue_sdm_achieve_tree"), |
| | | WITHDRAW_FEE("exchange_withdraw_fee", "route_key_withdraw_fee", "queue_withdraw_fee"); |
| | | WITHDRAW_FEE("exchange_withdraw_fee", "route_key_withdraw_fee", "queue_withdraw_fee"), |
| | | TFC_NEW_PRICE("exchange_tfc_new_price", "route_key_tfc_new_price", "queue_tfc_new_price"); |
| | | |
| | | private String exchange; |
| | | |
| | |
| | | return BindingBuilder.bind(withdrawFeeQueue()).to(withdrawFeeExchange()).with(QueueEnum.WITHDRAW_FEE.getRoute()); |
| | | } |
| | | // === 提现手续费 end === |
| | | |
| | | |
| | | |
| | | // === tfc最新价 start === |
| | | @Bean |
| | | public DirectExchange tfcNewPriceExchange() { |
| | | return new DirectExchange(QueueEnum.TFC_NEW_PRICE.getExchange()); |
| | | } |
| | | |
| | | @Bean |
| | | public Queue tfcNewPriceQueue() { |
| | | return new Queue(QueueEnum.TFC_NEW_PRICE.getQueue()); |
| | | } |
| | | |
| | | @Bean |
| | | public Binding tfcNewPriceBind() { |
| | | return BindingBuilder.bind(tfcNewPriceQueue()).to(tfcNewPriceExchange()).with(QueueEnum.TFC_NEW_PRICE.getRoute()); |
| | | } |
| | | // === tfc最新价 end === |
| | | } |
| | |
| | | log.info("收到业绩树消息"); |
| | | dappSystemService.achieveTree(Long.parseLong(id)); |
| | | } |
| | | |
| | | @RabbitListener(queues = QueueConstants.TFC_NEW_PRICE) |
| | | public void tfcNewPrice(String data) { |
| | | log.info("收到最新价消息"); |
| | | |
| | | } |
| | | } |
| | |
| | | </where> |
| | | </select> |
| | | |
| | | |
| | | |
| | | <update id="updateBalance"> |
| | | update dapp_wallet_mine |
| | | set total_amount = total_amount + #{totalAmount}, |
| | | available_amount = available_amount + #{availableAmount} |
| | | where member_id=#{memberId} |
| | | </update> |
| | | |
| | | <update id="updateWithLock"> |
| | | update dapp_wallet_mine |
| | | set total_amount=#{record.totalAmount}, |
| | | available_amount=#{record.availableAmount}, |
| | | version=version+1 |
| | | where id=#{record.id} and version=#{record.version} |
| | | </update> |
| | | </mapper> |