🎨 机器人新增vip权限判断
This commit is contained in:
@@ -6,8 +6,10 @@ import (
|
||||
botReq "git.echol.cn/loser/lckt/model/bot/request"
|
||||
"git.echol.cn/loser/lckt/model/common/response"
|
||||
"git.echol.cn/loser/lckt/utils"
|
||||
"git.echol.cn/loser/lckt/utils/user_jwt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type BotApi struct{}
|
||||
@@ -183,7 +185,9 @@ func (btApi *BotApi) FindKey(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
bt, err := btService.GetBotPublic(req)
|
||||
userId := user_jwt.GetUserID(c)
|
||||
|
||||
bt, err := btService.GetBotPublic(req, userId)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
||||
response.FailWithMessage("获取失败:"+err.Error(), c)
|
||||
@@ -205,8 +209,9 @@ func (btApi *BotApi) BulkBot(c *gin.Context) {
|
||||
|
||||
err := btService.BulkBot(p, name)
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("批量创建失败!", zap.Error(err))
|
||||
response.FailWithMessage("批量创建失败:"+err.Error(), c)
|
||||
global.GVA_LOG.Error("批量上传失败!", zap.Error(err))
|
||||
// 只要返回部分失败的文件列表 删除前面的"部分文件上传失败: "即可
|
||||
response.FailWithDetailed(strings.TrimPrefix(err.Error(), "部分文件上传失败: "), "部分文件上传失败:"+strings.TrimPrefix(err.Error(), "部分文件上传失败: "), c)
|
||||
return
|
||||
}
|
||||
response.OkWithMessage("批量创建成功", c)
|
||||
|
@@ -2,6 +2,7 @@ package bot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.echol.cn/loser/lckt/global"
|
||||
"git.echol.cn/loser/lckt/model/bot"
|
||||
botReq "git.echol.cn/loser/lckt/model/bot/request"
|
||||
@@ -73,7 +74,24 @@ func (btService *BotService) GetBotInfoList(ctx context.Context, info botReq.Bot
|
||||
}
|
||||
|
||||
// GetBotPublic 模糊搜索公开机器人
|
||||
func (btService *BotService) GetBotPublic(keyWord botReq.FindKey) (bt bot.Bot, err error) {
|
||||
func (btService *BotService) GetBotPublic(keyWord botReq.FindKey, userId uint) (bt bot.Bot, err error) {
|
||||
// 判断用户是否为VIP或者SVIP
|
||||
var userCount int64
|
||||
if userId != 0 {
|
||||
err = global.GVA_DB.Table("app_user").Where("id = ? AND is_vip = 1", userId).Count(&userCount).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("查询用户VIP状态失败", zap.Error(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if userCount == 0 {
|
||||
text := "抱歉,该内容仅对VIP用户开放,升级VIP后即可查看完整内容。"
|
||||
// 非VIP直接返回空内容
|
||||
bt.Content = &text
|
||||
return
|
||||
}
|
||||
|
||||
userInput := strings.TrimSpace(keyWord.KeyWord)
|
||||
|
||||
// 生成用户输入的所有变体
|
||||
@@ -168,22 +186,29 @@ func (btService *BotService) generateKeywordVariants(input string) []string {
|
||||
}
|
||||
|
||||
func (btService *BotService) BulkBot(p botReq.BulkBot, userName string) (err error) {
|
||||
var bots []bot.Bot
|
||||
// 上传失败的图片
|
||||
var failFiles []string
|
||||
|
||||
for _, a := range p.Files {
|
||||
content := "<p><img src=" + a + " alt=\"" + a + "\" data-href=\"\" style=\"width: 100%;height: auto;\"/></p>"
|
||||
bots = append(bots, bot.Bot{
|
||||
bots := bot.Bot{
|
||||
Keyword: getBotKeyWorld(a),
|
||||
Content: &content,
|
||||
CreateBy: userName,
|
||||
})
|
||||
}
|
||||
|
||||
err = global.GVA_DB.Create(&bots).Error
|
||||
if err != nil {
|
||||
global.GVA_LOG.Error("创建机器人失败", zap.Error(err))
|
||||
// 记录上传失败的文件
|
||||
failFiles = append(failFiles, a)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if len(bots) > 0 {
|
||||
if dbErr := global.GVA_DB.Create(&bots).Error; dbErr != nil {
|
||||
global.GVA_LOG.Error("批量上传文章失败", zap.Error(dbErr))
|
||||
return dbErr
|
||||
}
|
||||
if len(failFiles) > 0 {
|
||||
global.GVA_LOG.Error("部分文件上传失败", zap.Strings("failedFiles", failFiles))
|
||||
return fmt.Errorf("部分文件上传失败: %v", failFiles)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user