From 81e16613800f974ab987738dcdca0da86edf063c Mon Sep 17 00:00:00 2001 From: Echo <1711788888@qq.com> Date: Wed, 17 Sep 2025 18:32:18 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=96=B0=E5=A2=9E=E5=B0=81=E7=A6=81?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BF=94=E5=9B=9E=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=B8=8A=E4=BC=A0=E6=9C=BA=E5=99=A8=E4=BA=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v1/app/user.go | 10 ++++++++++ api/v1/bot/bot.go | 20 ++++++++++++++++++++ model/bot/request/bot.go | 4 ++++ model/common/response/response.go | 9 +++++++++ router/bot/bot.go | 1 + service/bot/bot.go | 31 +++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+) diff --git a/api/v1/app/user.go b/api/v1/app/user.go index efb8a50..10b1920 100644 --- a/api/v1/app/user.go +++ b/api/v1/app/user.go @@ -131,6 +131,11 @@ func (*AppUserApi) WechatLogin(ctx *gin.Context) { r.FailWithMessage("登录失败:"+err.Error(), ctx) return } + + if user.Status == 0 { + r.Banned("用户已被禁用", ctx) + return + } // 生成token token, claims, err := user_jwt.LoginToken(user) if err != nil { @@ -208,6 +213,11 @@ func (*AppUserApi) PwdLogin(ctx *gin.Context) { return } + if user.Status == 0 { + r.Banned("用户已被禁用", ctx) + return + } + // 生成token token, claims, err := user_jwt.LoginToken(user) if err != nil { diff --git a/api/v1/bot/bot.go b/api/v1/bot/bot.go index 6c6f8b4..3e40c41 100644 --- a/api/v1/bot/bot.go +++ b/api/v1/bot/bot.go @@ -5,6 +5,7 @@ import ( "git.echol.cn/loser/lckt/model/bot" botReq "git.echol.cn/loser/lckt/model/bot/request" "git.echol.cn/loser/lckt/model/common/response" + "git.echol.cn/loser/lckt/utils" "github.com/gin-gonic/gin" "go.uber.org/zap" ) @@ -191,3 +192,22 @@ func (btApi *BotApi) FindKey(c *gin.Context) { response.OkWithDetailed(bt, "获取成功", c) } + +// BulkBot 批量创建机器人 +func (btApi *BotApi) BulkBot(c *gin.Context) { + var p botReq.BulkBot + if err := c.ShouldBind(&p); err != nil { + response.FailWithMessage(err.Error(), c) + return + } + + name := utils.GetUserName(c) + + err := btService.BulkBot(p, name) + if err != nil { + global.GVA_LOG.Error("批量创建失败!", zap.Error(err)) + response.FailWithMessage("批量创建失败:"+err.Error(), c) + return + } + response.OkWithMessage("批量创建成功", c) +} diff --git a/model/bot/request/bot.go b/model/bot/request/bot.go index ddd1aad..ade4b94 100644 --- a/model/bot/request/bot.go +++ b/model/bot/request/bot.go @@ -14,3 +14,7 @@ type BotSearch struct { type FindKey struct { KeyWord string `json:"keyWord" form:"keyWord"` } + +type BulkBot struct { + Files []string `json:"files" form:"files" binding:"required"` +} diff --git a/model/common/response/response.go b/model/common/response/response.go index d5ba72d..dd06b38 100644 --- a/model/common/response/response.go +++ b/model/common/response/response.go @@ -61,3 +61,12 @@ func NoAuth(message string, c *gin.Context) { func FailWithDetailed(data interface{}, message string, c *gin.Context) { Result(ERROR, data, message, c) } + +// Banned 被封禁 +func Banned(message string, c *gin.Context) { + c.JSON(403, Response{ + 4, + nil, + message, + }) +} diff --git a/router/bot/bot.go b/router/bot/bot.go index af0c60b..e7f9028 100644 --- a/router/bot/bot.go +++ b/router/bot/bot.go @@ -17,6 +17,7 @@ func (s *BotRouter) InitBotRouter(Router *gin.RouterGroup, PublicRouter *gin.Rou btRouter.DELETE("deleteBot", btApi.DeleteBot) // 删除机器人 btRouter.DELETE("deleteBotByIds", btApi.DeleteBotByIds) // 批量删除机器人 btRouter.PUT("updateBot", btApi.UpdateBot) // 更新机器人 + btRouter.POST("bulkBot", btApi.BulkBot) // 机器人批量操作 } { btRouterWithoutRecord.GET("findBot", btApi.FindBot) // 根据ID获取机器人 diff --git a/service/bot/bot.go b/service/bot/bot.go index 8e2fb35..1ccf930 100644 --- a/service/bot/bot.go +++ b/service/bot/bot.go @@ -5,6 +5,7 @@ import ( "git.echol.cn/loser/lckt/global" "git.echol.cn/loser/lckt/model/bot" botReq "git.echol.cn/loser/lckt/model/bot/request" + "go.uber.org/zap" "gorm.io/gorm" "strings" ) @@ -165,3 +166,33 @@ func (btService *BotService) generateKeywordVariants(input string) []string { return result } + +func (btService *BotService) BulkBot(p botReq.BulkBot, userName string) (err error) { + var bots []bot.Bot + + for _, a := range p.Files { + content := "