zyy
2025-08-11 fd112c08c7bdc1b549c92d1e851f948c3410c502
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -177,20 +177,20 @@
                    return ServerResponse.createByErrorMsg("报价0,请稍后再试", request);
                }
                BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
                BigDecimal finalBuyAmt = buyAmt;
                //如果不是默认货币需要转换金额
                if (!stock.getStockType().equals(EStockType.getDefault().getCode())) {
                    buyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt);
                }
                //手续费
                BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
                BigDecimal needBuyAmt = buyAmt.add(orderFree);
                //资金校验
                /*if (!stock.getStockType().equals(EStockType.getDefault().getCode())) {
                    needBuyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt);
                }*/
                BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
                BigDecimal availableBalance =  fundratio.multiply(userAssets.getAvailableBalance());
                if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) {
                if (availableBalance.compareTo(needBuyAmt) < 0) {
                    return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
                }
                UserPosition userPosition = new UserPosition();
                if (profitTarget != null && profitTarget.compareTo(new BigDecimal("0")) > 0) {
                    userPosition.setProfitTargetPrice(profitTarget);
@@ -217,7 +217,7 @@
                }
                userPosition.setIsLock(Integer.valueOf(0));
                userPosition.setOrderLever(lever);
                userPosition.setOrderTotalPrice(finalBuyAmt);
                userPosition.setOrderTotalPrice(buyAmt);
                // 手续费
                userPosition.setOrderFee(orderFree);
@@ -1809,9 +1809,9 @@
            BigDecimal newBuyAmt = buyAmt;
            //如果不是默认货币需要转换金额
            if (!stock.getStockType().equals(EStockType.getDefault().getCode())) {
            /*if (!stock.getStockType().equals(EStockType.getDefault().getCode())) {
                newBuyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt);
            }
            }*/
            if(newBuyAmt.compareTo(userAssets.getAvailableBalance()) > 0){
                return ServerResponse.createByErrorMsg("可用余额不足" + userAssets.getAvailableBalance(), request);
            }
@@ -1829,9 +1829,9 @@
            UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt);
            userPositionMapper.insert(userPosition);
            BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(newBuyAmt);
            //已经转化 直接传默认类型
            userAssetsServices.availablebalanceChange(EStockType.getDefault().getCode(), user.getId(), EUserAssets.BUY, newBuyAmt.negate(),"","");
            iUserAssetsServices.availablebalanceChange(EStockType.getDefault().getCode(), userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", "");
            userAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, newBuyAmt.negate(),"","");
            iUserAssetsServices.availablebalanceChange(stock.getStockType(), userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", "");
            return ServerResponse.createBySuccess("购买成功", request);
        } catch (Exception e) {
            log.error("大宗下单异常{}", e.getMessage());