From 9ad045c8f40ecccb8280dfed5b7102ce2f400d68 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 8 Sep 2023 10:52:51 +0800 Subject: [PATCH] fix --- model/gmodel/fs_user_logic.go | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index e795973d..466b122c 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -216,38 +216,31 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT err = txUserInfo.Where("user_id = ?", uinfo.UserId).Take(nil).Error // txUserInfo.Statement.Table - if err == nil { + if err != nil { + if err == gorm.ErrRecordNotFound { + err = txUserInfo.Create(uinfo).Error + if err == gorm.ErrRecordNotFound { + return nil + } + } + } else { updatesql := `UPDATE %s SET metadata = CASE - WHEN metadata IS NULL THEN '%s' - ELSE JSON_MERGE_PATCH(metadata, '%s') + WHEN metadata IS NULL THEN ? + ELSE JSON_MERGE_PATCH(metadata, ?) END WHERE id = ?;` updatesql = fmt.Sprintf(updatesql, txUserInfo.Statement.Table) - - txUserInfo.Raw(`UPDATE fusen.fs_change_code - SET metadata = CASE - WHEN metadata IS NULL THEN '%s' - ELSE JSON_MERGE_PATCH(metadata, '%s') - END - WHERE id = ?;`) + txUserInfo.Raw(updatesql, metadata, metadata, uinfo.UserId) } - - if err == gorm.ErrRecordNotFound { - err = txUserInfo.Create(uinfo).Error - if err == gorm.ErrRecordNotFound { - return nil - } - } - return err - }) if err == gorm.ErrRecordNotFound { return nil } + return err }