| | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import com.xcong.excoin.modules.blackchain.model.EosResult; |
| | | import com.xcong.excoin.modules.blackchain.model.XrpTransResult; |
| | | import com.xcong.excoin.modules.blackchain.model.XrpTransactions; |
| | | import com.xcong.excoin.modules.blackchain.model.XrpTx; |
| | | import com.xcong.excoin.modules.blackchain.model.*; |
| | | import com.xcong.excoin.modules.blackchain.service.*; |
| | | import com.xcong.excoin.modules.coin.service.BlockCoinService; |
| | | import com.xcong.excoin.modules.member.dao.MemberCoinAddressDao; |
| | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | private MemberWalletCoinDao memberWalletCoinDao; |
| | | |
| | | @Resource |
| | | private UsdtEthService usdtEthService; |
| | | |
| | | @Resource |
| | | private RedisUtils redisUtils; |
| | | |
| | | private final static String EOS_SEQ_KEY="eos_seq_key"; |
| | | |
| | | private final static String xrp_update_key = "xrp_update_key"; |
| | | |
| | | private final static String trc20_update_key = "trc20_update_key"; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoinEntity.getId(), newBalance, balance, 0); |
| | | |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "ERC20", balance); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "ERC20", balance, null); |
| | | ThreadPoolUtils.sendWholePrice(memberId); |
| | | |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.USDT.name(), 1, 1); |
| | | |
| | |
| | | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.ETH.name(), null, balance); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.ETH.name(), null, balance, null); |
| | | |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.ETH.name(), 1, 1); |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "OMNI", balance); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "OMNI", balance, null); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoin.getId(), newBalance, balance, 0); |
| | | |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.BTC.name(), null, balance); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.BTC.name(), null, balance, null); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.BTC.name(), 1, 1); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | |
| | | if(memberCoinAddressEntity!=null){ |
| | | memberWalletCoinDao.updateBlockBalance(memberWalletCoinEntity.getId(),amount,BigDecimal.ZERO,0); |
| | | // 添加冲币记录 |
| | | String orderNo = insertCoinCharge(EosService.ACCOUNT,memberId,amount,CoinTypeEnum.EOS.name(),memo,BigDecimal.ZERO); |
| | | String orderNo = insertCoinCharge(EosService.ACCOUNT, memberId, amount, CoinTypeEnum.EOS.name(), memo, BigDecimal.ZERO, null); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", amount, CoinTypeEnum.EOS.name(), 1, 1); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | |
| | | if(memberCoinAddressEntity!=null){ |
| | | memberWalletCoinDao.updateBlockBalance(memberWalletCoinEntity.getId(),amount,BigDecimal.ZERO,0); |
| | | // 添加冲币记录 |
| | | String orderNo = insertCoinCharge(XrpService.ACCOUNT,memberId,amount,CoinTypeEnum.XRP.name(),memo,BigDecimal.ZERO); |
| | | String orderNo = insertCoinCharge(XrpService.ACCOUNT, memberId, amount, CoinTypeEnum.XRP.name(), memo, BigDecimal.ZERO, null); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", amount, CoinTypeEnum.XRP.name(), 1, 1); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void updateTrc20(EthUsdtChargeDto dto) { |
| | | String address = dto.getAddress(); |
| | | BigDecimal amount = dto.getBalance(); |
| | | String hash = dto.getHash(); |
| | | // 判断有无 |
| | | //List<MemberCoinAddressEntity> addressList = memberCoinAddressDao.selectAllBlockAddressBySymbolAndTag(CoinTypeEnum.USDT.name(), "TRC20"); |
| | | Map<String, Object> hashParam = new HashMap<>(); |
| | | // 校验hash是否已同步过 |
| | | hashParam.put("hash", hash); |
| | | List<MemberCoinChargeEntity> memberCoinChargeEntities = memberCoinChargeDao.selectByMap(hashParam); |
| | | if (CollectionUtils.isNotEmpty(memberCoinChargeEntities)) { |
| | | // 若已同步过 |
| | | return; |
| | | } |
| | | // 添加钱包余额 |
| | | // 用户ID |
| | | MemberCoinAddressEntity memberCoinAddress = memberCoinAddressDao.selectCoinAddressByAddressAndSymbolTag(address, CoinTypeEnum.USDT.name(),"TRC20"); |
| | | if (memberCoinAddress == null) { |
| | | return; |
| | | } |
| | | Long memberId = memberCoinAddress.getMemberId(); |
| | | // 查询钱包 并更新 |
| | | MemberWalletCoinEntity memberWalletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); |
| | | memberWalletCoinDao.updateBlockBalance(memberWalletCoinEntity.getId(), amount, BigDecimal.ZERO, 0); |
| | | // 添加冲币记录 |
| | | String orderNo = insertCoinCharge(address, memberId, amount, CoinTypeEnum.USDT.name(), "TRC20", BigDecimal.ZERO, hash); |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", amount, CoinTypeEnum.USDT.name(), 1, 1); |
| | | |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | | if (StrUtil.isNotBlank(member.getPhone())) { |
| | | //String amountEos = amount + "XRP"; |
| | | Sms106Send.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo); |
| | | } else { |
| | | SubMailSend.sendRechargeMail(member.getEmail(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void updateEthUsdtNew(EthUsdtChargeDto ethUsdtChargeDto) { |
| | | String address = ethUsdtChargeDto.getAddress(); |
| | | String hash = ethUsdtChargeDto.getHash(); |
| | | // hash没有用过 |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("hash", hash); |
| | | param.put("address", address); |
| | | List<MemberCoinChargeEntity> memberCoinChargeEntities = memberCoinChargeDao.selectByMap(param); |
| | | if (CollectionUtils.isNotEmpty(memberCoinChargeEntities)) { |
| | | return; |
| | | } |
| | | // 校验这个交易是否成功 |
| | | EthService ethService = new EthService(); |
| | | boolean b = ethService.checkTransferResult(hash); |
| | | if (!b) { |
| | | log.info("#USDT假充值:{}#", hash); |
| | | return; |
| | | } |
| | | MemberCoinAddressEntity coinAddressEntity = memberCoinAddressDao.selectCoinAddressByAddressAndSymbol(address, CoinTypeEnum.USDT.toString()); |
| | | if (coinAddressEntity == null) { |
| | | return; |
| | | } |
| | | Long memberId = coinAddressEntity.getMemberId(); |
| | | BigDecimal balance = ethUsdtChargeDto.getBalance(); |
| | | if (balance != null && balance.compareTo(new BigDecimal("0.1")) > 0) { |
| | | balance = balance.setScale(8, RoundingMode.CEILING); |
| | | BigDecimal early = BigDecimal.ZERO; |
| | | |
| | | MemberWalletCoinEntity walletCoinEntity = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, CoinTypeEnum.USDT.name()); |
| | | if (walletCoinEntity == null) { |
| | | return; |
| | | } |
| | | BigDecimal newBalance = balance.subtract(early); |
| | | memberWalletCoinDao.updateBlockBalance(walletCoinEntity.getId(), newBalance, balance, 0); |
| | | String orderNo = insertCoinCharge(address, memberId, newBalance, CoinTypeEnum.USDT.name(), "ERC20", balance, ethUsdtChargeDto.getHash()); |
| | | // 插入财务记录 |
| | | LogRecordUtils.insertMemberAccountMoneyChange(memberId, "转入", newBalance, CoinTypeEnum.USDT.name(), 1, 1); |
| | | ThreadPoolUtils.sendDingTalk(5); |
| | | MemberEntity member = memberDao.selectById(memberId); |
| | | if (StrUtil.isNotBlank(member.getPhone())) { |
| | | String amount = newBalance.toPlainString() + "USDT-ERC20"; |
| | | Sms106Send.sendRechargeMsg(member.getPhone(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo); |
| | | } else { |
| | | SubMailSend.sendRechargeMail(member.getEmail(), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_MINUTE_PATTERN), orderNo); |
| | | } |
| | | // 同步 |
| | | try { |
| | | usdtEthService.pollByAddress(address, balance); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |
| | | private String generateNo() { |
| | | // 生成订单号 |
| | | Long timestamp = System.currentTimeMillis(); |
| | |
| | | return String.valueOf(timestamp).substring(2) + random; |
| | | } |
| | | |
| | | public String insertCoinCharge(String address, Long memberId, BigDecimal newBalance, String symbol, String tag, BigDecimal lastAmount) { |
| | | public String insertCoinCharge(String address, Long memberId, BigDecimal newBalance, String symbol, String tag, BigDecimal lastAmount, String hash) { |
| | | MemberCoinChargeEntity memberCoinChargeEntity = new MemberCoinChargeEntity(); |
| | | memberCoinChargeEntity.setAddress(address); |
| | | memberCoinChargeEntity.setMemberId(memberId); |
| | |
| | | memberCoinChargeEntity.setTag(tag); |
| | | memberCoinChargeEntity.setStatus(1); |
| | | memberCoinChargeEntity.setLastAmount(lastAmount); |
| | | memberCoinChargeEntity.setHash(hash); |
| | | String orderNo = generateNo(); |
| | | memberCoinChargeEntity.setOrderCode(orderNo); |
| | | memberCoinChargeDao.insert(memberCoinChargeEntity); |
| | | return orderNo; |
| | | } |
| | | |
| | | } |