From f620192bcac7f5cb910a99e092edcee00280ce10 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Sat, 11 Oct 2025 18:39:54 +0800
Subject: [PATCH] 充值提现修改

---
 trading-order-service/src/main/java/com/yami/trading/service/impl/CapitaltWalletServiceImpl.java |   66 +++++++++++++++++++++++++++++---
 1 files changed, 59 insertions(+), 7 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 7bfe54f..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
@@ -4,9 +4,11 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yami.trading.bean.contract.domain.ContractOrder;
+import com.yami.trading.bean.item.domain.Item;
 import com.yami.trading.bean.model.CapitaltWallet;
 import com.yami.trading.bean.model.MoneyLog;
 import com.yami.trading.bean.model.Wallet;
+import com.yami.trading.bean.model.WalletExtend;
 import com.yami.trading.common.constants.Constants;
 import com.yami.trading.common.domain.Result;
 import com.yami.trading.common.exception.YamiShopBindException;
@@ -16,6 +18,7 @@
 import com.yami.trading.service.MoneyLogService;
 import com.yami.trading.service.WalletService;
 import com.yami.trading.service.contract.ContractOrderService;
+import com.yami.trading.service.item.ItemService;
 import lombok.extern.slf4j.Slf4j;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,10 +47,24 @@
     @Autowired
     MoneyLogService moneyLogService;
 
+    @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;
+        }
     }
 
     /**
@@ -122,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);
 
             // 保存资金日志
@@ -138,14 +160,44 @@
             moneyLog.setAmountBefore(new BigDecimal(amount_before));
             moneyLog.setAmount(new BigDecimal(amount1));
             moneyLog.setAmountAfter(BigDecimal.valueOf(Arith.add(amount_before, amount1)));
-            moneyLog.setLog("后台手动充值");
+            moneyLog.setLog("后台手动充值/扣款");
             moneyLog.setUserId(userId);
             moneyLog.setWalletType(Constants.WALLET);
             moneyLog.setContentType(Constants.MONEYLOG_CONTENT_RECHARGE);
             moneyLog.setCreateTime(new Date());
             moneyLogService.save(moneyLog);
         } else {
-            throw new YamiShopBindException("只支持usdt");
+            Item item = itemService.findBySymbol(coinType);
+            if (item == null) {
+                throw new YamiShopBindException("暂不支持的币种");
+            }
+            WalletExtend walletExtend = new WalletExtend();
+            walletExtend = walletService.saveExtendByPara(userId, coinType);
+
+            double volume = moneyRevise.doubleValue();
+
+            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);
+
+            // 保存资金日志
+            MoneyLog moneyLog = new MoneyLog();
+            moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
+            moneyLog.setAmountBefore(new BigDecimal(amount_before));
+            moneyLog.setAmount(new BigDecimal(volume));
+            moneyLog.setAmountAfter(new BigDecimal(Arith.add(amount_before, volume)));
+
+            moneyLog.setLog("后台手动充值/扣款");
+            moneyLog.setUserId(userId);
+            moneyLog.setWalletType(coinType);
+            moneyLog.setContentType(Constants.MONEYLOG_CONTENT_RECHARGE);
+            moneyLog.setCreateTime(new Date());
+            moneyLogService.save(moneyLog);
         }
         return Result.succeed();
     }

--
Gitblit v1.9.3