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 | 154 ++++++++++++++++++++++++++++-----------------------
1 files changed, 84 insertions(+), 70 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
index bb30fa6..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;
@@ -187,12 +177,18 @@
return ServerResponse.createByErrorMsg("报价0,请稍后再试", request);
}
- BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
- BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
- BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
+ BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
+ //手续费
+ 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();
@@ -1761,71 +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);
+ }
- //判断审核开关
- if(stockDz.getSwitchType() == 1) {
+ 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) {
+ 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(buyAmt);
- userAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"","");
- iUserAssetsServices.availablebalanceChange(stock.getStockType(), 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) {
@@ -2177,6 +2188,9 @@
userPositionCheckDzService.updateById(userPositionCheckDz);
return ServerResponse.createBySuccess("审核成功", request);
}
+ if (orderNum > userPositionCheckDz.getOrderNum()) {
+ return ServerResponse.createByErrorMsg("输入数量大于用户买入数量", request);
+ }
User user = userMapper.selectById(userPositionCheckDz.getUserId());
StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", userPositionCheckDz.getDzId()));
@@ -2206,7 +2220,7 @@
userPosition.setId(null);
userPosition.setDzId(stockDz.getId());
userPositionMapper.insert(userPosition);
- userAssetsServices.availablebalanceChange(userAssets.getAccectType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", "");
+ userAssetsServices.availablebalanceChange(stockDz.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", "");
return ServerResponse.createBySuccessMsg("审核成功,订单已转客户持仓", request);
} catch (Exception e) {
return ServerResponse.createByErrorMsg(e.getMessage());
--
Gitblit v1.9.3