From fa1b970c8fa7772ce123ab84e8cc4240065bcd26 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Fri, 06 Feb 2026 17:43:42 +0800
Subject: [PATCH] 提现

---
 trading-order-service/src/main/java/com/yami/trading/service/impl/CapitaltWalletServiceImpl.java |   30 +++++++++++++++++++++++++-----
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/trading-order-service/src/main/java/com/yami/trading/service/impl/CapitaltWalletServiceImpl.java b/trading-order-service/src/main/java/com/yami/trading/service/impl/CapitaltWalletServiceImpl.java
index e424b24..5539802 100644
--- a/trading-order-service/src/main/java/com/yami/trading/service/impl/CapitaltWalletServiceImpl.java
+++ b/trading-order-service/src/main/java/com/yami/trading/service/impl/CapitaltWalletServiceImpl.java
@@ -50,10 +50,21 @@
     @Autowired
     ItemService itemService;
 
+    @Autowired
+    CapitaltWalletMapper capitaltWalletMapper;
+
     @Override
     public CapitaltWallet getUserIdWallet(String userId) {
-        return getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
+        CapitaltWallet capitaltWallet = getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
                 .eq(CapitaltWallet::getUserId,userId).last(" limit 1"));
+        if (capitaltWallet != null) {
+            return capitaltWallet;
+        } else {
+            capitaltWallet = new CapitaltWallet();
+            capitaltWallet.setUserId(userId);
+            save(capitaltWallet);
+            return capitaltWallet;
+        }
     }
 
     /**
@@ -128,14 +139,19 @@
         if (accountType == 1 && moneyRevise.compareTo(BigDecimal.ZERO) <= 0) { //充值
             throw new YamiShopBindException("请输入大于0的数量");
         }
-        if (accountType == 2 && moneyRevise.compareTo(BigDecimal.ZERO) >= 0) {
-            throw new YamiShopBindException("请输入小于0的数量");
+        if (accountType == 2) {
+            moneyRevise = moneyRevise.negate();
         }
         if ("usdt".equals(coinType)) {
             double amount1 = moneyRevise.doubleValue();
-            CapitaltWallet capitaltWallet = getOne(new LambdaQueryWrapper<>(CapitaltWallet.class)
-                    .eq(CapitaltWallet::getUserId, userId).last(" limit 1 "));
+            CapitaltWallet capitaltWallet = getUserIdWallet(userId);
+            if (capitaltWallet == null) {
+                throw new YamiShopBindException("账号缺少资金数据");
+            }
             double amount_before = capitaltWallet.getMoney().doubleValue();
+            if (accountType == 2 && capitaltWallet.getMoney().subtract(moneyRevise).compareTo(BigDecimal.ZERO) < 0) {
+                throw new YamiShopBindException("账号资金不足");
+            }
             update(capitaltWallet, amount1);
 
             // 保存资金日志
@@ -162,6 +178,10 @@
 
             double amount_before = walletExtend.getAmount();
 
+            if (accountType == 2 && Arith.sub(amount_before, volume) < 0) {
+                throw new YamiShopBindException("账号资金不足");
+            }
+
             // walletExtend = walletService.saveWalletExtendByParaAndUpdate(String.valueOf(recharge.getPartyId()), recharge.getSymbol(), volume);
             walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), volume);
 

--
Gitblit v1.9.3