From f23b33bbb9eaff76cac5b69e3b793fc7910fb0fa Mon Sep 17 00:00:00 2001
From: peternameyakj <908253177@qq.com>
Date: Tue, 30 Jul 2024 11:03:37 +0800
Subject: [PATCH] 新增资金账户以及与交易账户的互转
---
src/main/java/project/Constants.java | 18 +
src/main/java/project/wallet/WalletRedisKeys.java | 8
src/main/java/project/blockchain/internal/RechargeBlockchainServiceImpl.java | 224 ++++--------
src/main/java/project/wallet/internal/WalletGatherServiceImpl.java | 308 ++++++++++++++++++
src/main/java/project/web/admin/AdminWithdrawController.java | 17
src/main/java/project/web/api/WalletGatherController.java | 78 ++++
src/main/java/project/wallet/WalletGather.java | 92 +++++
src/main/java/project/withdraw/AdminWithdrawService.java | 3
pom.xml | 3
src/main/java/project/withdraw/internal/AdminWithdrawServiceImpl.java | 84 +---
src/main/resources/config/db.properties | 4
src/main/resources/config/redis.properties | 4
src/main/resources/spring/applicationContext-recharge_blockchain_admin.xml | 5
src/main/java/project/withdraw/internal/WithdrawServiceImpl.java | 73 ++-
src/main/java/project/web/api/WithdrawController.java | 19 +
src/main/java/project/withdraw/WithdrawService.java | 4
src/main/java/project/wallet/WalletGatherService.java | 21 +
17 files changed, 738 insertions(+), 227 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8d3b206..9f0fe23 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
- <version>9.0.70</version>
+ <version>8.5.100</version>
<scope>provided</scope>
</dependency>
@@ -280,6 +280,7 @@
</dependency>
</dependencies>
+
<build>
<finalName>dapp</finalName>
<plugins>
diff --git a/src/main/java/project/Constants.java b/src/main/java/project/Constants.java
index 8bcdbf1..5633a15 100644
--- a/src/main/java/project/Constants.java
+++ b/src/main/java/project/Constants.java
@@ -57,6 +57,24 @@
*/
/**
+ * 资金账户(USDT)
+ */
+ public static final String WALLET_GATHER_USDT = "GATHERUSDT";
+ /**
+ * 资金账户(BTC)
+ */
+ public static final String WALLET_GATHER_BTC = "GATHERBTC";
+ /**
+ * 资金账户(ETH)
+ */
+ public static final String WALLET_GATHER_ETH = "GATHERETH";
+ /**
+ * 资金账户(USDC)
+ */
+ public static final String WALLET_GATHER_USDC = "GATHERUSDC";
+
+
+ /**
* 交易账户(USDT)
*/
public static final String WALLET = "USDT";
diff --git a/src/main/java/project/blockchain/internal/RechargeBlockchainServiceImpl.java b/src/main/java/project/blockchain/internal/RechargeBlockchainServiceImpl.java
index d74ff1c..dc9aa1b 100644
--- a/src/main/java/project/blockchain/internal/RechargeBlockchainServiceImpl.java
+++ b/src/main/java/project/blockchain/internal/RechargeBlockchainServiceImpl.java
@@ -27,16 +27,14 @@
import project.log.MoneyLogService;
import project.party.PartyService;
import project.party.model.Party;
+import project.redis.RedisHandler;
import project.syspara.Syspara;
import project.syspara.SysparaService;
import project.tip.TipConstants;
import project.tip.TipService;
import project.user.UserDataService;
-import project.wallet.Wallet;
-import project.wallet.WalletExtend;
-import project.wallet.WalletLog;
-import project.wallet.WalletLogService;
-import project.wallet.WalletService;
+import project.wallet.*;
+import project.wallet.internal.WalletGatherServiceImpl;
import project.wallet.rate.ExchangeRateService;
import security.SecUser;
import security.internal.SecUserService;
@@ -59,6 +57,7 @@
protected SysparaService sysparaService;
protected ChannelBlockchainService channelBlockchainService;
protected TipService tipService;
+ protected RedisHandler redisHandler;
@Override
public void save(RechargeBlockchain recharge) {
@@ -441,6 +440,7 @@
@Override
public boolean saveSucceeded(String id, String operator, double success_amount) {
+ System.out.println("进入saveSucceeded方法,参数operator="+operator+",success_amount="+success_amount);
// RechargeBlockchain recharge = this.findByOrderNo(order_no);
RechargeBlockchain recharge = this.get(id);
String order_no = recharge.getOrder_no();
@@ -476,72 +476,61 @@
Party party = this.partyService.cachePartyBy(recharge.getPartyId(), false);
Syspara user_recom_bonus_open = sysparaService.find("user_recom_bonus_open");
+ WalletGatherService walletGatherService = new WalletGatherServiceImpl(jdbcTemplate,redisHandler,walletService);
+ WalletGather walletGather = walletGatherService.getWalletGatherByPartyId(recharge.getPartyId(),null);
- if ("usdt".equals(recharge.getSymbol())) {
- double amount = recharge.getVolume();
+ double amount = recharge.getVolume();
+ // 保存资金日志
+ MoneyLog moneyLog = new MoneyLog();
+ moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
+ System.out.println("recharge.getSymbol()===="+recharge.getSymbol());
+ if("usdt".equals(recharge.getSymbol())){
+ moneyLog.setAmount_before(walletGather.getUsdtMoney());
+ moneyLog.setAmount_after(Arith.add(walletGather.getUsdtMoney(), amount));
+ moneyLog.setWallettype(Constants.WALLET_GATHER_USDT);
+ }else if("btc".equals(recharge.getSymbol())){
+ moneyLog.setAmount_before(walletGather.getBtcMoney());
+ moneyLog.setAmount_after(Arith.add(walletGather.getBtcMoney(), amount));
+ moneyLog.setWallettype(Constants.WALLET_GATHER_BTC);
+ }else if("eth".equals(recharge.getSymbol())){
+ moneyLog.setAmount_before(walletGather.getEthMoney());
+ moneyLog.setAmount_after(Arith.add(walletGather.getEthMoney(), amount));
+ moneyLog.setWallettype(Constants.WALLET_GATHER_ETH);
+ }else if("usdc".equals(recharge.getSymbol())){
+ moneyLog.setAmount_before(walletGather.getUsdcMoney());
+ moneyLog.setAmount_after(Arith.add(walletGather.getUsdcMoney(), amount));
+ moneyLog.setWallettype(Constants.WALLET_GATHER_USDC);
+ }
- Wallet wallet = new Wallet();
- wallet = walletService.saveWalletByPartyId(recharge.getPartyId());
-
- double amount_before = wallet.getMoney();
-
- walletService.update(wallet.getPartyId().toString(), amount);
+ moneyLog.setAmount(recharge.getVolume());
+ moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]");
+ moneyLog.setPartyId(recharge.getPartyId());
- // 保存资金日志
- MoneyLog moneyLog = new MoneyLog();
- moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
- moneyLog.setAmount_before(amount_before);
- moneyLog.setAmount(amount);
- moneyLog.setAmount_after(Arith.add(wallet.getMoney(), amount));
- moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]");
- moneyLog.setPartyId(recharge.getPartyId());
- moneyLog.setWallettype(Constants.WALLET);
- moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
- moneyLog.setCreateTime(new Date());
- moneyLogService.save(moneyLog);
+ moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
+ moneyLog.setCreateTime(new Date());
+ moneyLogService.save(moneyLog);
- walletLog.setStatus(recharge.getSucceeded());
- walletLogService.update(walletLog);
+ //修改资金账户
+ walletGatherService.update(walletGather.getPartyId().toString(),recharge.getSymbol(),recharge.getVolume(),"add");
- this.updateRechargeBlockchain(recharge);
- /**
- * 给他的代理添加充值记录
- */
- userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
-
- /**
- * 若已开启充值奖励 ,则充值到账后给他的代理用户添加奖金
- */
- if ("true".equals(user_recom_bonus_open.getValue())) {
- rechargeBonusService.saveBounsHandle(recharge, 1);
- }
-
- // 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,
- // 1不重置,2重置
- String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw").getValue();
- if ("1".equals(recharge_sucess_reset_withdraw)) {
- party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), amount));
- if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
- party.setWithdraw_limit_now_amount(0);
- }
- }
- if ("2".equals(recharge_sucess_reset_withdraw)) {
- double withdraw_limit_turnover_percent = Double
- .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
- double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
-
- if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
- party.setWithdraw_limit_amount(amount);
- party.setWithdraw_limit_now_amount(0);
- } else {
- party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), amount));
- }
- }
-
- partyService.update(party);
-
- } else {
-
+ this.updateRechargeBlockchain(recharge);
+ /**
+ * 给他的代理添加充值记录
+ */
+ userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
+ /**
+ * 若已开启充值奖励 ,则充值到账后给他的代理用户添加奖金
+ */
+ if ("true".equals(user_recom_bonus_open.getValue())) {
+ rechargeBonusService.saveBounsHandle(recharge, 1);
+ }
+ /**
+ * 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,1不重置,2重置
+ */
+ double usdt_amount = 0;
+ if("usdt".equals(recharge.getSymbol())){
+ usdt_amount = amount;
+ }else {
List<Realtime> realtime_list = this.dataService.realtime(recharge.getSymbol());
Realtime realtime = null;
if (realtime_list.size() > 0) {
@@ -551,84 +540,31 @@
}
// 对应usdt价格
double transfer_usdt = realtime.getClose();
-
- WalletExtend walletExtend = new WalletExtend();
- walletExtend = walletService.saveExtendByPara(recharge.getPartyId(), recharge.getSymbol());
-
- double volume = recharge.getVolume();
-
- double amount_before = walletExtend.getAmount();
-
- // walletExtend = walletService.saveWalletExtendByParaAndUpdate(String.valueOf(recharge.getPartyId()), recharge.getSymbol(), volume);
- walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), volume);
- this.updateRechargeBlockchain(recharge);
-
// 币种usdt价格= 币种价格×充值数量
- double usdt_amount = Arith.mul(volume, transfer_usdt);
-
- // 保存资金日志
- MoneyLog moneyLog = new MoneyLog();
- moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
- moneyLog.setAmount_before(amount_before);
- moneyLog.setAmount(volume);
- moneyLog.setAmount_after(Arith.add(walletExtend.getAmount(), volume));
-
- moneyLog.setLog("充值订单[" + recharge.getOrder_no() + "]");
- moneyLog.setPartyId(recharge.getPartyId());
- moneyLog.setWallettype(recharge.getSymbol());
- moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_RECHARGE);
- moneyLog.setCreateTime(new Date());
- moneyLogService.save(moneyLog);
-
- walletLog.setStatus(recharge.getSucceeded());
- walletLogService.update(walletLog);
- /**
- * 给他的代理添加充值记录
- */
- userDataService.saveRechargeHandle(recharge.getPartyId(), recharge.getVolume(), recharge.getSymbol());
- /**
- * 买币-币冲充值其他非usdt币时使用
- */
-// userDataService.saveBuy(recharge.getPartyId(), recharge.getSymbol(), recharge.getVolume());
-
- /**
- * 充值到账后给他的代理用户添加奖金
- */
- if ("true".equals(user_recom_bonus_open.getValue())) {
- rechargeBonusService.saveBounsHandle(recharge, transfer_usdt);
- }
-
- /**
- * 充值到账后给他增加提现流水限制金额
- */
-
- /**
- * 充值到账后给他增加提现流水限制金额 充值到账后,当前流水大于提现限制流水时是否重置提现限制流水并将Party表里的当前流水设置清零,1不重置,2重置
- */
- String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw")
- .getValue();
- if ("1".equals(recharge_sucess_reset_withdraw)) {
- party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
- if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
- party.setWithdraw_limit_now_amount(0);
- }
- }
- if ("2".equals(recharge_sucess_reset_withdraw)) {
- double withdraw_limit_turnover_percent = Double
- .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
- double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
-
- if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
- party.setWithdraw_limit_amount(usdt_amount);
- party.setWithdraw_limit_now_amount(0);
- } else {
- party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
- }
- }
-
- partyService.update(party);
-
+ usdt_amount = Arith.mul(recharge.getVolume(), transfer_usdt);
}
+ String recharge_sucess_reset_withdraw = this.sysparaService.find("recharge_sucess_reset_withdraw")
+ .getValue();
+ if ("1".equals(recharge_sucess_reset_withdraw)) {
+ party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
+ if (party.getWithdraw_limit_now_amount() > party.getWithdraw_limit_amount()) {
+ party.setWithdraw_limit_now_amount(0);
+ }
+ }
+ if ("2".equals(recharge_sucess_reset_withdraw)) {
+ double withdraw_limit_turnover_percent = Double
+ .valueOf(sysparaService.find("withdraw_limit_turnover_percent").getValue());
+ double party_withdraw = Arith.mul(party.getWithdraw_limit_amount(), withdraw_limit_turnover_percent);
+
+ if (party.getWithdraw_limit_now_amount() >= party_withdraw) {
+ party.setWithdraw_limit_amount(usdt_amount);
+ party.setWithdraw_limit_now_amount(0);
+ } else {
+ party.setWithdraw_limit_amount(Arith.add(party.getWithdraw_limit_amount(), usdt_amount));
+ }
+ }
+
+ partyService.update(party);
Log log = new Log();
log.setCategory(Constants.LOG_CATEGORY_OPERATION);
@@ -734,4 +670,8 @@
this.tipService = tipService;
}
+ public void setRedisHandler(RedisHandler redisHandler) {
+ this.redisHandler = redisHandler;
+ }
+
}
diff --git a/src/main/java/project/wallet/WalletGather.java b/src/main/java/project/wallet/WalletGather.java
new file mode 100644
index 0000000..ba290ae
--- /dev/null
+++ b/src/main/java/project/wallet/WalletGather.java
@@ -0,0 +1,92 @@
+package project.wallet;
+
+import kernel.bo.EntityObject;
+
+import javax.persistence.Column;
+import javax.persistence.Table;
+import java.io.Serializable;
+
+
+@Table(name="T_WALLET_GATHER")
+public class WalletGather extends EntityObject {
+ private static final long serialVersionUID = 7522745589282180829L;
+
+ @Column(name="PARTY_ID")
+ private Serializable partyId;
+
+ /**
+ * USDT
+ */
+ @Column(name="USDT_MONEY")
+ private double usdtMoney = 0.0D;
+
+ /**
+ * BTC
+ */
+ @Column(name="BTC_MONEY")
+ private double btcMoney = 0.0D;
+
+ /**
+ * ETH
+ */
+ @Column(name="ETH_MONEY")
+ private double ethMoney = 0.0D;
+
+ /**
+ * USDC
+ */
+ @Column(name="USDC_MONEY")
+ private double usdcMoney = 0.0D;
+
+
+ private double totalMoney = 0.0D;
+
+
+ public Serializable getPartyId() {
+ return partyId;
+ }
+
+ public void setPartyId(Serializable partyId) {
+ this.partyId = partyId;
+ }
+
+ public double getUsdtMoney() {
+ return usdtMoney;
+ }
+
+ public void setUsdtMoney(double usdtMoney) {
+ this.usdtMoney = usdtMoney;
+ }
+
+ public double getBtcMoney() {
+ return btcMoney;
+ }
+
+ public void setBtcMoney(double btcMoney) {
+ this.btcMoney = btcMoney;
+ }
+
+ public double getEthMoney() {
+ return ethMoney;
+ }
+
+ public void setEthMoney(double ethMoney) {
+ this.ethMoney = ethMoney;
+ }
+
+ public double getUsdcMoney() {
+ return usdcMoney;
+ }
+
+ public void setUsdcMoney(double usdcMoney) {
+ this.usdcMoney = usdcMoney;
+ }
+
+ public double getTotalMoney() {
+ return totalMoney;
+ }
+
+ public void setTotalMoney(double totalMoney) {
+ this.totalMoney = totalMoney;
+ }
+}
diff --git a/src/main/java/project/wallet/WalletGatherService.java b/src/main/java/project/wallet/WalletGatherService.java
new file mode 100644
index 0000000..dceb8a4
--- /dev/null
+++ b/src/main/java/project/wallet/WalletGatherService.java
@@ -0,0 +1,21 @@
+package project.wallet;
+
+import kernel.web.ResultObject;
+import project.data.DataService;
+import project.party.PartyService;
+import project.syspara.SysparaService;
+
+import java.io.Serializable;
+
+public interface WalletGatherService {
+
+ public WalletGather getWalletGatherByPartyId(Serializable partyId, DataService dataService);
+
+ public WalletGather save(String partyId);
+
+ public void update(String partyId, String currency,double amount,String mark);
+
+ public ResultObject transfer(String partyId, String currency, String fromTo, String amount, String safeword, PartyService partyService, SysparaService sysparaService);
+
+ public ResultObject getParameter(String partyId, String currency, String fromTo);
+}
diff --git a/src/main/java/project/wallet/WalletRedisKeys.java b/src/main/java/project/wallet/WalletRedisKeys.java
index 071a262..1f3c5ab 100644
--- a/src/main/java/project/wallet/WalletRedisKeys.java
+++ b/src/main/java/project/wallet/WalletRedisKeys.java
@@ -13,4 +13,12 @@
* wallet_extend update队列
*/
public final static String WALLET_EXTEND_QUEUE_UPDATE = "WALLET_EXTEND_QUEUE_UPDATE_";
+
+
+
+ public final static String WALLET_GATHER_PARTY_ID = "WALLET_GATHER_PARTY_ID_";
+ /**
+ * wallet_gather update队列
+ */
+ public final static String WALLET_GATHER_UPDATE = "WALLET_GATHER_UPDATE_";
}
diff --git a/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java b/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java
new file mode 100644
index 0000000..6ed7d3f
--- /dev/null
+++ b/src/main/java/project/wallet/internal/WalletGatherServiceImpl.java
@@ -0,0 +1,308 @@
+package project.wallet.internal;
+
+import kernel.exception.BusinessException;
+import kernel.util.Arith;
+import kernel.util.StringUtils;
+import kernel.util.UUIDGenerator;
+import kernel.web.ApplicationUtil;
+import kernel.web.ResultObject;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import project.data.DataService;
+import project.data.model.Realtime;
+import project.party.PartyService;
+import project.redis.RedisHandler;
+import project.syspara.SysparaService;
+import project.wallet.*;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+public class WalletGatherServiceImpl implements WalletGatherService {
+
+ private JdbcTemplate jdbcTemplate;
+ private RedisHandler redisHandler;
+ private WalletService walletService;
+
+ // 构造函数,传入 DataSource 初始化 jdbcTemplate
+ public WalletGatherServiceImpl(JdbcTemplate jdbcTemplate,RedisHandler redisHandler,WalletService walletService) {
+ this.jdbcTemplate = jdbcTemplate;
+ this.redisHandler = redisHandler;
+ this.walletService = walletService;
+ }
+
+
+ @Override
+ public WalletGather getWalletGatherByPartyId(Serializable partyId, DataService dataService) {
+ //先从redis中获取
+// WalletGather walletGather = (WalletGather)redisHandler.get(WalletRedisKeys.WALLET_GATHER_PARTY_ID + partyId.toString());
+ WalletGather walletGather = null;
+ if(null == walletGather){
+ List<WalletGather> walletGathers = jdbcTemplate.query(
+ "SELECT UUID id, PARTY_ID partyId, USDT_MONEY usdtMoney, BTC_MONEY btcMoney, ETH_MONEY ethMoney, USDC_MONEY usdcMoney FROM T_WALLET_GATHER WHERE PARTY_ID=?",
+ new Object[]{partyId},
+ BeanPropertyRowMapper.newInstance(WalletGather.class)
+ );
+ // 处理查询结果,可以检查列表是否为空
+ if (!walletGathers.isEmpty()) {
+ walletGather = walletGathers.get(0);
+ }
+ }
+ if(null == walletGather){
+ walletGather = save(partyId.toString());
+ }
+ System.out.println("判断dataService是否为空"+dataService);
+ if(null != dataService){
+ //查总数
+ List<String> symbols = new ArrayList<>();
+ if(walletGather.getBtcMoney() > 0){
+ symbols.add("btc");
+ }
+ if(walletGather.getEthMoney() > 0){
+ symbols.add("eth");
+ }
+ if(walletGather.getUsdcMoney() > 0){
+ symbols.add("usdc");
+ }
+ System.out.println("组装symbols"+symbols);
+ System.out.println("组装symbols"+symbols.size());
+ String data_symbol = "";
+ double money_coin = 0;
+ if(symbols.size() > 0){
+ for (int i = 0; i < symbols.size(); i++) {
+ if (i != 0) {
+ data_symbol = data_symbol + "," + symbols.get(i);
+ } else {
+ data_symbol = symbols.get(i);
+ }
+ }
+ System.out.println("组装data_symbol"+data_symbol);
+ List<Realtime> realtime_all = dataService.realtime(data_symbol);
+ System.out.println("查询realtime_all"+realtime_all);
+ if (realtime_all.size() <= 0) {
+ throw new BusinessException("系统错误,请稍后重试");
+ }
+ Realtime realtime = null;
+ for (int i = 0; i < symbols.size(); i++) {
+ for (Realtime real : realtime_all) {
+ realtime = null;
+ if (real.getSymbol().equals(symbols.get(i).toLowerCase())) {
+ realtime = real;
+ }
+ if (realtime != null) {
+ if("btc".equals(symbols.get(i))){
+ money_coin = Arith.add(money_coin, Arith.mul(realtime.getClose(), walletGather.getBtcMoney()));
+ }else if("eth".equals(symbols.get(i))){
+ money_coin = Arith.add(money_coin, Arith.mul(realtime.getClose(), walletGather.getEthMoney()));
+ }else if("usdc".equals(symbols.get(i))){
+ money_coin = Arith.add(money_coin, Arith.mul(realtime.getClose(), walletGather.getUsdcMoney()));
+ }
+ }
+ }
+ }
+ }else {
+ money_coin = walletGather.getUsdtMoney();
+ }
+ walletGather.setTotalMoney(money_coin);
+ }
+ return walletGather;
+ }
+
+ @Override
+ public WalletGather save(String partyId) {
+ WalletGather walletGather = new WalletGather();
+ walletGather.setId(UUIDGenerator.getUUID());
+ walletGather.setPartyId(partyId);
+ ApplicationUtil.executeInsert(walletGather);
+ redisHandler.setAsyn(WalletRedisKeys.WALLET_GATHER_PARTY_ID + walletGather.getPartyId().toString(),walletGather);
+ return walletGather;
+ }
+
+ @Override
+ public void update(String partyId, String currency, double amount,String mark) {
+ System.out.println("update 方法:参数partyId="+partyId+",参数currency="+currency+",参数amount="+amount+",参数mark="+mark);
+ WalletGather walletGather = getWalletGatherByPartyId(partyId,null);
+ if("usdt".equals(currency)){
+ if("add".equals(mark)){
+ walletGather.setUsdtMoney(Arith.add(walletGather.getUsdtMoney(), amount));
+ }else {
+ walletGather.setUsdtMoney(Arith.sub(walletGather.getUsdtMoney(), amount));
+ }
+ }else if("btc".equals(currency)){
+ if("add".equals(mark)){
+ walletGather.setBtcMoney(Arith.add(walletGather.getBtcMoney(), amount));
+ }else {
+ walletGather.setBtcMoney(Arith.sub(walletGather.getBtcMoney(), amount));
+ }
+ }else if("eth".equals(currency)){
+ if("add".equals(mark)){
+ walletGather.setEthMoney(Arith.add(walletGather.getEthMoney(), amount));
+ }else {
+ walletGather.setEthMoney(Arith.sub(walletGather.getEthMoney(), amount));
+ }
+ }else if("usdc".equals(currency)){
+ if("add".equals(mark)){
+ walletGather.setUsdcMoney(Arith.add(walletGather.getUsdcMoney(), amount));
+ }else {
+ walletGather.setUsdcMoney(Arith.sub(walletGather.getUsdcMoney(), amount));
+ }
+ }
+ ApplicationUtil.executeUpdate(walletGather);
+ redisHandler.setAsyn(WalletRedisKeys.WALLET_GATHER_PARTY_ID + walletGather.getPartyId().toString(),walletGather);
+ }
+
+ @Override
+ public ResultObject transfer(String partyId,String currency, String fromTo, String amount,String safeword,PartyService partyService,SysparaService sysparaService) {
+ // 交易所提现是否需要资金密码
+ String exchange_withdraw_need_safeword = sysparaService.find("exchange_withdraw_need_safeword").getValue();
+ if(StringUtils.isEmptyString(exchange_withdraw_need_safeword)) {
+ throw new BusinessException("系统参数错误");
+ }
+
+ if ("true".equals(exchange_withdraw_need_safeword)) {
+ if (StringUtils.isEmptyString(safeword)) {
+ ResultObject resultObject = new ResultObject();
+ resultObject.setCode("1");
+ resultObject.setMsg("资金密码不能为空");
+ return resultObject;
+ }
+
+ if (safeword.length() < 6 || safeword.length() > 12) {
+ ResultObject resultObject = new ResultObject();
+ resultObject.setCode("1");
+ resultObject.setMsg("资金密码必须6-12位");
+ return resultObject;
+ }
+
+ if (!partyService.checkSafeword(safeword, partyId)) {
+ ResultObject resultObject = new ResultObject();
+ resultObject.setCode("1");
+ resultObject.setMsg("资金密码错误");
+ return resultObject;
+ }
+ }
+
+ WalletGather walletGather = getWalletGatherByPartyId(partyId,null);
+ List<WalletGather> walletGathers = jdbcTemplate.query(
+ "SELECT UUID id, PARTY_ID partyId, USDT_MONEY usdtMoney, BTC_MONEY btcMoney, ETH_MONEY ethMoney, USDC_MONEY usdcMoney FROM T_WALLET_GATHER WHERE PARTY_ID=?",
+ new Object[]{partyId},
+ BeanPropertyRowMapper.newInstance(WalletGather.class)
+ );
+ // 处理查询结果,可以检查列表是否为空
+ if (!walletGathers.isEmpty()) {
+ walletGather = walletGathers.get(0);
+ }
+ WalletExtend walletExtend = walletService.saveExtendByPara(partyId, currency);
+ double volume = Double.parseDouble(amount);
+ if("1".equals(fromTo)){
+ //资金账号=>交易账户
+ System.out.println("资金账号=>交易账户");
+ return this.transferGathertoExtend(walletGather,walletExtend,currency,volume);
+ }else {
+ //交易账户=>资金账户
+ System.out.println("交易账户=>资金账户");
+ return this.transferExtendtoGather(walletGather,walletExtend,currency,volume);
+ }
+ }
+
+ @Override
+ public ResultObject getParameter(String partyId, String currency, String fromTo) {
+ ResultObject resultObject = new ResultObject();
+ if(org.apache.commons.lang3.StringUtils.isBlank(partyId) || org.apache.commons.lang3.StringUtils.isBlank(currency) || org.apache.commons.lang3.StringUtils.isBlank(fromTo)){
+ resultObject.setCode("1");
+ resultObject.setCode("参数错误");
+ return resultObject;
+ }
+ resultObject.setCode("0");
+ resultObject.setCode("操作成功");
+ if("1".equals(fromTo)){
+ WalletGather walletGather = this.getWalletGatherByPartyId(partyId,null);
+ if("usdt".equals(currency)){
+ resultObject.setData(walletGather.getUsdtMoney());
+ }else if("btc".equals(currency)){
+ resultObject.setData(walletGather.getBtcMoney());
+ }else if("eth".equals(currency)){
+ resultObject.setData(walletGather.getEthMoney());
+ }else if("usdc".equals(currency)){
+ resultObject.setData(walletGather.getUsdcMoney());
+ }
+ return resultObject;
+ }else {
+ //交易账户=>资金账户
+ WalletExtend walletExtend = walletService.saveExtendByPara(partyId, currency);
+ resultObject.setData(walletExtend.getAmount());
+ return resultObject;
+ }
+ }
+
+ 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));
+ }
+ }else {
+ resultObject.setCode("1");
+ resultObject.setMsg("划转资金不足");
+ return resultObject;
+ }
+
+ ApplicationUtil.executeUpdate(walletGather);
+ redisHandler.setAsyn(WalletRedisKeys.WALLET_GATHER_PARTY_ID + walletGather.getPartyId().toString(),walletGather);
+ walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), -amount);
+ resultObject.setMsg("划转成功");
+ return resultObject;
+ }
+
+ public ResultObject transferGathertoExtend(WalletGather walletGather,WalletExtend walletExtend,String currency,double amount){
+ ResultObject resultObject = new ResultObject();
+ resultObject.setCode("0");
+ if("usdt".equals(currency)){
+ if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+ walletGather.setUsdtMoney(Arith.sub(walletGather.getUsdtMoney(), amount));
+ }else {
+ resultObject.setCode("1");
+ resultObject.setMsg("划转资金不足");
+ return resultObject;
+ }
+ }else if("btc".equals(currency)){
+ if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+ walletGather.setBtcMoney(Arith.sub(walletGather.getBtcMoney(), amount));
+ }else {
+ resultObject.setCode("1");
+ resultObject.setMsg("划转资金不足");
+ return resultObject;
+ }
+ }else if("eth".equals(currency)){
+ if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+ walletGather.setEthMoney(Arith.sub(walletGather.getEthMoney(), amount));
+ }else {
+ resultObject.setCode("1");
+ resultObject.setMsg("划转资金不足");
+ return resultObject;
+ }
+ }else if("usdc".equals(currency)){
+ if(new BigDecimal(walletGather.getUsdtMoney()).compareTo(new BigDecimal(amount)) >= 0){
+ walletGather.setUsdcMoney(Arith.sub(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);
+ walletService.updateExtend(walletExtend.getPartyId().toString(), walletExtend.getWallettype(), amount);
+ resultObject.setMsg("划转成功");
+ return resultObject;
+ }
+}
diff --git a/src/main/java/project/web/admin/AdminWithdrawController.java b/src/main/java/project/web/admin/AdminWithdrawController.java
index f334a35..2ff1f1e 100644
--- a/src/main/java/project/web/admin/AdminWithdrawController.java
+++ b/src/main/java/project/web/admin/AdminWithdrawController.java
@@ -10,6 +10,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@@ -20,6 +21,10 @@
import kernel.web.Page;
import kernel.web.PageActionSupport;
import project.Constants;
+import project.redis.RedisHandler;
+import project.wallet.WalletGatherService;
+import project.wallet.WalletService;
+import project.wallet.internal.WalletGatherServiceImpl;
import project.withdraw.AdminWithdrawService;
import util.LockFilter;
@@ -31,6 +36,15 @@
@Resource
private AdminWithdrawService adminWithdrawService;
+ @Autowired
+ private RedisHandler redisHandler;
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ @Autowired
+ private WalletService walletService;
+
private static final String action = "normal/adminWithdrawAction!";
@@ -215,7 +229,8 @@
lock = true;
// 统一处理失败接口
- this.adminWithdrawService.saveReject(id, failure_msg, this.getUsername_login(), this.getLoginPartyId());
+ WalletGatherService walletGatherService = new WalletGatherServiceImpl(jdbcTemplate,redisHandler,walletService);
+ this.adminWithdrawService.saveReject(id, failure_msg, this.getUsername_login(), this.getLoginPartyId(),walletGatherService);
ThreadUtils.sleep(300);
} catch (BusinessException e) {
modelAndView.addObject("error", e.getMessage());
diff --git a/src/main/java/project/web/api/WalletGatherController.java b/src/main/java/project/web/api/WalletGatherController.java
new file mode 100644
index 0000000..9c09d4e
--- /dev/null
+++ b/src/main/java/project/web/api/WalletGatherController.java
@@ -0,0 +1,78 @@
+package project.web.api;
+
+import kernel.web.BaseAction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.web.bind.annotation.*;
+import project.data.DataService;
+import project.party.PartyService;
+import project.redis.RedisHandler;
+import project.syspara.SysparaService;
+import project.wallet.WalletGatherService;
+import project.wallet.WalletService;
+import project.wallet.internal.WalletGatherServiceImpl;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+/**
+ * 资金钱包
+ */
+@RestController
+@CrossOrigin
+public class WalletGatherController extends BaseAction {
+ private Logger logger = LoggerFactory.getLogger(WalletGatherController.class);
+// @Autowired
+// protected WalletGatherService walletGatherService;
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+ @Autowired
+ private RedisHandler redisHandler;
+ @Autowired
+ private WalletService walletService;
+ @Autowired
+ private PartyService partyService;
+ @Autowired
+ private SysparaService sysparaService;
+ @Autowired
+ private DataService dataService;
+
+
+ private final String action = "/api/walletGrther!";
+
+ /**
+ * 获取登录用户的资金账号
+ * @param request
+ * @return
+ */
+ @GetMapping(action + "get.action")
+ public Object get(HttpServletRequest request) throws IOException {
+ String partyId = this.getLoginPartyId();
+ WalletGatherService walletGatherService = new WalletGatherServiceImpl(jdbcTemplate,redisHandler,walletService);
+ return walletGatherService.getWalletGatherByPartyId(partyId,dataService);
+ }
+
+ @PostMapping(action + "transfer.action")
+ public Object transfer(HttpServletRequest request) throws IOException {
+ String partyId = this.getLoginPartyId();
+ String currency = request.getParameter("currency");
+ String fromTo = request.getParameter("fromTo");
+ String amount = request.getParameter("amount");
+ String safeword = request.getParameter("safeword");
+ WalletGatherService walletGatherService = new WalletGatherServiceImpl(jdbcTemplate,redisHandler,walletService);
+ return walletGatherService.transfer(partyId,currency,fromTo,amount,safeword,partyService,sysparaService);
+ }
+
+ @GetMapping(action + "getParameter.action")
+ public Object getParameter(HttpServletRequest request) throws IOException {
+ String partyId = this.getLoginPartyId();
+ String currency = request.getParameter("currency");
+ String fromTo = request.getParameter("fromTo");
+ WalletGatherService walletGatherService = new WalletGatherServiceImpl(jdbcTemplate,redisHandler,walletService);
+ return walletGatherService.getParameter(partyId,currency,fromTo);
+ }
+
+
+}
diff --git a/src/main/java/project/web/api/WithdrawController.java b/src/main/java/project/web/api/WithdrawController.java
index b15e7fe..fc6e02c 100644
--- a/src/main/java/project/web/api/WithdrawController.java
+++ b/src/main/java/project/web/api/WithdrawController.java
@@ -11,6 +11,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -24,12 +25,17 @@
import kernel.web.BaseAction;
import kernel.web.ResultObject;
import project.Constants;
+import project.data.DataService;
import project.log.Log;
import project.log.LogService;
import project.party.PartyService;
import project.party.model.Party;
+import project.redis.RedisHandler;
import project.syspara.SysparaService;
+import project.wallet.WalletGatherService;
import project.wallet.WalletLogService;
+import project.wallet.WalletService;
+import project.wallet.internal.WalletGatherServiceImpl;
import project.withdraw.Withdraw;
import project.withdraw.WithdrawService;
import util.LockFilter;
@@ -55,6 +61,16 @@
@Autowired
private LogService logService;
+
+ @Autowired
+ private RedisHandler redisHandler;
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ @Autowired
+ private WalletService walletService;
+
private final String action = "/api/withdraw!";
@@ -169,7 +185,8 @@
withdraw.setDeviceIp(this.getIp());
// 保存
- this.withdrawService.saveApply(withdraw, channel, null, googleCode);
+ WalletGatherService walletGatherService = new WalletGatherServiceImpl(jdbcTemplate,redisHandler,walletService);
+ this.withdrawService.saveApply(withdraw, channel, null, googleCode,walletGatherService);
Log log = new Log();
Party party = this.partyService.cachePartyBy(partyId, false);
diff --git a/src/main/java/project/withdraw/AdminWithdrawService.java b/src/main/java/project/withdraw/AdminWithdrawService.java
index c218138..fc72916 100644
--- a/src/main/java/project/withdraw/AdminWithdrawService.java
+++ b/src/main/java/project/withdraw/AdminWithdrawService.java
@@ -3,6 +3,7 @@
import java.util.Date;
import kernel.web.Page;
+import project.wallet.WalletGatherService;
public interface AdminWithdrawService {
/**
@@ -11,7 +12,7 @@
* @param id
* @param failure_msg 驳回原因
*/
- public void saveReject(String id, String failure_msg,String userName,String partyId);
+ public void saveReject(String id, String failure_msg, String userName, String partyId, WalletGatherService walletGatherService);
/**
* 通过
diff --git a/src/main/java/project/withdraw/WithdrawService.java b/src/main/java/project/withdraw/WithdrawService.java
index ac821c5..973e597 100644
--- a/src/main/java/project/withdraw/WithdrawService.java
+++ b/src/main/java/project/withdraw/WithdrawService.java
@@ -1,5 +1,7 @@
package project.withdraw;
+import project.wallet.WalletGatherService;
+
import java.util.List;
public interface WithdrawService {
@@ -7,7 +9,7 @@
/**
* 代付,通过web申请一个代付订单
*/
- public void saveApply(Withdraw entity, String channel, String method_id, String googleCode);
+ public void saveApply(Withdraw entity, String channel, String method_id, String googleCode, WalletGatherService walletGatherService);
/**
* 查找订单 order_no 订单号
diff --git a/src/main/java/project/withdraw/internal/AdminWithdrawServiceImpl.java b/src/main/java/project/withdraw/internal/AdminWithdrawServiceImpl.java
index 269b993..6d31355 100644
--- a/src/main/java/project/withdraw/internal/AdminWithdrawServiceImpl.java
+++ b/src/main/java/project/withdraw/internal/AdminWithdrawServiceImpl.java
@@ -24,10 +24,7 @@
import project.party.recom.UserRecomService;
import project.tip.TipService;
import project.user.UserDataService;
-import project.wallet.Wallet;
-import project.wallet.WalletExtend;
-import project.wallet.WalletLogService;
-import project.wallet.WalletService;
+import project.wallet.*;
import project.withdraw.AdminWithdrawService;
import project.withdraw.Withdraw;
import security.SecUser;
@@ -51,7 +48,7 @@
private TipService tipService;
@Override
- public void saveReject(String id, String failure_msg, String userName, String partyId) {
+ public void saveReject(String id, String failure_msg, String userName, String partyId, WalletGatherService walletGatherService) {
Withdraw withdraw = this.get(id);
if (withdraw.getSucceeded() == 2 ) {// 通过后不可驳回
@@ -70,56 +67,41 @@
symbol = "btc";
} else if (withdraw.getMethod().indexOf("ETH") != -1) {
symbol = "eth";
+ } else if (withdraw.getMethod().indexOf("USDC") != -1) {
+ symbol = "eth";
} else {
symbol = "usdt";
}
- if ("usdt".equals(symbol)) {
- Wallet wallet = walletService.saveWalletByPartyId(withdraw.getPartyId());
-
- double amount_before = wallet.getMoney();
-
- walletService.update(wallet.getPartyId().toString(),
- Arith.add(withdraw.getAmount(), withdraw.getAmount_fee()));
-
- /*
- * 保存资金日志
- */
- MoneyLog moneyLog = new MoneyLog();
- moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
- moneyLog.setAmount_before(amount_before);
- moneyLog.setAmount(Arith.add(withdraw.getAmount(), withdraw.getAmount_fee()));
- moneyLog.setAmount_after(
- Arith.add(amount_before, Arith.add(withdraw.getAmount(), withdraw.getAmount_fee())));
-
- moneyLog.setLog("驳回提现[" + withdraw.getOrder_no() + "]");
- // moneyLog.setExtra(withdraw.getOrder_no());
- moneyLog.setPartyId(withdraw.getPartyId());
- moneyLog.setWallettype(Constants.WALLET);
- moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_WITHDRAW);
-
- moneyLogService.save(moneyLog);
- } else {
- WalletExtend walletExtend = walletService.saveExtendByPara(withdraw.getPartyId(), symbol);
- double amount_before = walletExtend.getAmount();
- walletService.updateExtend(withdraw.getPartyId().toString(), symbol, withdraw.getVolume());
-
- /*
- * 保存资金日志
- */
- MoneyLog moneyLog = new MoneyLog();
- moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
- moneyLog.setAmount_before(amount_before);
- moneyLog.setAmount(withdraw.getVolume());
- moneyLog.setAmount_after(Arith.add(amount_before, withdraw.getVolume()));
-
- moneyLog.setLog("驳回提现[" + withdraw.getOrder_no() + "]");
- // moneyLog.setExtra(withdraw.getOrder_no());
- moneyLog.setPartyId(withdraw.getPartyId());
- moneyLog.setWallettype(symbol.toUpperCase());
- moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_WITHDRAW);
-
- moneyLogService.save(moneyLog);
+ WalletGather walletGather = walletGatherService.getWalletGatherByPartyId(withdraw.getPartyId(),null);
+ double amount_before = 0;
+ if("usdt".equals(symbol)){
+ amount_before = walletGather.getUsdtMoney();
+ } else if ("btc".equals(symbol)) {
+ amount_before = walletGather.getBtcMoney();
+ } else if ("eth".equals(symbol)) {
+ amount_before = walletGather.getEthMoney();
+ } else if ("usdc".equals(symbol)) {
+ amount_before = walletGather.getUsdcMoney();
}
+ //修改资金账户
+ walletGatherService.update(walletGather.getPartyId().toString(),symbol,withdraw.getAmount(),"add");
+ /*
+ * 保存资金日志
+ */
+ MoneyLog moneyLog = new MoneyLog();
+ moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
+ moneyLog.setAmount_before(amount_before);
+ moneyLog.setAmount(Arith.add(withdraw.getAmount(), withdraw.getAmount_fee()));
+ moneyLog.setAmount_after(
+ Arith.add(amount_before, Arith.add(withdraw.getAmount(), withdraw.getAmount_fee())));
+
+ moneyLog.setLog("驳回提现[" + withdraw.getOrder_no() + "]");
+ // moneyLog.setExtra(withdraw.getOrder_no());
+ moneyLog.setPartyId(withdraw.getPartyId());
+ moneyLog.setWallettype(Constants.WALLET);
+ moneyLog.setContent_type(Constants.MONEYLOG_CONTENT_WITHDRAW);
+
+ moneyLogService.save(moneyLog);
this.walletLogService.updateStatus(withdraw.getOrder_no(), withdraw.getSucceeded());
SecUser SecUser = secUserService.findUserByPartyId(withdraw.getPartyId());
diff --git a/src/main/java/project/withdraw/internal/WithdrawServiceImpl.java b/src/main/java/project/withdraw/internal/WithdrawServiceImpl.java
index 3a92816..a8b133c 100644
--- a/src/main/java/project/withdraw/internal/WithdrawServiceImpl.java
+++ b/src/main/java/project/withdraw/internal/WithdrawServiceImpl.java
@@ -10,6 +10,7 @@
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -20,10 +21,13 @@
import kernel.util.StringUtils;
import kernel.web.ApplicationUtil;
import project.Constants;
+import project.data.DataService;
import project.log.MoneyLog;
import project.log.MoneyLogService;
import project.party.PartyService;
import project.party.model.Party;
+import project.redis.RedisHandler;
+import project.redis.interal.RedisHandlerImpl;
import project.syspara.Syspara;
import project.syspara.SysparaService;
import project.tip.TipConstants;
@@ -36,11 +40,8 @@
import project.user.kyc.KycHighLevel;
import project.user.kyc.KycHighLevelService;
import project.user.kyc.KycService;
-import project.wallet.Wallet;
-import project.wallet.WalletExtend;
-import project.wallet.WalletLog;
-import project.wallet.WalletLogService;
-import project.wallet.WalletService;
+import project.wallet.*;
+import project.wallet.internal.WalletGatherServiceImpl;
import project.wallet.rate.ExchangeRateService;
import project.withdraw.Withdraw;
import project.withdraw.WithdrawService;
@@ -66,7 +67,7 @@
protected TipService tipService;
@Override
- public void saveApply(Withdraw withdraw, String channel, String method_id, String googleCode) {
+ public void saveApply(Withdraw withdraw, String channel, String method_id, String googleCode,WalletGatherService walletGatherService) {
Party party = this.partyService.cachePartyBy(withdraw.getPartyId(), false);
if (Constants.SECURITY_ROLE_TEST.equals(party.getRolename())) {
throw new BusinessException(1, "无权限");
@@ -119,16 +120,16 @@
// +withdrawList.get(0).getDeviceIp()+"]不同, 请注意核对!!!");
// }
// }
-
+ System.out.println("打印信息");
withdraw.setMethod(channel);
if (channel.indexOf("BTC") != -1) {
- saveApplyOtherChannel(withdraw, "btc");
+ saveApplyOtherChannel(withdraw, "btc",walletGatherService);
return;
} else if (channel.indexOf("ETH") != -1) {
- saveApplyOtherChannel(withdraw, "eth");
+ saveApplyOtherChannel(withdraw, "eth",walletGatherService);
return;
}else if(channel.indexOf("USDC") !=-1){
- saveApplyOtherChannel(withdraw, "usdc");
+ saveApplyOtherChannel(withdraw, "usdc",walletGatherService);
return;
}
Kyc party_kyc = this.kycService.get(withdraw.getPartyId().toString());
@@ -153,8 +154,12 @@
throw new BusinessException(506, "Your account has been frozen");
}
- Wallet wallet = walletService.saveWalletByPartyId(withdraw.getPartyId());
- if (wallet.getMoney() < withdraw.getVolume()) {
+// Wallet wallet = walletService.saveWalletByPartyId(withdraw.getPartyId());
+ System.out.println("获取walletGather前");
+ WalletGather walletGather = walletGatherService.getWalletGatherByPartyId(withdraw.getPartyId(),null);
+ System.out.println("获取walletGather后");
+ System.out.println("walletGather-usdt"+walletGather.getUsdtMoney());
+ if (walletGather.getUsdtMoney() < withdraw.getVolume()) {
throw new BusinessException(1, "余额不足");
}
@@ -393,10 +398,12 @@
withdraw.setQdcode(withdraw_qr);
- double amount_before = wallet.getMoney();
+ double amount_before = walletGather.getUsdtMoney();
- wallet.setMoney(Arith.sub(wallet.getMoney(), withdraw.getVolume()));
- walletService.update(wallet.getPartyId().toString(), Arith.sub(0, withdraw.getVolume()));
+// wallet.setMoney(Arith.sub(wallet.getMoney(), withdraw.getVolume()));
+// walletService.update(wallet.getPartyId().toString(), Arith.sub(0, withdraw.getVolume()));
+ //修改资金账户
+ walletGatherService.update(walletGather.getPartyId().toString(),"usdt",withdraw.getVolume(),"sub");
withdraw.setId(ApplicationUtil.getCurrentTimeUUID());
insertWithdraw(withdraw);
@@ -408,7 +415,7 @@
moneyLog.setCategory(Constants.MONEYLOG_CATEGORY_COIN);
moneyLog.setAmount_before(amount_before);
moneyLog.setAmount(Arith.sub(0, withdraw.getVolume()));
- moneyLog.setAmount_after(wallet.getMoney());
+ moneyLog.setAmount_after(Arith.sub(amount_before, withdraw.getVolume()));
moneyLog.setLog("提现订单[" + withdraw.getOrder_no() + "]");
// moneyLog.setExtra(withdraw.getOrder_no());
@@ -523,7 +530,7 @@
return userWithdraw;
}
- public void saveApplyOtherChannel(Withdraw withdraw, String symbol) {
+ public void saveApplyOtherChannel(Withdraw withdraw, String symbol,WalletGatherService walletGatherService) {
Party party = this.partyService.cachePartyBy(withdraw.getPartyId(), false);
if (Constants.SECURITY_ROLE_TEST.equals(party.getRolename())) {
@@ -550,11 +557,29 @@
if (!party.getEnabled()) {
throw new BusinessException(506, "Your account has been frozen");
}
-
- WalletExtend walletExtend = walletService.saveExtendByPara(party.getId(), symbol);
- if (walletExtend.getAmount() < withdraw.getVolume()) {
- throw new BusinessException(1, "余额不足");
+ double amount_before = 0;
+ WalletGather walletGather = walletGatherService.getWalletGatherByPartyId(withdraw.getPartyId(),null);
+ if("btc".equals(symbol)){
+ if (walletGather.getBtcMoney() < withdraw.getVolume()) {
+ throw new BusinessException(1, "余额不足");
+ }
+ amount_before = walletGather.getBtcMoney();
+ }else if("eth".equals(symbol)){
+ if (walletGather.getEthMoney() < withdraw.getVolume()) {
+ throw new BusinessException(1, "余额不足");
+ }
+ amount_before = walletGather.getBtcMoney();
+ }else if("usdc".equals(symbol)){
+ if (walletGather.getUsdcMoney() < withdraw.getVolume()) {
+ throw new BusinessException(1, "余额不足");
+ }
+ amount_before = walletGather.getBtcMoney();
}
+
+// WalletExtend walletExtend = walletService.saveExtendByPara(party.getId(), symbol);
+// if (walletExtend.getAmount() < withdraw.getVolume()) {
+// throw new BusinessException(1, "余额不足");
+// }
String withdraw_limit = sysparaService.find("withdraw_limit_" + symbol).getValue();
if (withdraw.getVolume() < Double.valueOf(withdraw_limit)) {
@@ -706,9 +731,11 @@
withdraw.setQdcode(withdraw_qr);
- double amount_before = walletExtend.getAmount();
- walletService.updateExtend(walletExtend.getPartyId().toString(), symbol, Arith.sub(0, withdraw.getVolume()));
+// walletService.updateExtend(walletExtend.getPartyId().toString(), symbol, Arith.sub(0, withdraw.getVolume()));
+ //修改资金账户
+ walletGatherService.update(walletGather.getPartyId().toString(),symbol,withdraw.getVolume(),"sub");
+
withdraw.setId(ApplicationUtil.getCurrentTimeUUID());
insertWithdraw(withdraw);
diff --git a/src/main/resources/config/db.properties b/src/main/resources/config/db.properties
index 8c53656..85bcc5d 100644
--- a/src/main/resources/config/db.properties
+++ b/src/main/resources/config/db.properties
@@ -1,9 +1,9 @@
#\u5907\u4efd\u6570\u636e\u5e93
db.ip=127.0.0.1
-db.port=6306
+db.port=3306
db.database.name=dapp3
db.username=root
-db.password=GBysd4bW%2B5mEmZ4r0BxN0zFqpUG4FvlqdDbFvjTX80g%3D
+db.password=123456
db.backup.path=/backup
diff --git a/src/main/resources/config/redis.properties b/src/main/resources/config/redis.properties
index ce980db..f6934f8 100644
--- a/src/main/resources/config/redis.properties
+++ b/src/main/resources/config/redis.properties
@@ -1,5 +1,5 @@
-redis.address=127.0.0.1:6380
-redis.address.port=6380
+redis.address=127.0.0.1:6379
+redis.address.port=6379
redis.pool.testOnBorrow=true
redis.pool.testOnReturn=false
redis.pool.testWhileIdle=false
diff --git a/src/main/resources/spring/applicationContext-recharge_blockchain_admin.xml b/src/main/resources/spring/applicationContext-recharge_blockchain_admin.xml
index 4f761c5..9a6c8ff 100644
--- a/src/main/resources/spring/applicationContext-recharge_blockchain_admin.xml
+++ b/src/main/resources/spring/applicationContext-recharge_blockchain_admin.xml
@@ -18,9 +18,10 @@
<property name="partyService" ref="partyService" />
<property name="sysparaService" ref="sysparaService" />
<property name="channelBlockchainService" ref="channelBlockchainService" />
- <property name="tipService" ref="tipService" />
+ <property name="tipService" ref="tipService" />
+ <property name="redisHandler" ref="redisHandler" />
</bean>
-
+
<bean id="channelBlockchainService" class="project.blockchain.internal.ChannelBlockchainServiceImpl">
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="logService" ref="logService" />
--
Gitblit v1.9.3