From b512f3d680be5593cd8dc92b75b0f31b1e5b0bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Fri, 13 Jan 2023 18:51:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=94=A8=E6=88=B7=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=E6=9B=B4=E6=94=B9=E4=BB=A5=E5=BE=80=E5=90=8C?= =?UTF-8?q?=E5=90=8D=E7=94=A8=E6=88=B7=E7=9A=84=E7=94=A8=E6=88=B7=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/user_dao.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/internal/db/models/user_dao.go b/internal/db/models/user_dao.go index e6171b77..275ecf82 100644 --- a/internal/db/models/user_dao.go +++ b/internal/db/models/user_dao.go @@ -12,6 +12,7 @@ import ( "github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/lists" + "github.com/iwind/TeaGo/rands" "github.com/iwind/TeaGo/types" stringutil "github.com/iwind/TeaGo/utils/string" timeutil "github.com/iwind/TeaGo/utils/time" @@ -66,7 +67,27 @@ func (this *UserDAO) DisableUser(tx *dbs.Tx, userId int64) error { return errors.New("invalid 'userId'") } - _, err := this.Query(tx). + // 处理以往同用户名用户 + username, err := this.Query(tx). + Pk(userId). + Result("username"). + FindStringCol("") + if err != nil { + return err + } + if len(username) > 0 { + err = this.Query(tx). + Attr("username", username). + Attr("state", UserStateDisabled). + Set("username", username+"_"+rands.HexString(8)). + UpdateQuickly() + if err != nil { + return err + } + } + + // 禁止当前 + _, err = this.Query(tx). Pk(userId). Set("state", UserStateDisabled). Update()