From cf4322f5e7a51afa3c57f22c961c5e972ff64577 Mon Sep 17 00:00:00 2001 From: Queenie Date: Mon, 28 Oct 2019 10:27:16 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9A=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/account.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/models/account.go b/models/account.go index 30e97ff..bb58995 100644 --- a/models/account.go +++ b/models/account.go @@ -62,6 +62,11 @@ type Account struct { func (account *Account) AfterSave(db *gorm.DB) {} +func (account *Account) Amount() (amount decimal.Decimal) { + amount = account.Balance.Add(account.Locked) + return +} + func (account *Account) PlusFunds(db *utils.GormDB, amount, fee decimal.Decimal, reason, modifiableId int, modifiableType string) (err error) { if amount.LessThan(decimal.Zero) || fee.GreaterThan(amount) { err = fmt.Errorf("cannot add funds (amount: %v)", amount) @@ -179,7 +184,7 @@ func (account *Account) after(db *utils.GormDB, fun int, amount decimal.Decimal, "fun": strconv.Itoa(fun), "fee": fee.String(), "reason": strconv.Itoa(reason), - "amount": amount.String(), + "amount": account.Amount().String(), "currency_id": strconv.Itoa(account.CurrencyId), "user_id": strconv.Itoa(account.UserId), "account_id": strconv.Itoa(account.Id),