peternameyakj
2024-07-30 f23b33bbb9eaff76cac5b69e3b793fc7910fb0fa
src/main/java/project/withdraw/internal/WithdrawServiceImpl.java
@@ -10,6 +10,7 @@
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -20,10 +21,13 @@
import kernel.util.StringUtils;
import kernel.web.ApplicationUtil;
import project.Constants;
import project.data.DataService;
import project.log.MoneyLog;
import project.log.MoneyLogService;
import project.party.PartyService;
import project.party.model.Party;
import project.redis.RedisHandler;
import project.redis.interal.RedisHandlerImpl;
import project.syspara.Syspara;
import project.syspara.SysparaService;
import project.tip.TipConstants;
@@ -36,11 +40,8 @@
import project.user.kyc.KycHighLevel;
import project.user.kyc.KycHighLevelService;
import project.user.kyc.KycService;
import project.wallet.Wallet;
import project.wallet.WalletExtend;
import project.wallet.WalletLog;
import project.wallet.WalletLogService;
import project.wallet.WalletService;
import project.wallet.*;
import project.wallet.internal.WalletGatherServiceImpl;
import project.wallet.rate.ExchangeRateService;
import project.withdraw.Withdraw;
import project.withdraw.WithdrawService;
@@ -66,7 +67,7 @@
   protected TipService tipService;
   @Override
   public void saveApply(Withdraw withdraw, String channel, String method_id, String googleCode) {
   public void saveApply(Withdraw withdraw, String channel, String method_id, String googleCode,WalletGatherService walletGatherService) {
      Party party = this.partyService.cachePartyBy(withdraw.getPartyId(), false);
      if (Constants.SECURITY_ROLE_TEST.equals(party.getRolename())) {
         throw new BusinessException(1, "无权限");
@@ -119,16 +120,16 @@
//          +withdrawList.get(0).getDeviceIp()+"]不同, 请注意核对!!!");
//          }
//       }
      System.out.println("打印信息");
      withdraw.setMethod(channel);
      if (channel.indexOf("BTC") != -1) {
         saveApplyOtherChannel(withdraw, "btc");
         saveApplyOtherChannel(withdraw, "btc",walletGatherService);
         return;
      } else if (channel.indexOf("ETH") != -1) {
         saveApplyOtherChannel(withdraw, "eth");
         saveApplyOtherChannel(withdraw, "eth",walletGatherService);
         return;
      }else  if(channel.indexOf("USDC") !=-1){
         saveApplyOtherChannel(withdraw, "usdc");
         saveApplyOtherChannel(withdraw, "usdc",walletGatherService);
         return;
      }
      Kyc party_kyc = this.kycService.get(withdraw.getPartyId().toString());
@@ -153,8 +154,12 @@
         throw new BusinessException(506, "Your account has been frozen");
      }
      Wallet wallet = walletService.saveWalletByPartyId(withdraw.getPartyId());
      if (wallet.getMoney() < withdraw.getVolume()) {
//      Wallet wallet = walletService.saveWalletByPartyId(withdraw.getPartyId());
      System.out.println("获取walletGather前");
      WalletGather walletGather = walletGatherService.getWalletGatherByPartyId(withdraw.getPartyId(),null);
      System.out.println("获取walletGather后");
      System.out.println("walletGather-usdt"+walletGather.getUsdtMoney());
      if (walletGather.getUsdtMoney() < withdraw.getVolume()) {
         throw new BusinessException(1, "余额不足");
      }
@@ -393,10 +398,12 @@
      withdraw.setQdcode(withdraw_qr);
      double amount_before = wallet.getMoney();
      double amount_before = walletGather.getUsdtMoney();
      wallet.setMoney(Arith.sub(wallet.getMoney(), withdraw.getVolume()));
      walletService.update(wallet.getPartyId().toString(), Arith.sub(0, withdraw.getVolume()));
//      wallet.setMoney(Arith.sub(wallet.getMoney(), withdraw.getVolume()));
//      walletService.update(wallet.getPartyId().toString(), Arith.sub(0, withdraw.getVolume()));
      //修改资金账户
      walletGatherService.update(walletGather.getPartyId().toString(),"usdt",withdraw.getVolume(),"sub");
      withdraw.setId(ApplicationUtil.getCurrentTimeUUID());
      insertWithdraw(withdraw);
@@ -408,7 +415,7 @@
      moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
      moneyLog.setAmount_before(amount_before);
      moneyLog.setAmount(Arith.sub(0, withdraw.getVolume()));
      moneyLog.setAmount_after(wallet.getMoney());
      moneyLog.setAmount_after(Arith.sub(amount_before, withdraw.getVolume()));
      moneyLog.setLog("提现订单[" + withdraw.getOrder_no() + "]");
      // moneyLog.setExtra(withdraw.getOrder_no());
@@ -523,7 +530,7 @@
      return userWithdraw;
   }
   public void saveApplyOtherChannel(Withdraw withdraw, String symbol) {
   public void saveApplyOtherChannel(Withdraw withdraw, String symbol,WalletGatherService walletGatherService) {
      Party party = this.partyService.cachePartyBy(withdraw.getPartyId(), false);
      if (Constants.SECURITY_ROLE_TEST.equals(party.getRolename())) {
@@ -550,11 +557,29 @@
      if (!party.getEnabled()) {
         throw new BusinessException(506, "Your account has been frozen");
      }
      WalletExtend walletExtend = walletService.saveExtendByPara(party.getId(), symbol);
      if (walletExtend.getAmount() < withdraw.getVolume()) {
         throw new BusinessException(1, "余额不足");
      double amount_before = 0;
      WalletGather walletGather = walletGatherService.getWalletGatherByPartyId(withdraw.getPartyId(),null);
      if("btc".equals(symbol)){
         if (walletGather.getBtcMoney() < withdraw.getVolume()) {
            throw new BusinessException(1, "余额不足");
         }
         amount_before = walletGather.getBtcMoney();
      }else if("eth".equals(symbol)){
         if (walletGather.getEthMoney() < withdraw.getVolume()) {
            throw new BusinessException(1, "余额不足");
         }
         amount_before = walletGather.getBtcMoney();
      }else if("usdc".equals(symbol)){
         if (walletGather.getUsdcMoney() < withdraw.getVolume()) {
            throw new BusinessException(1, "余额不足");
         }
         amount_before = walletGather.getBtcMoney();
      }
//      WalletExtend walletExtend = walletService.saveExtendByPara(party.getId(), symbol);
//      if (walletExtend.getAmount() < withdraw.getVolume()) {
//         throw new BusinessException(1, "余额不足");
//      }
      String withdraw_limit = sysparaService.find("withdraw_limit_" + symbol).getValue();
      if (withdraw.getVolume() < Double.valueOf(withdraw_limit)) {
@@ -706,9 +731,11 @@
      withdraw.setQdcode(withdraw_qr);
      double amount_before = walletExtend.getAmount();
      walletService.updateExtend(walletExtend.getPartyId().toString(), symbol, Arith.sub(0, withdraw.getVolume()));
//      walletService.updateExtend(walletExtend.getPartyId().toString(), symbol, Arith.sub(0, withdraw.getVolume()));
      //修改资金账户
      walletGatherService.update(walletGather.getPartyId().toString(),symbol,withdraw.getVolume(),"sub");
      withdraw.setId(ApplicationUtil.getCurrentTimeUUID());
      insertWithdraw(withdraw);