| | |
| | | package com.yami.trading.admin.controller; |
| | | |
| | | import com.yami.trading.admin.model.UpdateAddressModel; |
| | | import com.yami.trading.admin.model.UpdateUserAddressModel; |
| | | import com.yami.trading.bean.model.ChannelBlockchain; |
| | | import com.yami.trading.bean.model.User; |
| | | import com.yami.trading.common.constants.RedisKeys; |
| | | import com.yami.trading.common.domain.Result; |
| | | import com.yami.trading.common.exception.YamiShopBindException; |
| | | import com.yami.trading.security.common.enums.CryptoCurrencyEnum; |
| | | import com.yami.trading.service.ChannelBlockchainService; |
| | | import com.yami.trading.service.exchange.PartyBlockchainService; |
| | | import com.yami.trading.service.user.UserService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @Autowired |
| | | private ChannelBlockchainService channelBlockchainService; |
| | | |
| | | @Autowired |
| | | private PartyBlockchainService partyBlockchainService; |
| | | |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @ApiOperation("充值地址列表") |
| | | @PostMapping("/list") |
| | |
| | | return Result.succeed(data); |
| | | } |
| | | |
| | | @GetMapping("/updateUserAddress") |
| | | public Result<?> updateUserAddress(UpdateUserAddressModel model) { |
| | | if (StringUtils.isBlank(model.getUserCode())) { |
| | | throw new YamiShopBindException("用户编码不能为空"); |
| | | } |
| | | User user = userService.findUserByUserCode(model.getUserCode()); |
| | | if (user == null) { |
| | | throw new YamiShopBindException("用户不存在"); |
| | | } |
| | | String userName = user.getUserName(); |
| | | String partyId = user.getUserId(); |
| | | saveUserAddress(userName, partyId, "usdt", "TRC20", model.getUsdtTrc20()); |
| | | saveUserAddress(userName, partyId, "usdt", "ERC20", model.getUsdtErc20()); |
| | | saveUserAddress(userName, partyId, "btc", "BTC", model.getBtc()); |
| | | saveUserAddress(userName, partyId, "eth", "ETH", model.getEth()); |
| | | saveUserAddress(userName, partyId, "usdc", "ERC20", model.getUsdcErc20()); |
| | | saveUserAddress(userName, partyId, "usdc", "TRC20", model.getUsdcTrc20()); |
| | | return Result.succeed(null); |
| | | } |
| | | |
| | | private void saveUserAddress(String userName, String partyId, String coin, String chain, String address) { |
| | | if (StringUtils.isBlank(address)) { |
| | | return; |
| | | } |
| | | ChannelBlockchain template = findTemplate(coin, chain); |
| | | String chainName = template != null ? template.getBlockchainName() : chain.toLowerCase(); |
| | | String qrImage = template != null ? template.getImg() : null; |
| | | partyBlockchainService.saveOrUpdateAddress(userName, coin, chainName, address.trim(), qrImage); |
| | | CryptoCurrencyEnum currencyEnum = findCurrencyEnum(coin, chain); |
| | | if (currencyEnum != null) { |
| | | redisTemplate.opsForValue().set(RedisKeys.BLOCKCHAIN_ADDRESS + partyId + currencyEnum.getName(), address.trim()); |
| | | } |
| | | } |
| | | |
| | | private CryptoCurrencyEnum findCurrencyEnum(String coin, String chain) { |
| | | for (CryptoCurrencyEnum currencyEnum : CryptoCurrencyEnum.getAll()) { |
| | | if (currencyEnum.getCoin().equalsIgnoreCase(coin) && currencyEnum.getChain().equalsIgnoreCase(chain)) { |
| | | return currencyEnum; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private ChannelBlockchain findTemplate(String coin, String chain) { |
| | | List<ChannelBlockchain> list = channelBlockchainService.findByCoin(coin.toLowerCase()); |
| | | return list.stream() |
| | | .filter(item -> chain.equalsIgnoreCase(item.getBlockchainName())) |
| | | .findFirst() |
| | | .orElse(null); |
| | | } |
| | | |
| | | private void fillBlockchainNameAlias(ChannelBlockchain item) { |
| | | if (item != null && StringUtils.isNotBlank(item.getBlockchainName())) { |
| | | item.setBlockchain_name(item.getBlockchainName()); |