From 11cb582d69d25bbfea5b62df940ace93aa1dbe4f Mon Sep 17 00:00:00 2001
From: zainali5120 <512061637@qq.com>
Date: Sun, 31 May 2020 21:23:05 +0800
Subject: [PATCH] 合约持仓方法添加

---
 src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java |   28 ++++++++++++----------------
 1 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java b/src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
index 6d4af30..5d4ebf0 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/service/impl/OrderCoinServiceImpl.java
@@ -43,7 +43,9 @@
 import com.xcong.excoin.modules.platform.dao.PlatformCnyUsdtExchangeDao;
 import com.xcong.excoin.modules.platform.dao.TradeSettingDao;
 import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity;
+import com.xcong.excoin.utils.CoinTypeConvert;
 import com.xcong.excoin.utils.MessageSourceUtils;
+import com.xcong.excoin.utils.RedisUtils;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
@@ -67,6 +69,8 @@
 	OrderCoinDealDao orderCoinDealDao;
 	@Resource
 	MemberAccountFlowEntityDao memberAccountFlowEntityDao;
+    @Resource
+    RedisUtils redisUtils;
 	
 	@Override
 	public String generateSimpleSerialno(String userId) {
@@ -110,12 +114,8 @@
 		//获取USDT的币币账户信息
 		MemberWalletCoinEntity walletCoinUsdt = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, 
 															MemberWalletCoinEnum.WALLETCOINCODE.getValue());
-		/**
-		 * todo
-		 */
-		//获取某个币种的收盘价
-		//Double closePrice = symbolsService.getCloseSymbolsBySymbolsName(symbol+"/USDT");
-		BigDecimal closePrice = new BigDecimal("100.0000");
+		
+		BigDecimal closePrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol+"/USDT")));
 		
 		List<MemberSelectSymbolsEntity> memSymbols = memberSelectSymbolsDao.selectSymbolByMemIdAndSymbol(memberId, symbol);
 
@@ -154,18 +154,13 @@
 
 	@Override
 	@Transactional
-	public Result submitSalesWalletCoinOrder(String symbol, Integer type, Integer tradeType, BigDecimal price,
-			BigDecimal amount) {
+	public Result submitSalesWalletCoinOrder(String symbol, Integer type, Integer tradeType, BigDecimal price,BigDecimal amount) {
 			//获取用户ID
 			Long memberId = LoginUserUtils.getAppLoginUser().getId();
 			
-			/**
-			 * todo
-			*/
 			//查询当前价
-			//BigDecimal nowPrice = new BigDecimal(redisUtil.getString(CoinTypeConConvert.convertToKey(symbol+"/USDT")));
+			BigDecimal nowPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(symbol+"/USDT")));
 			
-			BigDecimal nowPrice = new BigDecimal("10.0000");
 			// 获取交易管理的杠杠倍率,手续费率等信息,由平台进行设置
 			symbol = symbol.toUpperCase();
 			MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, symbol);
@@ -278,7 +273,8 @@
 					walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().subtract(amount).setScale(4, BigDecimal.ROUND_DOWN));
 					memberWalletCoinDao.updateById(walletCoin);
 					
-					walletCoinUsdt.setAvailableBalance(walletCoinUsdt.getAvailableBalance().add(totalPayPrice).setScale(4, BigDecimal.ROUND_DOWN));
+					BigDecimal subtract = totalPayPrice.subtract(closingPrice).subtract(closingPrice);
+					walletCoinUsdt.setAvailableBalance(walletCoinUsdt.getAvailableBalance().add(subtract).setScale(4, BigDecimal.ROUND_DOWN));
 					memberWalletCoinDao.updateById(walletCoinUsdt);
 				}
 			}
@@ -335,7 +331,7 @@
 					
 					String symbol = orderCoinsEntity.getSymbol();
 					
-					if(orderCoinsEntity.getOrderType() == OrderCoinsEntity.TRADETYPE_FIXEDPRICE) {
+					if(OrderCoinsEntity.ORDERTYPE_BUY.equals(orderCoinsEntity.getOrderType())) {
 						//如果是限价买入,撤单将USDT账户冻结金额返回
 						String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
 						MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
@@ -343,7 +339,7 @@
 						if (ObjectUtil.isNotEmpty(walletCoin)) {
 							//手续费 = 开仓价*数量*手续费率
 							//返还金额=开仓价*未成交数量+手续费
-							BigDecimal returnBalance = orderCoinsEntity.getDealAmount().add(orderCoinsEntity.getFeeAmount());
+							BigDecimal returnBalance = orderCoinsEntity.getDealAmount();
 							
 							walletCoin.setAvailableBalance(walletCoin.getAvailableBalance().add(returnBalance).setScale(4, BigDecimal.ROUND_DOWN));
 							walletCoin.setFrozenBalance(walletCoin.getFrozenBalance().subtract(returnBalance).setScale(4, BigDecimal.ROUND_DOWN));

--
Gitblit v1.9.1