[Snow Team] backend-fixer: auto-commit work
This commit is contained in:
@@ -25,7 +25,8 @@ type FreezeRequest struct {
|
||||
}
|
||||
|
||||
type DepositFreeQuotaRequest struct {
|
||||
Amount float64 `json:"amount"`
|
||||
AmountCent int64 `json:"amount_cent"`
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
||||
type PaginatedResult struct {
|
||||
|
||||
@@ -2,6 +2,7 @@ package adminuser
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"hfb_sys/backend/internal/auditlog"
|
||||
"hfb_sys/backend/internal/model"
|
||||
@@ -60,24 +61,29 @@ func (r *Repository) Unfreeze(adminID uint64, userID uint64, meta AuditMeta) (*U
|
||||
}
|
||||
|
||||
func (r *Repository) SetDepositFreeQuota(adminID uint64, userID uint64, req DepositFreeQuotaRequest, meta AuditMeta) (*UserDTO, error) {
|
||||
amount := roundMoney(req.Amount)
|
||||
if amount < 0 {
|
||||
amountCent := depositFreeQuotaAmountCent(req)
|
||||
if amountCent < 0 {
|
||||
return nil, ErrInvalidUser
|
||||
}
|
||||
amount := float64(amountCent) / 100
|
||||
err := r.db.Transaction(func(tx *gorm.DB) error {
|
||||
var user model.User
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&user, userID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
beforeAmount := user.DepositFreeQuota
|
||||
beforeAmountCent := user.DepositFreeQuotaCent
|
||||
user.DepositFreeQuota = amount
|
||||
user.DepositFreeQuotaCent = amountCent
|
||||
if err := tx.Save(&user).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return appendAuditLog(tx, adminID, "admin_user.set_deposit_free_quota", user.ID, meta, map[string]any{
|
||||
"user_id": user.ID,
|
||||
"before_amount": beforeAmount,
|
||||
"after_amount": amount,
|
||||
"user_id": user.ID,
|
||||
"before_amount": beforeAmount,
|
||||
"after_amount": amount,
|
||||
"before_amount_cent": beforeAmountCent,
|
||||
"after_amount_cent": amountCent,
|
||||
})
|
||||
})
|
||||
if err != nil {
|
||||
@@ -172,6 +178,13 @@ func roundMoney(value float64) float64 {
|
||||
return money.Round(value)
|
||||
}
|
||||
|
||||
func depositFreeQuotaAmountCent(req DepositFreeQuotaRequest) int64 {
|
||||
if req.AmountCent != 0 {
|
||||
return req.AmountCent
|
||||
}
|
||||
return int64(math.Round(req.Amount * 100))
|
||||
}
|
||||
|
||||
func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizID uint64, meta AuditMeta, detail map[string]any) error {
|
||||
return auditlog.Append(tx, auditlog.Entry{
|
||||
ActorType: "admin",
|
||||
|
||||
Reference in New Issue
Block a user