From 68b9175323a2f9b40ffcc48bb01af1d8279e5d01 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Fri, 22 Aug 2025 10:21:51 +0800
Subject: [PATCH] 平仓返回保证金修改
---
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java | 159 +++++++++++++++++++++++++---------------------------
1 files changed, 77 insertions(+), 82 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
index 726822e..6224d60 100644
--- a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -88,14 +88,10 @@
@Autowired
StockMapper stockMapper;
@Autowired
- AgentAgencyFeeMapper agentAgencyFeeMapper;
- @Autowired
IAgentAgencyFeeService iAgentAgencyFeeService;
@Autowired
ISiteProductService iSiteProductService;
- @Autowired
- FundsApplyMapper fundsApplyMapper;
@Autowired
UserStockSubscribeMapper userStockSubscribeMapper;
@Resource
@@ -103,12 +99,6 @@
@Resource
UserIndexPositionMapper userIndexPositionMapper;
- @Autowired
- IStockFuturesService iStockFuturesService;
- @Autowired
- IStockCoinService iStockCoinService;
- @Autowired
- CurrencyUtils currencyUtils;
@Resource
StockDzMapper stockDzMapper;
@@ -189,16 +179,16 @@
BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
- BigDecimal finalBuyAmt = buyAmt;
- //如果不是墨西哥币需要转换金额
- if (!stock.getStockType().equals(EStockType.MX.getCode())) {
- buyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt);
- }
+ //手续费
BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
-
+ BigDecimal needBuyAmt = buyAmt.add(orderFree);
+ //资金校验
+ if (!stock.getStockType().equals(EStockType.MX.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();
@@ -227,7 +217,7 @@
}
userPosition.setIsLock(Integer.valueOf(0));
userPosition.setOrderLever(lever);
- userPosition.setOrderTotalPrice(finalBuyAmt);
+ userPosition.setOrderTotalPrice(buyAmt);
// 手续费
userPosition.setOrderFee(orderFree);
@@ -1767,81 +1757,86 @@
* @return
*/
@Transactional(rollbackFor = Exception.class)
- public ServerResponse buyDz(Integer dzId, String password, Integer num, HttpServletRequest request) throws Exception {
- /*实名认证开关开启*/
- SiteProduct siteProduct = iSiteProductService.getProductSetting();
- User user = this.iUserService.getCurrentRefreshUser(request);
+ public ServerResponse buyDz(Integer dzId, String password, Integer num, HttpServletRequest request){
+ try {
+ /*实名认证开关开启*/
+ SiteProduct siteProduct = iSiteProductService.getProductSetting();
+ User user = this.iUserService.getCurrentRefreshUser(request);
- if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) {
- return ServerResponse.createByErrorMsg("Order failed, please first real name authentication");
- }
- if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
- return ServerResponse.createByErrorMsg("Order failed, account has been locked");
- }
- StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", dzId));
- if (StringUtils.isNotEmpty(stockDz.getPassword()) && !Objects.equals(stockDz.getPassword(), password)) {
- return ServerResponse.createByErrorMsg("密码错误", request);
- }
- if (stockDz.getIsLock() != 0) {
- return ServerResponse.createByErrorMsg("股票被锁定,不能购买", request);
- }
- //价格处理
- Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", stockDz.getStockCode()));
+ if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) {
+ return ServerResponse.createByErrorMsg("Order failed, please first real name authentication");
+ }
+ if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
+ return ServerResponse.createByErrorMsg("Order failed, account has been locked");
+ }
+ StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", dzId));
+ if (StringUtils.isNotEmpty(stockDz.getPassword()) && !Objects.equals(stockDz.getPassword(), password)) {
+ return ServerResponse.createByErrorMsg("密码错误", request);
+ }
+ if (stockDz.getIsLock() != 0) {
+ return ServerResponse.createByErrorMsg("股票被锁定,不能购买", request);
+ }
+ //价格处理
+ Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", stockDz.getStockCode()));
- UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(stock.getStockType(), user.getId());
- if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
- return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
- }
+ UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(stock.getStockType(), user.getId());
+ if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
+ return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
+ }
- if(stockDz.getStartTime().getTime() > new Date().getTime() || stockDz.getEndTime().getTime() < new Date().getTime()){
- return ServerResponse.createByErrorMsg("不在内幕交易时间之内", request);
- }
+ if(stockDz.getStartTime().getTime() > new Date().getTime() || stockDz.getEndTime().getTime() < new Date().getTime()){
+ return ServerResponse.createByErrorMsg("不在内幕交易时间之内", request);
+ }
// BigDecimal nowPrice = priceServices.getNowPrice(stockDz.getStockCode()).multiply(stockDz.getDiscount());
- BigDecimal nowPrice = stockDz.getNowPrice();
+ BigDecimal nowPrice = stockDz.getNowPrice();
- if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
- return ServerResponse.createByErrorMsg("股票价格0,请重试", request);
- }
- if (stockDz.getStockNum() > num) {
- return ServerResponse.createByErrorMsg("最小购买数据" + stockDz.getStockNum(), request);
- }
+ if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
+ return ServerResponse.createByErrorMsg("股票价格0,请重试", request);
+ }
+ if (stockDz.getStockNum() > num) {
+ return ServerResponse.createByErrorMsg("最小购买数据" + stockDz.getStockNum(), request);
+ }
- BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
+ BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
- BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(num.intValue()));
- BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
- BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
- BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance());
- if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) {
- return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
- }
+ BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(num.intValue()));
+ BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
+ BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
+ BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance());
+ if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) {
+ return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
+ }
- BigDecimal newBuyAmt = buyAmt;
- //如果不是墨西哥币需要转换金额
- if (!stock.getStockType().equals(EStockType.MX.getCode())) {
- newBuyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt);
- }
- if(newBuyAmt.compareTo(userAssets.getAvailableBalance()) > 0){
- return ServerResponse.createByErrorMsg("可用余额不足" + userAssets.getAvailableBalance(), request);
- }
+ BigDecimal newBuyAmt = buyAmt;
+ //如果不是墨西哥币需要转换金额
+ if (!stock.getStockType().equals(EStockType.MX.getCode())) {
+ newBuyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt);
+ }
+ if(newBuyAmt.compareTo(userAssets.getAvailableBalance()) > 0){
+ return ServerResponse.createByErrorMsg("可用余额不足" + userAssets.getAvailableBalance(), request);
+ }
- //判断审核开关
- if(stockDz.getSwitchType() == 1) {
+ //判断审核开关
+ if(stockDz.getSwitchType() == 1) {
+ UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt);
+ UserPositionCheckDz userPositionCheckDz = Convert.convert(UserPositionCheckDz.class, userPosition);
+ userPositionCheckDz.setDzId(dzId);
+ userPositionCheckDzService.save(userPositionCheckDz);
+ return ServerResponse.createBySuccess("购买成功,等待审核", request);
+ }
+
+ // 创建UserPosition对象
UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt);
- UserPositionCheckDz userPositionCheckDz = Convert.convert(UserPositionCheckDz.class, userPosition);
- userPositionCheckDz.setDzId(dzId);
- userPositionCheckDzService.save(userPositionCheckDz);
- return ServerResponse.createBySuccess("购买成功,等待审核", request);
+ userPositionMapper.insert(userPosition);
+ BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(newBuyAmt);
+ //已经转化 直接穿MEX类型
+ userAssetsServices.availablebalanceChange(EStockType.MX.getCode(), user.getId(), EUserAssets.BUY, newBuyAmt.negate(),"","");
+ iUserAssetsServices.availablebalanceChange(EStockType.MX.getCode(), userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", "");
+ return ServerResponse.createBySuccess("购买成功", request);
+ } catch (Exception e) {
+ log.error("大宗下单异常{}", e.getMessage());
}
-
- // 创建UserPosition对象
- UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt);
- userPositionMapper.insert(userPosition);
- BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(newBuyAmt);
- //已经转化 直接穿MEX类型
- userAssetsServices.availablebalanceChange(EStockType.MX.getCode(), user.getId(), EUserAssets.BUY, newBuyAmt.negate(),"","");
- iUserAssetsServices.availablebalanceChange(EStockType.MX.getCode(), userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", "");
- return ServerResponse.createBySuccess("购买成功", request);
+ return ServerResponse.createByError();
}
private UserPosition getUserPosition(Integer dzId,Integer num, User user, StockDz stockDz, BigDecimal nowPrice, Stock stock, BigDecimal buyAmt) {
--
Gitblit v1.9.3