🎨 机器人新增vip权限判断
This commit is contained in:
@@ -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