🐛 fix: delete soft delete error
This commit is contained in:
parent
a8891c0f72
commit
c80f81b177
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"one-api/common"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@ -32,7 +31,7 @@ type User struct {
|
||||
AffCode string `json:"aff_code" gorm:"type:varchar(32);column:aff_code;uniqueIndex"`
|
||||
InviterId int `json:"inviter_id" gorm:"type:int;column:inviter_id;index"`
|
||||
CreatedTime int64 `json:"created_time" gorm:"bigint"`
|
||||
DeletedAt *time.Time `gorm:"index"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
}
|
||||
|
||||
type UserUpdates func(*User)
|
||||
@ -161,7 +160,15 @@ func (user *User) Delete() error {
|
||||
if user.Id == 0 {
|
||||
return errors.New("id 为空!")
|
||||
}
|
||||
err := DB.Delete(user).Error
|
||||
|
||||
// 不改变当前数据库索引,通过更改用户名来删除用户
|
||||
user.Username = user.Username + "_del_" + common.GetRandomString(6)
|
||||
err := user.Update(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = DB.Delete(user).Error
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user