refactor: clean admin navigation and user details

This commit is contained in:
OpenClaw Agent
2026-09-17 03:42:24 +08:00
parent fef1cb7057
commit 6ccaec53d7
2 changed files with 29 additions and 14 deletions
+13 -4
View File
@@ -302,7 +302,8 @@ func (a *App) adminAdjustCredits(c *gin.Context) {
return
}
var in struct {
Amount int64 `json:"amount"`
Amount int64 `json:"amount"`
Reason string `json:"reason"`
}
if c.BindJSON(&in) != nil || in.Amount == 0 {
c.JSON(400, gin.H{"error": "amount cannot be zero"})
@@ -324,9 +325,15 @@ func (a *App) adminAdjustCredits(c *gin.Context) {
if err := tx.Save(&account).Error; err != nil {
return err
}
typ, reason := "grant", "admin credit adjustment"
typ, reason := "grant", strings.TrimSpace(in.Reason)
if reason == "" {
reason = "admin credit adjustment"
}
if in.Amount < 0 {
typ, reason = "admin_debit", "admin credit deduction"
typ = "admin_debit"
if strings.TrimSpace(in.Reason) == "" {
reason = "admin credit deduction"
}
}
return tx.Create(&CreditTransaction{UserID: uint(id), Type: typ, Amount: in.Amount, BalanceAfter: account.Balance, ReferenceType: "admin", ReferenceID: strconv.FormatUint(uint64(operator.ID), 10), Reason: reason}).Error
})
@@ -335,5 +342,7 @@ func (a *App) adminAdjustCredits(c *gin.Context) {
return
}
a.audit(operator.ID, "user.credits.adjust", "user", strconv.FormatUint(id, 10), "amount="+strconv.FormatInt(in.Amount, 10))
c.JSON(200, gin.H{"ok": true})
var account CreditAccount
_ = a.db.Where("user_id = ?", id).First(&account)
c.JSON(200, gin.H{"ok": true, "balance": account.Balance, "reserved": account.Reserved, "available": account.Balance - account.Reserved})
}