From aa717ed1fe3a970876d6bb08d1240fc622c5d110 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 20 Aug 2023 00:48:42 +0800 Subject: [PATCH] fix the problem that the time zone of the modify balance transaction generated by creating a new account was wrong --- pkg/api/accounts.go | 9 ++++++++- pkg/services/accounts.go | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/api/accounts.go b/pkg/api/accounts.go index 373eff3e..6644b0b9 100644 --- a/pkg/api/accounts.go +++ b/pkg/api/accounts.go @@ -136,6 +136,13 @@ func (a *AccountsApi) AccountCreateHandler(c *core.Context) (interface{}, *errs. return nil, errs.NewIncompleteOrIncorrectSubmissionError(err) } + utcOffset, err := c.GetClientTimezoneOffset() + + if err != nil { + log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] cannot get client timezone offset, because %s", err.Error()) + return nil, errs.ErrClientTimezoneOffsetInvalid + } + if accountCreateReq.Type == models.ACCOUNT_TYPE_SINGLE_ACCOUNT { if len(accountCreateReq.SubAccounts) > 0 { log.WarnfWithRequestId(c, "[accounts.AccountCreateHandler] account cannot have any sub accounts") @@ -196,7 +203,7 @@ func (a *AccountsApi) AccountCreateHandler(c *core.Context) (interface{}, *errs. mainAccount := a.createNewAccountModel(uid, &accountCreateReq, maxOrderId+1) childrenAccounts := a.createSubAccountModels(uid, &accountCreateReq) - err = a.accounts.CreateAccounts(mainAccount, childrenAccounts) + err = a.accounts.CreateAccounts(mainAccount, childrenAccounts, utcOffset) if err != nil { log.ErrorfWithRequestId(c, "[accounts.AccountCreateHandler] failed to create account \"id:%d\" for user \"uid:%d\", because %s", mainAccount.AccountId, uid, err.Error()) diff --git a/pkg/services/accounts.go b/pkg/services/accounts.go index 79e7208f..34f86d5d 100644 --- a/pkg/services/accounts.go +++ b/pkg/services/accounts.go @@ -151,7 +151,7 @@ func (s *AccountService) GetMaxSubAccountDisplayOrder(uid int64, category models } // CreateAccounts saves a new account model to database -func (s *AccountService) CreateAccounts(mainAccount *models.Account, childrenAccounts []*models.Account) error { +func (s *AccountService) CreateAccounts(mainAccount *models.Account, childrenAccounts []*models.Account, utcOffset int16) error { if mainAccount.Uid <= 0 { return errs.ErrUserIdInvalid } @@ -190,6 +190,7 @@ func (s *AccountService) CreateAccounts(mainAccount *models.Account, childrenAcc Deleted: false, Type: models.TRANSACTION_DB_TYPE_MODIFY_BALANCE, TransactionTime: transactionTime, + TimezoneUtcOffset: utcOffset, AccountId: allAccounts[i].AccountId, Amount: allAccounts[i].Balance, RelatedAccountId: allAccounts[i].AccountId,