From b8301f003ffec987f9e2ececf2c708a16e29116f Mon Sep 17 00:00:00 2001
From: peter <14100000001@qq.com>
Date: Sat, 15 Nov 2025 14:16:16 +0800
Subject: [PATCH] 修改购买金额问题

---
 src/main/java/com/nq/service/impl/UserPositionServiceImpl.java |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
index 319e0f6..15fc5c1 100644
--- a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -35,6 +35,7 @@
 
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.sql.Timestamp;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
@@ -207,6 +208,7 @@
             }
             //判断是否盘前,和价格
             StockSetting stockSetting = tradingHourService.preMarketPrice(stock.getStockCode());
+            BigDecimal buyAmtNew = BigDecimal.ZERO;
             if(null != preMarketPrice && preMarketPrice.compareTo(new BigDecimal(0)) > 0 && null != stockSetting && preMarketPrice.compareTo(new BigDecimal(stockSetting.getPrice())) != 0){
                 //挂单
                 UserPendingorder userPendingorder = new UserPendingorder();
@@ -221,8 +223,11 @@
                 userPendingorder.setTargetPrice(preMarketPrice);
                 userPendingorder.setAddTime(new Date());
                 userPendingorder.setStatus(0);
-                userPendingorder.setBuyAmt(buyAmt);
+                buyAmtNew = preMarketPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
+                userPendingorder.setBuyAmt(buyAmtNew);
                 int ret = userPendingorderMapper.insert(userPendingorder);
+                buyAmt = userPendingorder.getBuyAmt();
+                orderFree = siteSettingBuyFee.multiply(buyAmt);
             }else {
                 userPosition.setPositionType(user.getAccountType());
                 userPosition.setPositionSn(KeyUtils.getUniqueKey());
@@ -235,7 +240,7 @@
                 userPosition.setStockSpell(stock.getStockSpell());
                 userPosition.setBuyOrderId(GeneratePosition.getPositionId());
                 userPosition.setBuyOrderTime(new Date());
-                userPosition.setBuyOrderPrice(nowPrice);
+                userPosition.setBuyOrderPrice(null == preMarketPrice ? nowPrice : preMarketPrice);
                 userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌");
                 userPosition.setOrderNum(buyNum);
                 if (stock.getStockPlate() != null) {
@@ -245,7 +250,7 @@
                 userPosition.setOrderLever(lever);
                 userPosition.setOrderTotalPrice(buyAmt);
                 // 手续费
-
+                buyAmtNew = buyAmt;
                 userPosition.setOrderFee(orderFree);
                 userPosition.setOrderSpread(BigDecimal.ZERO);
                 userPosition.setSpreadRatePrice(BigDecimal.ZERO);
@@ -257,7 +262,7 @@
                 userPositionMapper.insert(userPosition);
 
             }
-            iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", "");
+            iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmtNew.negate(), "", "");
             iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", "");
             return ServerResponse.createBySuccessMsg("下单成功", request);
         }

--
Gitblit v1.9.3