111
This commit is contained in:
@@ -201,6 +201,11 @@ public class AdminController {
|
||||
String code = (String) params.get("code");
|
||||
BigDecimal price = new BigDecimal(params.get("price").toString());
|
||||
|
||||
// USDT价格固定为1,不允许修改
|
||||
if ("USDT".equalsIgnoreCase(code)) {
|
||||
return Result.fail("USDT价格固定为1,不可修改");
|
||||
}
|
||||
|
||||
Coin coin = coinService.getCoinByCode(code);
|
||||
if (coin == null) {
|
||||
return Result.fail("币种不存在");
|
||||
|
||||
@@ -153,16 +153,35 @@ public class AssetService {
|
||||
// 获取交易账户USDT持仓
|
||||
AccountTrade tradeUsdt = getOrCreateTradeAccount(userId, "USDT");
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
if (direction == 1) {
|
||||
// 资金账户 -> 交易账户
|
||||
if (fund.getBalance().compareTo(amount) < 0) {
|
||||
throw new RuntimeException("资金账户余额不足");
|
||||
}
|
||||
BigDecimal fundBalanceBefore = fund.getBalance();
|
||||
BigDecimal tradeBalanceBefore = tradeUsdt.getQuantity();
|
||||
|
||||
fund.setBalance(fund.getBalance().subtract(amount));
|
||||
tradeUsdt.setQuantity(tradeUsdt.getQuantity().add(amount));
|
||||
|
||||
// 使用 LambdaUpdateWrapper 显式更新资金账户
|
||||
LambdaUpdateWrapper<AccountFund> fundUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
fundUpdateWrapper.eq(AccountFund::getId, fund.getId())
|
||||
.set(AccountFund::getBalance, fund.getBalance())
|
||||
.set(AccountFund::getUpdateTime, now);
|
||||
accountFundMapper.update(null, fundUpdateWrapper);
|
||||
|
||||
// 使用 LambdaUpdateWrapper 显式更新交易账户
|
||||
LambdaUpdateWrapper<AccountTrade> tradeUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
tradeUpdateWrapper.eq(AccountTrade::getId, tradeUsdt.getId())
|
||||
.set(AccountTrade::getQuantity, tradeUsdt.getQuantity())
|
||||
.set(AccountTrade::getUpdateTime, now);
|
||||
accountTradeMapper.update(null, tradeUpdateWrapper);
|
||||
|
||||
// 记录流水
|
||||
createFlow(userId, 4, amount.negate(), fund.getBalance().add(amount),
|
||||
createFlow(userId, 4, amount.negate(), fundBalanceBefore,
|
||||
fund.getBalance(), "USDT", null, "划转至交易账户");
|
||||
|
||||
} else if (direction == 2) {
|
||||
@@ -170,22 +189,37 @@ public class AssetService {
|
||||
if (tradeUsdt.getQuantity().compareTo(amount) < 0) {
|
||||
throw new RuntimeException("交易账户USDT余额不足");
|
||||
}
|
||||
BigDecimal fundBalanceBefore = fund.getBalance();
|
||||
BigDecimal tradeBalanceBefore = tradeUsdt.getQuantity();
|
||||
|
||||
tradeUsdt.setQuantity(tradeUsdt.getQuantity().subtract(amount));
|
||||
fund.setBalance(fund.getBalance().add(amount));
|
||||
|
||||
// 使用 LambdaUpdateWrapper 显式更新资金账户
|
||||
LambdaUpdateWrapper<AccountFund> fundUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
fundUpdateWrapper.eq(AccountFund::getId, fund.getId())
|
||||
.set(AccountFund::getBalance, fund.getBalance())
|
||||
.set(AccountFund::getUpdateTime, now);
|
||||
accountFundMapper.update(null, fundUpdateWrapper);
|
||||
|
||||
// 使用 LambdaUpdateWrapper 显式更新交易账户
|
||||
LambdaUpdateWrapper<AccountTrade> tradeUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||
tradeUpdateWrapper.eq(AccountTrade::getId, tradeUsdt.getId())
|
||||
.set(AccountTrade::getQuantity, tradeUsdt.getQuantity())
|
||||
.set(AccountTrade::getUpdateTime, now);
|
||||
accountTradeMapper.update(null, tradeUpdateWrapper);
|
||||
|
||||
// 记录流水
|
||||
createFlow(userId, 3, amount, fund.getBalance().subtract(amount),
|
||||
createFlow(userId, 3, amount, fundBalanceBefore,
|
||||
fund.getBalance(), "USDT", null, "划转至资金账户");
|
||||
|
||||
} else {
|
||||
throw new RuntimeException("无效的划转方向");
|
||||
}
|
||||
|
||||
fund.setUpdateTime(LocalDateTime.now());
|
||||
accountFundMapper.updateById(fund);
|
||||
|
||||
tradeUsdt.setUpdateTime(LocalDateTime.now());
|
||||
accountTradeMapper.updateById(tradeUsdt);
|
||||
System.out.println("[划转成功] 用户ID=" + userId + ", 方向=" + (direction == 1 ? "资金→交易" : "交易→资金") +
|
||||
", 金额=" + amount + " USDT, 资金账户余额=" + fund.getBalance() +
|
||||
", 交易账户USDT=" + tradeUsdt.getQuantity());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,8 +36,13 @@ public class CoinService extends ServiceImpl<CoinMapper, Coin> {
|
||||
|
||||
/**
|
||||
* 更新币种价格
|
||||
* 注意:USDT价格固定为1,不允许修改
|
||||
*/
|
||||
public void updatePrice(String code, BigDecimal price) {
|
||||
// USDT价格固定为1,不允许修改
|
||||
if ("USDT".equalsIgnoreCase(code)) {
|
||||
return;
|
||||
}
|
||||
Coin coin = getCoinByCode(code);
|
||||
if (coin != null) {
|
||||
coin.setPrice(price);
|
||||
|
||||
Reference in New Issue
Block a user