From 7d80267c3797e557d9d38494306b402c908210c6 Mon Sep 17 00:00:00 2001
From: peternameyakj <908253177@qq.com>
Date: Mon, 12 Aug 2024 15:15:28 +0800
Subject: [PATCH] 新增资金账户以及与交易账户的互转
---
src/main/java/project/wallet/internal/WalletGatherServiceImpl.java | 39 ++++++++++++++++++++++++---------------
1 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java b/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java
index f79b557..3ca985f 100644
--- a/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java
+++ b/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java
@@ -244,21 +244,30 @@
public ResultObject transferExtendtoGather(WalletGather walletGather,WalletExtend walletExtend,String currency,double amount){
ResultObject resultObject = new ResultObject();
resultObject.setCode("0");
- if(new BigDecimal(walletExtend.getAmount()).compareTo(new BigDecimal(amount)) >= 0){
- if("usdt".equals(currency)){
- walletGather.setUsdtMoney(Arith.add(walletGather.getUsdtMoney(), amount));
- }else if("btc".equals(currency)){
- walletGather.setBtcMoney(Arith.add(walletGather.getBtcMoney(), amount));
- }else if("eth".equals(currency)){
- walletGather.setEthMoney(Arith.add(walletGather.getEthMoney(), amount));
- }else if("usdc".equals(currency)){
- walletGather.setUsdcMoney(Arith.add(walletGather.getUsdcMoney(), amount));
+ if("usdt".equals(currency)){
+ Wallet wallet = walletService.saveWalletByPartyId(walletExtend.getPartyId());
+ if(wallet.getMoney() < amount){
+ resultObject.setCode("1");
+ resultObject.setMsg("划转资金不足");
+ return resultObject;
}
+ walletGather.setUsdtMoney(Arith.add(walletGather.getUsdtMoney(), amount));
}else {
- resultObject.setCode("1");
- resultObject.setMsg("划转资金不足");
- return resultObject;
+ if(new BigDecimal(walletExtend.getAmount()).compareTo(new BigDecimal(amount)) >= 0){
+ if("btc".equals(currency)){
+ walletGather.setBtcMoney(Arith.add(walletGather.getBtcMoney(), amount));
+ }else if("eth".equals(currency)){
+ walletGather.setEthMoney(Arith.add(walletGather.getEthMoney(), amount));
+ }else if("usdc".equals(currency)){
+ walletGather.setUsdcMoney(Arith.add(walletGather.getUsdcMoney(), amount));
+ }
+ }else {
+ resultObject.setCode("1");
+ resultObject.setMsg("划转资金不足");
+ return resultObject;
+ }
}
+
ApplicationUtil.executeUpdate(walletGather);
redisHandler.setAsyn(WalletRedisKeys.WALLET_GATHER_PARTY_ID + walletGather.getPartyId().toString(),walletGather);
@@ -283,7 +292,7 @@
return resultObject;
}
}else if("btc".equals(currency)){
- if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+ if(new BigDecimal(walletGather.getBtcMoney()).compareTo(new BigDecimal(amount)) >= 0){
walletGather.setBtcMoney(Arith.sub(walletGather.getBtcMoney(), amount));
}else {
resultObject.setCode("1");
@@ -291,7 +300,7 @@
return resultObject;
}
}else if("eth".equals(currency)){
- if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+ if(new BigDecimal(walletGather.getEthMoney()).compareTo(new BigDecimal(amount)) >= 0){
walletGather.setEthMoney(Arith.sub(walletGather.getEthMoney(), amount));
}else {
resultObject.setCode("1");
@@ -299,7 +308,7 @@
return resultObject;
}
}else if("usdc".equals(currency)){
- if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+ if(new BigDecimal(walletGather.getUsdcMoney()).compareTo(new BigDecimal(amount)) >= 0){
walletGather.setUsdcMoney(Arith.sub(walletGather.getUsdcMoney(), amount));
}else {
resultObject.setCode("1");
--
Gitblit v1.9.3