From 16f5baf41e3224ccb43fce45de968833f9f022d2 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Sat, 06 Jun 2026 22:11:39 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java |   75 ++++++++++++++++++++++++++++---------
 1 files changed, 57 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java b/src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java
index 7b33ddf..69c29db 100644
--- a/src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserWithdrawServiceImpl.java
@@ -171,22 +171,27 @@
 
 
             synchronized (UserWithdrawServiceImpl.class){
-            //可取港币资金
-            BigDecimal hkAmt=user.getEnaleWithdrawAmt();
+            BigDecimal withdrawAmt = new BigDecimal(amt);
+            BigDecimal enableWithdrawAmt = user.getEnaleWithdrawAmt() == null ? BigDecimal.ZERO : user.getEnaleWithdrawAmt();
+            BigDecimal enableAmt = user.getEnableAmt() == null ? BigDecimal.ZERO : user.getEnableAmt();
 
-            int compareAmt = hkAmt.compareTo(new BigDecimal(amt));
-
-            if (compareAmt == -1) {
+            if (enableWithdrawAmt.compareTo(withdrawAmt) < 0) {
 
                 return ServerResponse.createByErrorMsg("提现失败,用户可取港币资金不足");
 
             }
 
-            BigDecimal reckon_hkAmt = hkAmt.subtract(new BigDecimal(amt));
+            if (enableAmt.compareTo(withdrawAmt) < 0) {
 
-            user.setEnaleWithdrawAmt(reckon_hkAmt);
+                return ServerResponse.createByErrorMsg("提现失败,用户可用资金不足");
 
-            log.info("提现前,港币金额={},提现后,港币金额={}",hkAmt,reckon_hkAmt);
+            }
+
+            BigDecimal reckonEnableWithdrawAmt = enableWithdrawAmt.subtract(withdrawAmt);
+
+            user.setEnaleWithdrawAmt(reckonEnableWithdrawAmt);
+
+            log.info("提现申请,用户 {} 冻结可取资金,原金额 = {} , 冻结后 = {}", user.getId(), enableWithdrawAmt, reckonEnableWithdrawAmt);
 
             int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
 
@@ -305,17 +310,14 @@
 
             User user = this.userMapper.selectByPrimaryKey(userWithdraw.getUserId());
 
-            user.setUserAmt(user.getUserAmt().add(userWithdraw.getWithAmt()));
-
-            user.setEnableAmt(user.getEnableAmt().add(userWithdraw.getWithAmt()));
-
-            user.setEnaleWithdrawAmt(user.getEnaleWithdrawAmt().add(userWithdraw.getWithAmt()));
+            BigDecimal enableWithdrawAmt = user.getEnaleWithdrawAmt() == null ? BigDecimal.ZERO : user.getEnaleWithdrawAmt();
+            user.setEnaleWithdrawAmt(enableWithdrawAmt.add(userWithdraw.getWithAmt()));
 
             int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user);
 
             if (updateUserCount > 0) {
 
-                log.info("反还用户资金,总 {} 可用 {}", user.getUserAmt(), user.getEnableAmt());
+                log.info("用户取消提现,返还可取资金 {}", userWithdraw.getWithAmt());
 
                 return ServerResponse.createBySuccessMsg("取消成功");
 
@@ -413,6 +415,7 @@
     }
 
 
+    @Transactional
     public ServerResponse updateState(Integer withId, Integer state, String authMsg) throws Exception {
 
         UserWithdraw userWithdraw = this.userWithdrawMapper.selectByPrimaryKey(withId);
@@ -440,6 +443,42 @@
         }
 
 
+        if (state.intValue() == 1) {
+
+            User user = this.userMapper.selectByPrimaryKey(userWithdraw.getUserId());
+
+            if (user == null) {
+
+                return ServerResponse.createByErrorMsg("用户不存在");
+
+            }
+
+            BigDecimal withAmt = userWithdraw.getWithAmt();
+            BigDecimal enableAmt = user.getEnableAmt() == null ? BigDecimal.ZERO : user.getEnableAmt();
+
+            if (enableAmt.compareTo(withAmt) < 0) {
+
+                return ServerResponse.createByErrorMsg("用户可用资金不足,无法完成提现");
+
+            }
+
+            BigDecimal afterEnableAmt = enableAmt.subtract(withAmt);
+
+            user.setEnableAmt(afterEnableAmt);
+
+            log.info("管理员确认提现成功,扣减用户 {} 可用资金,原金额 = {} , 扣减后 = {}", user.getId(), enableAmt, afterEnableAmt);
+
+            int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
+
+            if (updateCount <= 0) {
+
+                throw new Exception("修改用户资金出错,抛出异常");
+
+            }
+
+        }
+
+
         if (state.intValue() == 2) {
 
 
@@ -451,12 +490,12 @@
 
             }
 
-            //计算返还的总港币金额
-            BigDecimal hkAmt = user.getHkAmt().add(userWithdraw.getWithAmt());
+            BigDecimal enableWithdrawAmt = user.getEnaleWithdrawAmt() == null ? BigDecimal.ZERO : user.getEnaleWithdrawAmt();
+            BigDecimal refundAmt = enableWithdrawAmt.add(userWithdraw.getWithAmt());
 
-            log.info("管理员确认提现订单失败,返还用户 {} 总资金,原金额 = {} , 返还后 = {}", new Object[]{user.getId(), user.getHkAmt(), hkAmt});
+            log.info("管理员确认提现订单失败,返还用户 {} 可取资金,原金额 = {} , 返还后 = {}", user.getId(), enableWithdrawAmt, refundAmt);
 
-            user.setHkAmt(hkAmt);
+            user.setEnaleWithdrawAmt(refundAmt);
             int updateCount = this.userMapper.updateByPrimaryKeySelective(user);
 
             if (updateCount > 0) {

--
Gitblit v1.9.3