From 965450925b22fb9166687caa5bb663cd846cba14 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Fri, 21 Aug 2020 14:56:14 +0800
Subject: [PATCH] 20200821

---
 src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java |   27 +++++++++
 src/main/resources/i18n/messages_zh_CN.properties                                    |    1 
 src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java           |   14 ++++
 src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java        |   98 ++++++++++++++++++++++++++++++++
 src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java                 |    2 
 src/main/resources/i18n/messages_en_US.properties                                    |    1 
 6 files changed, 143 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java b/src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
index 4274413..7166929 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
@@ -22,6 +22,7 @@
 import org.springframework.web.bind.annotation.RestController;
 
 import com.xcong.excoin.common.response.Result;
+import com.xcong.excoin.modules.coin.parameter.dto.ContractInTransferDto;
 import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto;
 import com.xcong.excoin.modules.coin.parameter.dto.TransferOfBalanceDto;
 import com.xcong.excoin.modules.coin.parameter.dto.TransferOfBalanceFromAgentDto;
@@ -212,6 +213,19 @@
 	}
 	
 	/**
+	 * 合约账户内部划转(合约多账户)
+	 * @return
+	 */
+	@ApiOperation(value="合约账户内部划转(合约多账户)", notes="合约账户内部划转(合约多账户)")
+	@PostMapping(value="/contractInTransfer")
+	public Result contractInTransfer(@RequestBody @Valid ContractInTransferDto contractInTransferDto) {
+		BigDecimal balance = contractInTransferDto.getBalance();
+		String symbolIn = contractInTransferDto.getSymbolIn();
+		String symbolOut = contractInTransferDto.getSymbolOut();
+		return coinService.contractInTransfer(balance,symbolIn,symbolOut);
+	}
+	
+	/**
 	 * 代理账户划转到USDT账户
 	 * @return
 	 */
diff --git a/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java b/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java
new file mode 100644
index 0000000..4ac829c
--- /dev/null
+++ b/src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java
@@ -0,0 +1,27 @@
+package com.xcong.excoin.modules.coin.parameter.dto;
+
+import java.math.BigDecimal;
+
+import javax.validation.constraints.NotNull;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(value = "ContractInTransferDto", description = "参数接收类")
+public class ContractInTransferDto {
+	
+	@NotNull(message = "划转金额不能为空")
+    @ApiModelProperty(value = "划转金额", example = "100")
+    private BigDecimal balance;
+
+	@NotNull(message = "币种不能为空")
+    @ApiModelProperty(value = "转入币种", example = "USDT")
+    private String symbolIn;
+	
+	@NotNull(message = "币种不能为空")
+	@ApiModelProperty(value = "转出币种", example = "BTC")
+	private String symbolOut;
+
+}
diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java b/src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
index 8189cc2..6bac866 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
@@ -47,4 +47,6 @@
 
 	public Result getContractSymbolList();
 
+	public Result contractInTransfer(BigDecimal balance, String symbolIn, String symbolOut);
+
 }
diff --git a/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java b/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
index a3b8549..1ce5f47 100644
--- a/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -813,4 +813,102 @@
 		return Result.ok(list);
 	}
 
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public Result contractInTransfer(BigDecimal balance, String symbolIn, String symbolOut) {
+		//获取用户ID
+        Long memberId = LoginUserUtils.getAppLoginUser().getId();
+        //转入转出不能是同一账户
+        if(symbolIn.equals(symbolOut)) {
+        	return Result.fail(MessageSourceUtils.getString("member_service_0098"));
+        }
+        if (balance.compareTo(BigDecimal.ZERO) <= 0) {
+    		return Result.fail(MessageSourceUtils.getString("member_service_0004"));
+    	}
+        
+        MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbolOut);
+    	BigDecimal availableBalance = walletContract.getAvailableBalance();
+    	// 扣币
+    	BigDecimal availableSubtract = availableBalance.subtract(balance);
+    	if (availableSubtract.compareTo(BigDecimal.ZERO) < 0) {
+    		return Result.fail(MessageSourceUtils.getString("member_service_0007"));
+    	}
+    	BigDecimal totalBalance = walletContract.getTotalBalance();
+    	BigDecimal totalSubtract = totalBalance.subtract(balance);
+    	
+    	walletContract.setAvailableBalance(availableSubtract);
+    	walletContract.setTotalBalance(totalSubtract);
+    	int updateWalletCoinById = memberWalletContractDao.updateById(walletContract);
+    	if (updateWalletCoinById < 1) {
+    		return Result.fail(MessageSourceUtils.getString("member_service_0096"));
+    	}
+    	
+    	//更新合约全仓模式下的订单权益
+        MemberEntity memberEntity = memberDao.selectById(memberId);
+        String symbols = symbolOut+"/USDT";
+        ThreadPoolUtils.sendWholeForceClosingPrice(symbols, memberEntity);
+        
+        // 加币
+        // 查询合约账户
+        MemberWalletContractEntity walletContractIn = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbolIn);
+        BigDecimal availableBalanceIn = walletContractIn.getAvailableBalance();
+        BigDecimal addIn = availableBalanceIn.add(balance);
+        walletContractIn.setAvailableBalance(addIn);
+        BigDecimal totalBalanceIn = walletContractIn.getTotalBalance();
+        BigDecimal totalBigDecimalIn = totalBalanceIn.add(balance);
+        walletContractIn.setTotalBalance(totalBigDecimalIn);
+        int updateWalletContractById = memberWalletContractDao.updateById(walletContractIn);
+        if (updateWalletContractById < 1) {
+            return Result.fail(MessageSourceUtils.getString("member_service_0096"));
+        }
+        
+        //更新合约全仓模式下的订单权益
+        String symbolIns = symbolIn+"/USDT";
+        ThreadPoolUtils.sendWholeForceClosingPrice(symbolIns, memberEntity);
+        
+        //添加币币资金划转历史记录
+        MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
+        memberAccountRecord.setContent("转出至合约"+symbolIn+"账户");
+        memberAccountRecord.setMemberId(memberId);
+        memberAccountRecord.setAmount(balance.negate());
+        memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
+        memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
+        memberAccountMoneyChangeDao.insert(memberAccountRecord);
+
+        //添加合约资金划转历史记录
+        memberAccountRecord.setContent("由合约"+symbolOut+"账户转入至合约"+symbolIn+"账户");
+        memberAccountRecord.setAmount(balance);
+        memberAccountMoneyChangeDao.insert(memberAccountRecord);
+        
+        return Result.ok(MessageSourceUtils.getString("member_service_0006"));
+	}
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+	
+
 }
diff --git a/src/main/resources/i18n/messages_en_US.properties b/src/main/resources/i18n/messages_en_US.properties
index dc42e05..300eeb3 100644
--- a/src/main/resources/i18n/messages_en_US.properties
+++ b/src/main/resources/i18n/messages_en_US.properties
@@ -139,6 +139,7 @@
 member_service_0095=Insufficient available balance of agent usdt account
 member_service_0096=Transfer fail
 member_service_0097=Payment method already exists
+member_service_0098=Please select another account
 
 order_service_0001=Wrong parameter value
 order_service_0002=Not logged in
diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties
index 01c4b5a..335a593 100644
--- a/src/main/resources/i18n/messages_zh_CN.properties
+++ b/src/main/resources/i18n/messages_zh_CN.properties
@@ -139,6 +139,7 @@
 member_service_0095=代理USDT账户可用余额不足
 member_service_0096=划转失败
 member_service_0097=支付方式已存在
+member_service_0098=请选择其他账户
 
 order_service_0001=参值有误
 order_service_0002=未登录

--
Gitblit v1.9.1