Compare commits

..

2 Commits

Author SHA1 Message Date
JNG
b1e1d317ed 添加ip获取位置 2026-03-13 09:56:15 +08:00
JNG
469b0313ce 添加ip获取位置 2026-03-13 09:53:34 +08:00
8 changed files with 107 additions and 111 deletions

View File

@ -64,7 +64,6 @@ func MediaRouter(r *gin.RouterGroup) {
script.POST("update", serviceCast.UpdateVideoScript)
script.POST("detail", serviceCast.VideoScriptDetail)
script.POST("list", serviceCast.ListVideoScripts)
script.POST("export-excel", serviceCast.VideoScripExportExcel)
script.POST("import-batch", serviceCast.ImportBatch)
script.POST("update-approval", serviceCast.UpdateScriptApproval)
script.POST("delete", serviceCast.DeleteVideoScript)

View File

@ -77,7 +77,6 @@ func NewRouter() *gin.Engine {
privateGroup.POST("generate/captcha", account.GenerateCaptcha) //生成滑块验证码
privateGroup.POST("validate/captcha", account.ValidateCaptcha) //验证滑块验证码
privateGroup.POST("check/register", account.CheckRegister) //校验是否注册
privateGroup.GET("get/ip", account.GetIP)
acRoute := privateGroup.Group("/user")
acRoute.Use(middleware.CheckLogin(service.AccountFieeProvider))
{

View File

@ -577,10 +577,6 @@ func CheckRegister(c *gin.Context) {
service.Success(c, res)
return
}
func GetIP(c *gin.Context) {
ip := c.ClientIP()
service.Success(c, ip)
}
func UserLogout(c *gin.Context) {
req := account.DecryptJwtRequest{}
req.Token = c.GetHeader(e.Authorization)

View File

@ -65,15 +65,21 @@ func QuestionnaireSurveyCreate(c *gin.Context) {
service.Error(c, err)
return
}
if req.Longitude == "" || req.Latitude == "" {
service.Error(c, errors.New("获取定位失败"))
return
}
address, err := utils.ReverseGeo(req.Longitude, req.Latitude, "ZhCN")
ip := c.ClientIP()
address, err := utils.GetAddressByIP(ip)
if err != nil {
service.Error(c, errors.New("获取地址失败"))
return
}
//if req.Longitude == "" || req.Latitude == "" {
// service.Error(c, errors.New("获取定位失败"))
// return
//}
//address, err := utils.ReverseGeo(req.Longitude, req.Latitude, "ZhCN")
//if err != nil {
// service.Error(c, errors.New("获取地址失败"))
// return
//}
surveyInfo, err := service.BundleProvider.GetQuestionnaireSurveyInfo(c, &bundle.GetQuestionnaireSurveyInfoRequest{UserTel: req.UserTel})
if err != nil {
service.Error(c, err)

View File

@ -124,50 +124,6 @@ func ListVideoScripts(ctx *gin.Context) {
return
}
var videoScripMap = map[uint32]string{1: "草稿", 2: "审核中", 3: "审核通过", 4: "审核不通过"}
func VideoScripExportExcel(ctx *gin.Context) {
var req *cast.ListVideoScriptsReq
var err error
if err = ctx.ShouldBind(&req); err != nil {
service.Error(ctx, err)
return
}
newCtx := NewCtxWithUserInfo(ctx)
resp, err := service.CastProvider.ListVideoScripts(newCtx, req)
if err != nil {
service.Error(ctx, err)
return
}
titleList := []string{
"用户编号", "艺人", "艺人手机号", "引用次数", "状态", "脚本标题", "脚本内容", "创建人", "创建时间",
}
var dataList []interface{}
for _, task := range resp.Data {
data := []interface{}{
task.ArtistName,
task.ArtistName,
task.ArtistPhone,
task.QuoteCount,
videoScripMap[task.Status],
task.Title,
task.Content,
task.CreatorName,
task.CreatedDate,
}
dataList = append(dataList, &data)
}
content, err := utils.ToExcelByType(titleList, dataList, "slice", "")
if err != nil {
service.Error(ctx, errors.New("生成excel失败"))
}
utils.ResponseXls(ctx, content, fmt.Sprintf("视频脚本_%s.xlsx", time.Now().Format(time.DateTime)))
return
}
// DeleteVideoScript 删除视频脚本
func DeleteVideoScript(ctx *gin.Context) {
var req *cast.DeleteVideoScriptReq

View File

@ -1513,10 +1513,6 @@ func GetBalanceLayout(ctx *gin.Context) {
service.Success(ctx, j)
}
var (
EnableSecurityCheck = true //是否打开批量导入图文
)
func ImportWorkBatch(ctx *gin.Context) {
excelFile, err := ctx.FormFile("file")
var (
@ -1588,7 +1584,6 @@ func ImportWorkBatch(ctx *gin.Context) {
Source: 3,
}
var artistNum string
//检测艺人编号
if len(row) > 1 && utils.CleanString(row[1]) != "" {
artistNum = utils.CleanString(row[1])
artistSubNum := utils.CleanString(row[1])
@ -1610,6 +1605,7 @@ func ImportWorkBatch(ctx *gin.Context) {
Domain: "app",
})
//}
if err != nil {
temp.Remark = fmt.Sprintf("自媒体用户查询失败:%s", err.Error())
zap.L().Error("AccountFieeProvider.SubNumGetInfo", zap.Error(err))
@ -1628,37 +1624,43 @@ func ImportWorkBatch(ctx *gin.Context) {
temp.ArtistPhoneAreaCode = subInfoResp.TelAreaCode
temp.ArtistSubNum = subInfoResp.SubNum
}
//检测标题
if len(row) > 7 {
temp.Title = utils.CleanString(row[7])
// 检查并截取 title 长度(支持中文)
titleRunes := []rune(temp.Title)
if len(titleRunes) > 600 {
temp.Title = string(titleRunes[:600])
}
if EnableSecurityCheck {
_err := SecurityText(temp.Title)
if _err != nil {
temp.Remark = "标题黄反审核未通过"
req.ImageWorks = append(req.ImageWorks, temp)
break
}
ok, _err := check.SecurityText(temp.Title)
if _err != nil {
temp.Remark = _err.Error()
req.ImageWorks = append(req.ImageWorks, temp)
break
}
if !ok {
temp.Remark = "标题黄反审核未通过"
req.ImageWorks = append(req.ImageWorks, temp)
break
}
}
//检测内容
if len(row) > 8 {
temp.Content = utils.CleanString(row[8])
if temp.Content != "" {
// 检查并截取 content 长度(支持中文)
contentRunes := []rune(temp.Content)
if len(contentRunes) > 600 {
temp.Content = string(contentRunes[:600])
}
if EnableSecurityCheck {
_err := SecurityText(temp.Title)
if _err != nil {
temp.Remark = "标题黄反审核未通过"
req.ImageWorks = append(req.ImageWorks, temp)
break
}
ok, _err := check.SecurityText(temp.Content)
if _err != nil {
temp.Remark = _err.Error()
req.ImageWorks = append(req.ImageWorks, temp)
break
}
if !ok {
temp.Remark = "内容黄反审核未通过"
req.ImageWorks = append(req.ImageWorks, temp)
break
}
// 处理内容中的标签:提取、验证并批量导入,以及自动生成标签
processedContent, err := processContentAndAutoTags(ctx, temp.Content)
@ -1671,7 +1673,6 @@ func ImportWorkBatch(ctx *gin.Context) {
temp.Content = processedContent
}
}
//检测图片
for i := 10; i <= 20; i++ {
if len(row) > i {
if utils.CleanString(row[i]) != "" {
@ -1697,7 +1698,6 @@ func ImportWorkBatch(ctx *gin.Context) {
req.ImageWorks = append(req.ImageWorks, temp)
continue
}
//检测tiktok账号
if len(row) > 2 && utils.CleanString(row[2]) != "" {
mediaInfoResp, err = service.CastProvider.MediaInfo(context.Background(), &cast.MediaInfoReq{
ArtistUuid: temp.ArtistUuid,
@ -1722,7 +1722,6 @@ func ImportWorkBatch(ctx *gin.Context) {
temp.MediaAccountNames = append(temp.MediaAccountNames, utils.CleanString(row[2]))
temp.MediaAccountUuids = append(temp.MediaAccountUuids, mediaInfoResp.Info.MediaAccountUuid)
}
//检测ins账号
if len(row) > 3 && utils.CleanString(row[3]) != "" {
mediaInfoResp, err = service.CastProvider.MediaInfo(context.Background(), &cast.MediaInfoReq{
ArtistUuid: temp.ArtistUuid,
@ -1747,7 +1746,6 @@ func ImportWorkBatch(ctx *gin.Context) {
temp.MediaAccountNames = append(temp.MediaAccountNames, utils.CleanString(row[3]))
temp.MediaAccountUuids = append(temp.MediaAccountUuids, mediaInfoResp.Info.MediaAccountUuid)
}
//检测dm账号
if len(row) > 4 && utils.CleanString(row[4]) != "" {
temp.Remark = fmt.Sprintf("DM不能发图文")
zap.L().Error("CastProvider.MediaInfo", zap.Error(err))
@ -1776,7 +1774,7 @@ func ImportWorkBatch(ctx *gin.Context) {
temp.MediaAccountNames = append(temp.MediaAccountNames, utils.CleanString(row[4]))
temp.MediaAccountUuids = append(temp.MediaAccountUuids, mediaInfoResp.Info.MediaAccountUuid)*/
}
// 检测油管账号
// YouTube账号第F列row[5]
if len(row) > 5 && utils.CleanString(row[5]) != "" {
temp.Remark = fmt.Sprintf("Youtube不能发图文")
zap.L().Error("CastProvider.MediaInfo", zap.Error(err))
@ -1805,7 +1803,7 @@ func ImportWorkBatch(ctx *gin.Context) {
// temp.MediaAccountNames = append(temp.MediaAccountNames, utils.CleanString(row[5]))
// temp.MediaAccountUuids = append(temp.MediaAccountUuids, mediaInfoResp.Info.MediaAccountUuid)
}
//检测blueSky账号
// Bluesky账号第G列row[6]
if len(row) > 6 && utils.CleanString(row[6]) != "" {
mediaInfoResp, err = service.CastProvider.MediaInfo(context.Background(), &cast.MediaInfoReq{
ArtistUuid: temp.ArtistUuid,
@ -1830,7 +1828,6 @@ func ImportWorkBatch(ctx *gin.Context) {
temp.MediaAccountNames = append(temp.MediaAccountNames, utils.CleanString(row[6]))
temp.MediaAccountUuids = append(temp.MediaAccountUuids, mediaInfoResp.Info.MediaAccountUuid)
}
//最后检测数据
if artistNum == "" {
temp.Remark = "艺人编号不能为空"
req.ImageWorks = append(req.ImageWorks, temp)

View File

@ -9,7 +9,6 @@ import (
apiCast "fonchain-fiee/api/cast"
"fonchain-fiee/pkg/config"
"fonchain-fiee/pkg/service"
"fonchain-fiee/pkg/service/cast"
"image"
"image/draw"
"image/jpeg"
@ -655,47 +654,27 @@ func downloadAndUploadToBucket(imageURL string) (string, error) {
//url := fmt.Sprintf("%s/%s", config.ConfigData.Oss.CdnHost, fileName)
func (p *BatchProcessor) generateTitleAndContent(req *excelData) (string, string, error) {
var title, content string
var err error
if req.PhotoUrl != "" {
title, content, err = NewAiGenerator().GenerateTitleAndContentFromImage(
title, content, err := NewAiGenerator().GenerateTitleAndContentFromImage(
req.PhotoUrl,
req.TitleRequire,
req.ContentRequire,
)
if err != nil {
return "", "", fmt.Errorf("图生文失败: %w", err)
return "", "", fmt.Errorf("图生文失败: %v", err)
}
return title, content, nil
} else {
title, content, err = NewAiGenerator().GenerateTitleAndContentFromText(
title, content, err := NewAiGenerator().GenerateTitleAndContentFromText(
req.TitleRequire,
req.ContentRequire,
)
if err != nil {
return "", "", fmt.Errorf("生成内容失败: %w", err)
return "", "", fmt.Errorf("生成内容失败: %v", err)
}
return title, content, nil
}
if err = p.securityCheck(title, content); err != nil {
return "", "", err
}
return title, content, nil
}
func (p *BatchProcessor) securityCheck(title, content string) error {
// 标题审核
if err := cast.SecurityText(title); err != nil {
return fmt.Errorf("标题未通过黄反,原因:%w", err)
}
// 内容审核
if err := cast.SecurityText(content); err != nil {
return fmt.Errorf("内容未通过黄反,原因:%w", err)
}
return nil
}
func (p *BatchProcessor) generateImage(req *excelData) (string, error) {

View File

@ -2,11 +2,28 @@ package utils
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)
const baiduIPLocationAPI = "https://api.map.baidu.com/location/ip"
// 建议把 ak 放配置;这里先保留你给的 key后续可改为从配置读取。
const baiduMapAK = "T8DGBYxbZ1iAeXx1J57McKigyHJHulPQ"
type baiduIPResp struct {
Status int `json:"status"`
Address string `json:"address"`
Content struct {
Address string `json:"address"`
} `json:"content"`
Message string `json:"message"`
}
type ReverseGeocodingReq struct {
Ak string `json:"ak"`
Coordtype string `json:"coordtype"`
@ -86,3 +103,50 @@ func ReverseGeo(longitude, latitude string, language string) (address string, er
return address, nil
}
func GetAddressByIP(ip string) (string, error) {
ip = strings.TrimSpace(ip)
if ip == "" {
return "", fmt.Errorf("ip is empty")
}
q := url.Values{}
q.Set("ip", ip)
q.Set("coor", "bd09ll")
q.Set("ak", baiduMapAK)
reqURL := baiduIPLocationAPI + "?" + q.Encode()
client := &http.Client{Timeout: 5 * time.Second}
resp, err := client.Get(reqURL)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("baidu api status: %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
var r baiduIPResp
if err := json.Unmarshal(body, &r); err != nil {
return "", err
}
if r.Status != 0 {
if r.Message == "" {
r.Message = "baidu api error"
}
return "", fmt.Errorf("%s", r.Message)
}
if strings.TrimSpace(r.Content.Address) != "" {
return r.Content.Address, nil
}
if strings.TrimSpace(r.Address) != "" {
return r.Address, nil
}
return "", nil
}