From a2dc849bc20bffaa4ad45d68e401d3892ace24b3 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Fri, 04 Jul 2025 22:21:20 +0800
Subject: [PATCH] 1

---
 trading-order-service/src/main/java/com/yami/trading/service/impl/WithdrawServiceImpl.java |   77 +++++++++++++++++++-------------------
 1 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/trading-order-service/src/main/java/com/yami/trading/service/impl/WithdrawServiceImpl.java b/trading-order-service/src/main/java/com/yami/trading/service/impl/WithdrawServiceImpl.java
index c2b650a..fbf562a 100644
--- a/trading-order-service/src/main/java/com/yami/trading/service/impl/WithdrawServiceImpl.java
+++ b/trading-order-service/src/main/java/com/yami/trading/service/impl/WithdrawServiceImpl.java
@@ -1,9 +1,12 @@
 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;
@@ -65,6 +68,8 @@
     WalletLogService walletLogService;
     @Autowired
     LogService logService;
+    @Autowired
+    CapitaltWalletService capitaltWalletService;
 
     @Override
     public Page listRecord(Page page, String status, String roleName,
@@ -141,8 +146,18 @@
 
             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().doubleValue(), amount_before)))
+                    .eq(CapitaltWallet::getUserId,wallet.getUserId()));
+
 
             /*
              * 保存资金日志
@@ -462,8 +477,12 @@
         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()) {
+
+//        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("余额不足");
         }
         // 手续费(USDT)
@@ -626,45 +645,13 @@
                 }
             }
         }
-//		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());
         } else {
             throw new YamiShopBindException("渠道未开通");
         }
@@ -680,8 +667,20 @@
          */
         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("用户资金账户不存在!");
+        }
+        capitaltWalletService.update(new LambdaUpdateWrapper<CapitaltWallet>()
+                .set(CapitaltWallet::getMoney,new BigDecimal(Arith.sub(capitaltWallet.getMoney().doubleValue(), amount_before)))
+                .eq(CapitaltWallet::getUserId,capitaltWallet.getUserId()));
+
         save(withdraw);
 
         /*
@@ -691,7 +690,7 @@
         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());

--
Gitblit v1.9.3