From b28a97e1bf66e3279e78f31ce58122427787ceec Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Thu, 11 Jun 2026 09:44:20 +0800
Subject: [PATCH] 1
---
trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java | 57 +++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 45 insertions(+), 12 deletions(-)
diff --git a/trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java b/trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java
index aff60f2..07cc693 100644
--- a/trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java
+++ b/trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java
@@ -145,7 +145,7 @@
log.info("=============111111===>"+walletType);
walletExtend.setAmount(Arith.add(walletExtend.getAmount(), amount));
if (!walletExtendService.updateById(walletExtend)) {
- throw new YamiShopBindException("操作钱包失败!");
+ throw new YamiShopBindException("Wallet operation failed!");
}
redisTemplate.opsForValue().set(WalletRedisKeys.WALLET_EXTEND_PARTY_ID + partyId.toString() + walletType, walletExtend);
@@ -180,12 +180,12 @@
wallet.setMoney(wallet.getMoney().add(money));
if(wallet.getMoney().compareTo(BigDecimal.ZERO) < 0){
- wallet.setMoney(BigDecimal.ZERO);
+ throw new YamiShopBindException("Insufficient balance");
}
wallet.setUpdateTime(now);
- if (wallet.getMoney().doubleValue() <= 0) {
- throw new YamiShopBindException("余额不足");
- }
+ /*if (wallet.getMoney().doubleValue() < 0) {
+ throw new YamiShopBindException("Insufficient balance");
+ }*/
updateById(wallet);
// 账变日志
MoneyLog moneyLog = new MoneyLog();
@@ -297,7 +297,7 @@
close = realtimes.get(0).getClose().doubleValue();
} else {
close = 0;
- //throw new YamiShopBindException("参数错误");
+ //throw new YamiShopBindException("Invalid parameters");
}
return close;
}
@@ -712,14 +712,17 @@
BigDecimal orderVolume = BigDecimal.ONE;
- if (order.getLeverRate() != null && order.getLeverRate().compareTo(BigDecimal.ZERO) != 0) {
+ if (order.getLeverRate() != null && order.getLeverRate().compareTo(BigDecimal.ZERO) != 0
+ && order.getVolumeOpen() != null) {
orderVolume = order.getVolumeOpen().divide(order.getLeverRate(), 2, BigDecimal.ROUND_HALF_UP);
- } else {
+ } else if (order.getVolumeOpen() != null) {
orderVolume = order.getVolumeOpen();
}
- BigDecimal moneyContract = orderVolume.multiply(order.getUnitAmount()).add(order.getProfit());
- BigDecimal moneyContractDeposit = order.getDeposit();
- BigDecimal moneyContractProfit = order.getProfit();
+ BigDecimal unitAmount = order.getUnitAmount() != null ? order.getUnitAmount() : BigDecimal.ZERO;
+ BigDecimal profit = order.getProfit() != null ? order.getProfit() : BigDecimal.ZERO;
+ BigDecimal moneyContract = orderVolume.multiply(unitAmount).add(profit);
+ BigDecimal moneyContractDeposit = order.getDeposit() != null ? order.getDeposit() : BigDecimal.ZERO;
+ BigDecimal moneyContractProfit = profit;
moneysContract.put("money_contract", moneyContract);
@@ -751,11 +754,41 @@
Wallet wallet = findByUserId(userId);
wallet.setMoney(new BigDecimal(Arith.add(wallet.getMoney().doubleValue(), amount)));
if (!updateById(wallet)) {
- throw new YamiShopBindException("操作钱包失败!");
+ throw new YamiShopBindException("Wallet operation failed!");
}
}
+ @Override
+ public Wallet updateToBeCovered(Wallet wallet, BigDecimal amount, Integer type) {
+ amount = amount.abs();
+ if (type == 1) { //入款
+ if(wallet.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
+ BigDecimal availableBalance = amount.subtract(wallet.getAmountToBeCovered());
+ if(availableBalance.compareTo(BigDecimal.ZERO) >= 0){
+ wallet.setMoney(wallet.getMoney().add(availableBalance));
+ wallet.setAmountToBeCovered(BigDecimal.ZERO);
+ }else {
+ wallet.setAmountToBeCovered(availableBalance.abs());
+ }
+ } else {
+ wallet.setMoney(wallet.getMoney().add(amount));
+ }
+ } else if (type == 2) { //扣款
+ BigDecimal subtract = amount.subtract(wallet.getMoney());
+ if (subtract.compareTo(BigDecimal.ZERO) > 0) { //资金不足 放入待补
+ wallet.setMoney(BigDecimal.ZERO);
+ wallet.setAmountToBeCovered(wallet.getAmountToBeCovered().add(subtract));
+ } else {
+ wallet.setMoney(subtract.negate());
+ }
+ }
+ if (!updateById(wallet)) {
+ throw new YamiShopBindException("Wallet operation failed!");
+ }
+ return wallet;
+ }
+
@Override
public void updateExtendWithLockAndFreeze(String partyId, String walletType, double amount, double lockAmount, double freezeAmount) {
--
Gitblit v1.9.3