| | |
| | | package com.yami.trading.service.impl; |
| | | |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import cn.hutool.extra.qrcode.QrCodeUtil; |
| | | import cn.hutool.extra.qrcode.QrConfig; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | WalletLogService walletLogService; |
| | | @Autowired |
| | | LogService logService; |
| | | @Autowired |
| | | CapitaltWalletService capitaltWalletService; |
| | | |
| | | @Override |
| | | public Page listRecord(Page page, String status, String roleName, |
| | |
| | | symbol = "btc"; |
| | | } else if (withdraw.getMethod().indexOf("ETH") != -1) { |
| | | symbol = "eth"; |
| | | } else if (withdraw.getMethod().indexOf("USDC") != -1) { |
| | | symbol = "usdc"; |
| | | } else { |
| | | symbol = "usdt"; |
| | | } |
| | |
| | | Withdraw withdraw = getById(id); |
| | | |
| | | if (withdraw.getStatus() == 2 ) {// 通过后不可驳回 |
| | | return; |
| | | throw new YamiShopBindException("订单已操作,请不要重复操作!"); |
| | | } |
| | | Date date = new Date(); |
| | | withdraw.setReviewTime(date); |
| | |
| | | |
| | | String symbol = ""; |
| | | if (withdraw.getMethod().indexOf("BTC") != -1) { |
| | | symbol = "btc"; |
| | | symbol = "btcusdt"; |
| | | } else if (withdraw.getMethod().indexOf("ETH") != -1) { |
| | | symbol = "eth"; |
| | | } else { |
| | | symbol = "ethusdt"; |
| | | } else if (withdraw.getMethod().indexOf("USDC") != -1) { |
| | | symbol = "usdcusdt"; |
| | | } else if (withdraw.getMethod().indexOf("USDT") != -1) { |
| | | symbol = "usdt"; |
| | | } else { |
| | | return; |
| | | } |
| | | if ("usdt".equals(symbol)) { |
| | | Wallet wallet = walletService.saveWalletByPartyId(withdraw.getUserId()); |
| | | |
| | | double amount_before = wallet.getMoney().doubleValue(); |
| | | |
| | | walletService.update(wallet.getUserId().toString(), |
| | | Arith.add(withdraw.getAmount(), withdraw.getAmountFee())); |
| | | // walletService.update(wallet.getUserId().toString(), |
| | | // Arith.add(withdraw.getAmount(), withdraw.getAmountFee())); |
| | | |
| | | CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class) |
| | | .eq(CapitaltWallet::getUserId, wallet.getUserId().toString()).last(" limit 1 ")); |
| | | if(ObjectUtil.isEmpty(capitaltWallet)){ |
| | | throw new YamiShopBindException("用户资金账户不存在!"); |
| | | } |
| | | capitaltWalletService.update(new LambdaUpdateWrapper<CapitaltWallet>() |
| | | .set(CapitaltWallet::getMoney,new BigDecimal(Arith.add(capitaltWallet.getMoney(), withdraw.getVolume()))) |
| | | .eq(CapitaltWallet::getUserId,wallet.getUserId())); |
| | | |
| | | |
| | | /* |
| | | * 保存资金日志 |
| | |
| | | public void saveApplyOtherChannel(Withdraw withdraw, String symbol) { |
| | | User party = userService.getById(withdraw.getUserId()); |
| | | if (Constants.SECURITY_ROLE_TEST.equals(party.getRoleName())) { |
| | | throw new YamiShopBindException("无权限"); |
| | | throw new YamiShopBindException("no access"); |
| | | } |
| | | RealNameAuthRecord party_kyc = realNameAuthRecordService.getByUserId(withdraw.getUserId()); |
| | | HighLevelAuthRecord party_kycHighLevel = highLevelAuthRecordService.findByUserId(withdraw.getUserId()); |
| | |
| | | party_kyc=new RealNameAuthRecord(); |
| | | } |
| | | if (!(party_kyc.getStatus() == 2) && "true".equals(sysparaService.find("withdraw_by_kyc").getSvalue())) { |
| | | throw new YamiShopBindException("未基础认证"); |
| | | throw new YamiShopBindException("Not yet certified at the basic level"); |
| | | } |
| | | double withdraw_by_high_kyc = Double.valueOf(sysparaService.find("withdraw_by_high_kyc").getSvalue()); |
| | | if (withdraw_by_high_kyc > 0 && withdraw.getVolume().doubleValue() > withdraw_by_high_kyc |
| | | && !(party_kycHighLevel.getStatus() == 2)) { |
| | | throw new YamiShopBindException("请先通过高级认证"); |
| | | throw new YamiShopBindException("Please go through the advanced certification process first."); |
| | | } |
| | | // if (!party.isWithdrawAuthority()) { |
| | | // throw new YamiShopBindException("无权限"); |
| | |
| | | } |
| | | WalletExtend walletExtend = walletService.saveExtendByPara(party.getUserId(), symbol); |
| | | if (walletExtend.getAmount() < withdraw.getVolume().doubleValue()) { |
| | | throw new YamiShopBindException("余额不足"); |
| | | throw new YamiShopBindException("not sufficient funds"); |
| | | } |
| | | String withdraw_limit = sysparaService.find("withdraw_limit_" + symbol).getSvalue(); |
| | | if (withdraw.getVolume().doubleValue() < Double.valueOf(withdraw_limit)) { |
| | | throw new YamiShopBindException("提现不得小于限额"); |
| | | throw new YamiShopBindException("Withdrawal amount must not be less than the limit."); |
| | | } |
| | | String withdraw_limit_max = sysparaService.find("withdraw_limit_max").getSvalue(); |
| | | if (withdraw.getVolume().doubleValue() > Double.valueOf(withdraw_limit_max)) { |
| | | throw new YamiShopBindException("提现不得大于限额"); |
| | | throw new YamiShopBindException("Withdrawal amount cannot exceed the limit."); |
| | | } |
| | | /** |
| | | * 当日提现次数是否超过 |
| | |
| | | List<Withdraw> withdraw_days = findAllByDate(withdraw.getUserId().toString()); |
| | | if (withdraw_limit_num > 0 && withdraw_days != null) { |
| | | if (withdraw_days.size() >= withdraw_limit_num) { |
| | | throw new YamiShopBindException("当日可提现次数不足"); |
| | | throw new YamiShopBindException("The number of times funds can be withdrawn on the same day is insufficient."); |
| | | } |
| | | } |
| | | /** |
| | |
| | | // |
| | | String dateString = sdf.format(date); |
| | | if (dateString.compareTo(withdraw_time[0]) < 0 || dateString.compareTo(withdraw_time[1]) > 0) { |
| | | throw new YamiShopBindException("不在可提现时间内"); |
| | | throw new YamiShopBindException("Not within the available withdrawal period"); |
| | | } |
| | | } |
| | | /** |
| | |
| | | public void saveApply(Withdraw withdraw, String channel, String method_id) { |
| | | withdraw.setMethod(channel); |
| | | if (channel.indexOf("BTC") != -1) { |
| | | saveApplyOtherChannel(withdraw, "btc"); |
| | | saveApplyOtherChannel(withdraw, "btcusdt"); |
| | | return; |
| | | } else if (channel.indexOf("ETH") != -1) { |
| | | saveApplyOtherChannel(withdraw, "eth"); |
| | | saveApplyOtherChannel(withdraw, "ethusdt"); |
| | | return; |
| | | } else if (channel.indexOf("USDC") != -1) { |
| | | saveApplyOtherChannel(withdraw, "usdcusdt"); |
| | | return; |
| | | } |
| | | User party = userService.getById(withdraw.getUserId()); |
| | |
| | | if (party.getStatus() != 1) { |
| | | throw new YamiShopBindException("Your account has been frozen"); |
| | | } |
| | | Wallet wallet = walletService.saveWalletByPartyId(withdraw.getUserId()); |
| | | if (wallet.getMoney().doubleValue() < withdraw.getVolume().doubleValue()) { |
| | | throw new YamiShopBindException("余额不足"); |
| | | |
| | | // Wallet wallet = walletService.saveWalletByPartyId(withdraw.getUserId()); |
| | | |
| | | CapitaltWallet capitaltWallet = capitaltWalletService.getOne(new LambdaQueryWrapper<>(CapitaltWallet.class) |
| | | .eq(CapitaltWallet::getUserId, withdraw.getUserId()).last(" limit 1 ")); |
| | | if (capitaltWallet.getMoney().doubleValue() < withdraw.getVolume().doubleValue()) { |
| | | throw new YamiShopBindException("not sufficient funds"); |
| | | } |
| | | // 手续费(USDT) |
| | | /** |
| | |
| | | } |
| | | String withdraw_limit = sysparaService.find("withdraw_limit").getSvalue(); |
| | | if (withdraw.getVolume().doubleValue() < Double.valueOf(withdraw_limit)) { |
| | | throw new YamiShopBindException("提现不得小于限额"); |
| | | throw new YamiShopBindException("Withdrawal amount must not be less than the limit."); |
| | | } |
| | | String withdraw_limit_max = sysparaService.find("withdraw_limit_max").getSvalue(); |
| | | if (withdraw.getVolume().doubleValue() > Double.valueOf(withdraw_limit_max)) { |
| | | throw new YamiShopBindException("提现不得大于限额"); |
| | | throw new YamiShopBindException("Withdrawal amount must not be less than the withdrawal limit and must not exceed the withdrawal limit."); |
| | | } |
| | | /** |
| | | * 当日提现次数是否超过 |
| | |
| | | List<Withdraw> withdraw_days = findAllByDate(withdraw.getUserId().toString()); |
| | | if (withdraw_limit_num > 0 && withdraw_days != null) { |
| | | if (withdraw_days.size() >= withdraw_limit_num) { |
| | | throw new YamiShopBindException("当日可提现次数不足"); |
| | | throw new YamiShopBindException("The number of times funds can be withdrawn on the same day is insufficient."); |
| | | } |
| | | } |
| | | /** |
| | |
| | | // |
| | | String dateString = sdf.format(date); |
| | | if (dateString.compareTo(withdraw_time[0]) < 0 || dateString.compareTo(withdraw_time[1]) > 0) { |
| | | throw new YamiShopBindException("不在可提现时间内"); |
| | | throw new YamiShopBindException("Not within the available withdrawal period"); |
| | | } |
| | | } |
| | | /** |
| | |
| | | /** |
| | | * 用户Party表里可提现金额参数 -----可为负数 |
| | | */ |
| | | double party_withdraw = party.getWithdrawLimitAmount().doubleValue(); |
| | | // double party_withdraw = party.getWithdrawLimitAmount().doubleValue(); |
| | | /** |
| | | * usdt剩余余额 |
| | | */ |
| | |
| | | } |
| | | } |
| | | } |
| | | double withdraw_limit_turnover_percent = Double |
| | | .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getSvalue()); |
| | | party_withdraw = Arith.mul(party_withdraw, withdraw_limit_turnover_percent); |
| | | // 流水小于限额 |
| | | if (userdata_turnover < party_withdraw) { |
| | | fact_withdraw_amount = Arith.sub(party_withdraw, userdata_turnover); |
| | | throw new YamiShopBindException(fact_withdraw_amount + ""); |
| | | // throw new BusinessException(1, "当前还需交易" + fact_withdraw_amount + ",才可提币"); |
| | | } |
| | | // double withdraw_limit_turnover_percent = Double |
| | | // .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getSvalue()); |
| | | // party_withdraw = Arith.mul(party_withdraw, withdraw_limit_turnover_percent); |
| | | // // 流水小于限额 |
| | | // if (userdata_turnover < party_withdraw) { |
| | | // fact_withdraw_amount = Arith.sub(party_withdraw, userdata_turnover); |
| | | // throw new YamiShopBindException(fact_withdraw_amount + ""); |
| | | //// throw new BusinessException(1, "当前还需交易" + fact_withdraw_amount + ",才可提币"); |
| | | // } |
| | | } |
| | | if ("2".equals(withdraw_limit_open_use_type)) { |
| | | /** |
| | |
| | | } |
| | | } |
| | | } |
| | | // String withdraw_fee_type = sysparaService.find("withdraw_fee_type").getValue(); |
| | | // double withdraw_fee = Double.valueOf(((Syspara) sysparaService.find("withdraw_fee")).getValue()); |
| | | // DecimalFormat df = new DecimalFormat("#.##"); |
| | | // if ("fixed".equals(withdraw_fee_type)) { |
| | | // fee = withdraw_fee; |
| | | // } else { |
| | | // fee = Double.valueOf(df.format(Arith.mul(withdraw.getVolume(), withdraw_fee))); |
| | | // |
| | | // } |
| | | withdraw.setAmountFee(new BigDecimal(fee)); |
| | | // ExchangeRate exchangeRate = exchangeRateService.findBy(ExchangeRate.OUT, withdraw.getCurrency()); |
| | | // |
| | | // if (exchangeRate == null) { |
| | | // throw new BusinessException("Parameter Error"); |
| | | // } |
| | | // |
| | | // withdraw.setAmount(Double.valueOf(df.format(Arith.mul(withdraw.getVolume(), exchangeRate.getRata())))); |
| | | withdraw.setAmount(new BigDecimal(Arith.sub(withdraw.getVolume().doubleValue(), fee))); |
| | | if (channel.indexOf("USDT") != -1) { |
| | | withdraw.setMethod(channel); |
| | | } |
| | | // if ("USDT".equals(channel)) { |
| | | // withdraw.setMethod("USDT"); |
| | | // } |
| | | else if ("OTC".equals(channel)) { |
| | | throw new YamiShopBindException("渠道未开通"); |
| | | // if (StringUtils.isNullOrEmpty(method_id)) { |
| | | // throw new BusinessException("请选择付款账号"); |
| | | // } |
| | | // PaymentMethod paymentMethod = paymentMethodService.get(method_id); |
| | | // if (paymentMethod == null) { |
| | | // throw new BusinessException("请选择付款账号"); |
| | | // } |
| | | // withdraw.setMethod(paymentMethod.getMethod()); |
| | | // withdraw.setAccount(paymentMethod.getAccount()); |
| | | // withdraw.setBank(paymentMethod.getBank()); |
| | | // withdraw.setDeposit_bank(paymentMethod.getDeposit_bank()); |
| | | // withdraw.setQdcode(paymentMethod.getQdcode()); |
| | | // withdraw.setUsername(withdraw.getUsername()); |
| | | throw new YamiShopBindException("Channel not activated"); |
| | | } else { |
| | | throw new YamiShopBindException("渠道未开通"); |
| | | throw new YamiShopBindException("Channel not activated"); |
| | | } |
| | | log.info("========================getOrderNo=======11111111============================================="); |
| | | |
| | |
| | | */ |
| | | String withdraw_qr = qRGenerateService.generateWithdraw(withdraw.getOrderNo(), withdraw.getAddress()); |
| | | withdraw.setQdcode(withdraw_qr); |
| | | double amount_before = wallet.getMoney().doubleValue(); |
| | | walletService.update(wallet.getUserId().toString(), Arith.sub(0, withdraw.getVolume().doubleValue())); |
| | | double amount_before = capitaltWallet.getMoney().doubleValue(); |
| | | |
| | | |
| | | |
| | | // walletService.update(wallet.getUserId().toString(), Arith.sub(0, withdraw.getVolume().doubleValue())); |
| | | |
| | | |
| | | if(ObjectUtil.isEmpty(capitaltWallet)){ |
| | | throw new YamiShopBindException("The user's funds account does not exist!"); |
| | | } |
| | | capitaltWalletService.update(capitaltWallet,-withdraw.getVolume().doubleValue()); |
| | | |
| | | save(withdraw); |
| | | |
| | | /* |
| | |
| | | moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN); |
| | | moneyLog.setAmountBefore(new BigDecimal(amount_before)); |
| | | moneyLog.setAmount(new BigDecimal(Arith.sub(0, withdraw.getVolume().doubleValue()))); |
| | | moneyLog.setAmountAfter(wallet.getMoney()); |
| | | moneyLog.setAmountAfter(capitaltWallet.getMoney()); |
| | | moneyLog.setLog("提现订单[" + withdraw.getOrderNo() + "]"); |
| | | // moneyLog.setExtra(withdraw.getOrder_no()); |
| | | moneyLog.setUserId(withdraw.getUserId()); |
| | |
| | | } |
| | | String withdraw_limit = sysparaService.find("withdraw_limit_" + symbol).getSvalue(); |
| | | if (amount.doubleValue() < Double.valueOf(withdraw_limit)) { |
| | | throw new YamiShopBindException("提现不得小于限额"); |
| | | throw new YamiShopBindException("Withdrawal amount must not be less than the limit."); |
| | | } |
| | | String withdraw_limit_max = sysparaService.find("withdraw_limit_max").getSvalue(); |
| | | if (amount.doubleValue() > Double.valueOf(withdraw_limit_max)) { |
| | | throw new YamiShopBindException("提现不得大于限额"); |
| | | throw new YamiShopBindException("Withdrawal amount cannot exceed the limit."); |
| | | } |
| | | /** |
| | | * 当日提现次数是否超过 |
| | |
| | | List<Withdraw> withdraw_days = findAllByDate(withdraw.getUserId().toString()); |
| | | if (withdraw_limit_num > 0 && withdraw_days != null) { |
| | | if (withdraw_days.size() >= withdraw_limit_num) { |
| | | throw new YamiShopBindException("当日可提现次数不足"); |
| | | throw new YamiShopBindException("The number of times funds can be withdrawn on the same day is insufficient."); |
| | | } |
| | | } |
| | | /** |
| | |
| | | // |
| | | String dateString = sdf.format(date); |
| | | if (dateString.compareTo(withdraw_time[0]) < 0 || dateString.compareTo(withdraw_time[1]) > 0) { |
| | | throw new YamiShopBindException("不在可提现时间内"); |
| | | throw new YamiShopBindException("Not within the available withdrawal periodNot within the available withdrawal period"); |
| | | } |
| | | } |
| | | WithdrawFeeVo withdrawFeeVo = getFee(withdraw.getMethod(), withdraw.getAmount().doubleValue()); |