Skip to content

Commit

Permalink
fix: 修复旧用户的vip被降级,尽量不对原先用户做变动
Browse files Browse the repository at this point in the history
  • Loading branch information
jinjianming committed Jul 17, 2024
1 parent 25e1af2 commit 849f52c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,22 @@ func (user *User) ValidateAndFill() (err error) {
return errors.New("用户名或密码错误,或用户已被封禁")
}
// 校验用户是不是非default,如果是非default,判断到期时间如果过期了降级为default
if user.Group != "default" {
if user.ExpirationDate > 0 {

Check warning on line 217 in model/user.go

View check run for this annotation

Codecov / codecov/patch

model/user.go#L217

Added line #L217 was not covered by tests
// 将时间戳转换为 time.Time 类型
expirationTime := time.Unix(user.ExpirationDate, 0)

Check warning on line 219 in model/user.go

View check run for this annotation

Codecov / codecov/patch

model/user.go#L219

Added line #L219 was not covered by tests
// 获取当前时间
currentTime := time.Now()

Check warning on line 221 in model/user.go

View check run for this annotation

Codecov / codecov/patch

model/user.go#L221

Added line #L221 was not covered by tests

// 比较当前时间和到期时间
if expirationTime.Before(currentTime) {

Check warning on line 224 in model/user.go

View check run for this annotation

Codecov / codecov/patch

model/user.go#L224

Added line #L224 was not covered by tests
// 降级为default
// 降级为 default
user.Group = "default"
err = DB.Model(user).Updates(user).Error
fmt.Printf("用户: %s,特权组过期降为default", user.Username)
return err
err := DB.Model(user).Updates(user).Error
if err != nil {
fmt.Printf("用户: %s, 降级为 default 时发生错误: %v\n", user.Username, err)
return err

Check warning on line 230 in model/user.go

View check run for this annotation

Codecov / codecov/patch

model/user.go#L226-L230

Added lines #L226 - L230 were not covered by tests
}
fmt.Printf("用户: %s, 特权组过期降为 default\n", user.Username)

Check warning on line 232 in model/user.go

View check run for this annotation

Codecov / codecov/patch

model/user.go#L232

Added line #L232 was not covered by tests
}
}
return nil
Expand Down

0 comments on commit 849f52c

Please sign in to comment.