diff --git a/model/gmodel/fs_user_logic.go b/model/gmodel/fs_user_logic.go index 243c533f..c62fc342 100644 --- a/model/gmodel/fs_user_logic.go +++ b/model/gmodel/fs_user_logic.go @@ -147,83 +147,63 @@ func (u *FsUserModel) RegisterByFusen(ctx context.Context, token *auth.RegisterT err := u.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { var err error - defer func() { - if err == gorm.ErrRecordNotFound { - err = nil - } - - }() - UserTx := tx.Model(user) err = UserTx.Where("email = ?", token.Email).Take(user).Error - if err != nil { - // 没有找到在数据库就创建注册 - if err == gorm.ErrRecordNotFound { + if err == gorm.ErrRecordNotFound { - FirstName := token.Extend["first_name"].(string) - LastName := token.Extend["last_name"].(string) - Resetaurant := token.Extend["resetaurant"].(string) + FirstName := token.Extend["first_name"].(string) + LastName := token.Extend["last_name"].(string) + Resetaurant := token.Extend["resetaurant"].(string) - createAt := time.Now().UTC().Unix() - user.Email = &token.Email - user.CreatedAt = &createAt - user.PasswordHash = &token.Password - user.FirstName = &FirstName - user.LastName = &LastName + createAt := time.Now().UTC().Unix() + user.Email = &token.Email + user.CreatedAt = &createAt + user.PasswordHash = &token.Password + user.FirstName = &FirstName + user.LastName = &LastName - err = UserTx.Create(user).Error - logcontent += "create." - if err != nil { - return err - } + err = UserTx.Create(user).Error - if token.GuestId != 0 { - // 继承guest_id的资源表 - err = InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error { - userProfile := &UserProfile{ - FirstName: FirstName, - LastName: LastName, - Resetaurant: Resetaurant, - } - metadata, err := json.Marshal(userProfile) - if err != nil { - return err - } - now := time.Now() - uinfo := &FsUserInfo{ - Module: FsString("profile"), - UserId: &user.Id, - GuestId: &token.GuestId, - Metadata: &metadata, - Ctime: &now, - Utime: &now, - } - logcontent += "profile." - return txUserInfo.Create(uinfo).Error - }) - } + if err != nil { + logx.Error(err) + return err + } + + logcontent += "create." + if token.GuestId != 0 { + // 继承guest_id的资源表 + err = InheritGuestIdResource(tx, user.Id, token.GuestId, func(txResouce, txUserMaterial, txUserInfo *gorm.DB) error { + userProfile := &UserProfile{ + FirstName: FirstName, + LastName: LastName, + Resetaurant: Resetaurant, + } + metadata, err := json.Marshal(userProfile) + if err != nil { + return err + } + now := time.Now() + uinfo := &FsUserInfo{ + Module: FsString("profile"), + UserId: &user.Id, + GuestId: &token.GuestId, + Metadata: &metadata, + Ctime: &now, + Utime: &now, + } + logcontent += "profile." + return txUserInfo.Create(uinfo).Error + }) if err == gorm.ErrRecordNotFound { - err = nil + return nil } return err } - if err == gorm.ErrRecordNotFound { - err = nil - } - - return err } - if err == nil { - return fmt.Errorf("the email had registered") - } - - if err == gorm.ErrRecordNotFound { - err = nil - } - return err + return fmt.Errorf("the email had registered") }) if err != nil && err != gorm.ErrRecordNotFound {