-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calculate the reward #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move these lines up to the invitation code check block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这部分代码更适合放在 register_active 的逻辑中 此外这部分也应该使用事务包起来 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,29 @@ func Register(db *gorm.DB, u *models.User, invitation_code string) error { | |
return errors.Wrap(err, errors.DatabaseError) | ||
} | ||
|
||
|
||
|
||
|
||
//若该用户通过邀请码注册 | ||
if u.InvitationCode != ""{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
//寻找邀请人,找到后邀请人加一元 | ||
userInvite:= &models.User{} | ||
resultInvite := db.Where("invitation_code = ?", invitation_code).Take(userInvite) | ||
if err:=resultInvite.Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { | ||
return errors.Wrap(err, errors.DatabaseError) | ||
} | ||
if result.RowsAffected > 0 { | ||
if user.IsActive { | ||
return errors.New(errors.UserEmailDuplicated) | ||
} else { | ||
db.Delete(user) | ||
} | ||
} | ||
userInvite.Reward += 100 | ||
//将此字段标记为true,表示当被邀请人发表评论时可获得奖励 | ||
u.InvCommitReward = true | ||
} | ||
|
||
body := fmt.Sprintf(`<html><body> | ||
<h1>欢迎注册%s</h1> <p>我们已经接收到您的电子邮箱验证申请,请点击以下链接完成注册。</p> | ||
<p>验证完成后,您将能够即刻发布课程评价,并与其他用户互动。</p> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments/Post
方法内。Save
保存,否则修改不会写入数据库。comments/post.go:106
中 :