address和USDTmanage/address token管理页面,参考归集任务页面布局和功能,添加统计功能,优化页面布局。 商户和管理员都去掉删除和修改,商户的详情页面去掉对地址的各种金额操作,只保留刷新链上数据功能。
This commit is contained in:
1 parent
c516124eff
commit
e4ac32e8d7
4 files changed
+141
-10
No files matched your search
@@ -174,6 +174,15 @@ public class AppsController extends BaseController {
|
||||
return toAjax(appsService.updateApps(apps, false));
|
||||
}
|
||||
|
||||
/** TRX 与 USDT 使用同一财务权限和行锁,冻结余额不参与人工调整。 */
|
||||
@PreAuthorize("@ss.hasPermi('system:apps:balance-adjust')")
|
||||
@Log(title = "调整应用 TRX 余额", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/{id}/trx-balance-adjustment")
|
||||
public AjaxResult adjustTrxBalance(@PathVariable("id") Long id,
|
||||
@RequestBody AppUsdtBalanceAdjustmentRequest request) {
|
||||
return AjaxResult.success(appsService.adjustTrxBalance(id, request));
|
||||
}
|
||||
|
||||
/** 管理员人工增加或减少应用 USDT 可用余额,余额与流水在同一事务内更新。 */
|
||||
@PreAuthorize("@ss.hasPermi('system:apps:balance-adjust')")
|
||||
@Log(title = "调整应用 USDT 余额", businessType = BusinessType.UPDATE)
|
||||
|
||||
@@ -28,6 +28,9 @@ public interface IAppsService extends IService<AppsPlus>
|
||||
/** 管理员调整应用 USDT 可用余额,并在同一事务中记录资金流水。 */
|
||||
Apps adjustUsdtBalance(Long id, AppUsdtBalanceAdjustmentRequest request);
|
||||
|
||||
/** 管理员调整 TRX 可用余额,锁定应用并原子记录币种流水。 */
|
||||
Apps adjustTrxBalance(Long id, AppUsdtBalanceAdjustmentRequest request);
|
||||
|
||||
List<SelectItem> select(String keyword,boolean isUser);
|
||||
/**
|
||||
* 查询应用管理
|
||||
|
||||
@@ -100,10 +100,22 @@ public class AppsServiceImpl extends ServiceImpl<AppsMapper, AppsPlus> implement
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Apps adjustUsdtBalance(Long id, AppUsdtBalanceAdjustmentRequest request) {
|
||||
return adjustAvailableBalance(id, request, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Apps adjustTrxBalance(Long id, AppUsdtBalanceAdjustmentRequest request) {
|
||||
return adjustAvailableBalance(id, request, true);
|
||||
}
|
||||
|
||||
/** 两个公开事务入口共用校验、应用行锁及流水写入,避免币种逻辑分叉。 */
|
||||
private Apps adjustAvailableBalance(Long id, AppUsdtBalanceAdjustmentRequest request, boolean trx) {
|
||||
String currency = trx ? "TRX" : "USDT";
|
||||
if (id == null || request == null) {
|
||||
throw new CustomException("应用和调整参数不能为空");
|
||||
}
|
||||
String type = StringUtils.trim(request.getType()).toUpperCase(Locale.ROOT);
|
||||
String type = request.getType() == null ? "" : request.getType().trim().toUpperCase(Locale.ROOT);
|
||||
if (!BALANCE_ADD.equals(type) && !BALANCE_SUBTRACT.equals(type)) {
|
||||
throw new CustomException("调整类型只能为增加或减少");
|
||||
}
|
||||
@@ -127,24 +139,28 @@ public class AppsServiceImpl extends ServiceImpl<AppsMapper, AppsPlus> implement
|
||||
if (app == null) {
|
||||
throw new CustomException("商户不存在或已删除");
|
||||
}
|
||||
BigDecimal before = app.getUsdtBalance() == null ? BigDecimal.ZERO : app.getUsdtBalance();
|
||||
BigDecimal currentBalance = trx ? app.getTrxBalance() : app.getUsdtBalance();
|
||||
BigDecimal before = currentBalance == null ? BigDecimal.ZERO : currentBalance;
|
||||
BigDecimal after = BALANCE_ADD.equals(type) ? before.add(amount) : before.subtract(amount);
|
||||
if (after.signum() < 0) {
|
||||
throw new CustomException("USDT 可用余额不足,当前可用余额为 " + before.toPlainString());
|
||||
if (BALANCE_SUBTRACT.equals(type) && after.signum() < 0) {
|
||||
throw new CustomException(currency + " 可用余额不足,当前可用余额为 " + before.toPlainString());
|
||||
}
|
||||
if (after.precision() - after.scale() > 24) {
|
||||
throw new CustomException("调整后余额超出 DECIMAL(30,6) 范围");
|
||||
}
|
||||
Date now = DateUtils.getNowDate();
|
||||
if (appsMapper.updateAvailableBalances(app.getId(), after,
|
||||
app.getTrxBalance() == null ? BigDecimal.ZERO : app.getTrxBalance(), now) != 1) {
|
||||
if (appsMapper.updateAvailableBalances(app.getId(), trx ? app.getUsdtBalance() : after,
|
||||
trx ? after : app.getTrxBalance(), now) != 1) {
|
||||
throw new CustomException("应用余额更新失败");
|
||||
}
|
||||
|
||||
String tradeNo = "ADJ" + UUID.randomUUID().toString().replace("-", "").toUpperCase(Locale.ROOT);
|
||||
AppsBalanceLedger ledger = new AppsBalanceLedger();
|
||||
ledger.setTradeNo(tradeNo);
|
||||
ledger.setIdempotencyKey("ADMIN_USDT_ADJUST:" + tradeNo);
|
||||
ledger.setIdempotencyKey("ADMIN_" + currency + "_ADJUST:" + tradeNo);
|
||||
ledger.setAppId(app.getId());
|
||||
ledger.setUserId(app.getUserId());
|
||||
ledger.setCurrency("USDT");
|
||||
ledger.setCurrency(currency);
|
||||
ledger.setBalanceType(1);
|
||||
ledger.setBusinessType(BALANCE_ADD.equals(type) ? "ADMIN_BALANCE_ADD" : "ADMIN_BALANCE_SUBTRACT");
|
||||
ledger.setDirection(BALANCE_ADD.equals(type) ? 1 : 2);
|
||||
@@ -153,7 +169,8 @@ public class AppsServiceImpl extends ServiceImpl<AppsMapper, AppsPlus> implement
|
||||
ledger.setBalanceAfter(after);
|
||||
ledger.setAvailableBefore(before);
|
||||
ledger.setAvailableAfter(after);
|
||||
BigDecimal frozen = app.getUsdtFrozenBalance() == null ? BigDecimal.ZERO : app.getUsdtFrozenBalance();
|
||||
BigDecimal frozenBalance = trx ? app.getTrxFrozenBalance() : app.getUsdtFrozenBalance();
|
||||
BigDecimal frozen = frozenBalance == null ? BigDecimal.ZERO : frozenBalance;
|
||||
ledger.setFrozenBefore(frozen);
|
||||
ledger.setFrozenAfter(frozen);
|
||||
ledger.setOperatorId(SecurityUtils.getUserId());
|
||||
@@ -163,7 +180,11 @@ public class AppsServiceImpl extends ServiceImpl<AppsMapper, AppsPlus> implement
|
||||
if (appsBalanceLedgerMapper.insertAppsBalanceLedger(ledger) != 1) {
|
||||
throw new CustomException("应用余额流水记录失败");
|
||||
}
|
||||
app.setUsdtBalance(after);
|
||||
if (trx) {
|
||||
app.setTrxBalance(after);
|
||||
} else {
|
||||
app.setUsdtBalance(after);
|
||||
}
|
||||
app.setUpdatedAt(now);
|
||||
return app;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user