|
- package svc
-
- import (
- "applet/app/db"
- "applet/app/svc"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
- "context"
- "errors"
- "github.com/gin-gonic/gin"
- "github.com/olivere/elastic/v7"
- "time"
- )
-
- func IsCanComment(c *gin.Context) (isCan bool, err error) {
- user := svc.GetUser(c)
- //1、检测是否已实名
- eggFriendCircleBasicDb := implement.NewEggFriendCircleBasicDb(db.Db)
- eggFriendCircleBasic, err := eggFriendCircleBasicDb.EggFriendCircleBasicGet()
- if err != nil {
- return
- }
- if eggFriendCircleBasic.CommentIsRealName == 1 && user.IsRealName == 0 {
- err = errors.New("当前未实名~")
- return
- }
-
- //2、检测是否在黑名单中
- eggFriendCircleUserBlackListDb := implement.NewEggFriendCircleUserBlackListDb(db.Db)
- eggFriendCircleUserBlackList, err := eggFriendCircleUserBlackListDb.EggFriendCircleUserBlackListGet(user.Id)
- if err != nil {
- return
- }
- if eggFriendCircleUserBlackList != nil {
- err = errors.New("已被拉入黑名单~")
- return
- }
-
- //3、检测是否已达次数
- now := time.Now()
- startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Format("2006-01-02 15:04:05")
- endOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Add(24 * time.Hour).Format("2006-01-02 15:04:05")
- query := elastic.NewBoolQuery().
- Must(
- elastic.NewTermQuery("uid", user.Id),
- elastic.NewRangeQuery("created_at").Gte(startOfDay).Lt(endOfDay), // 根据你的索引结构调整字段名
- )
- searchResult, err := es.EsClient.Search().Index(md.EggFriendCircleCommentEsAlias).
- Query(query).
- Size(0). // 只关心总数,不实际返回文档
- Do(context.Background())
- if err != nil {
- return
- }
- total := searchResult.TotalHits()
- if int(total) >= eggFriendCircleBasic.CommentNumsEveryDay {
- err = errors.New("今日朋友圈发布数量已达上限~")
- return
- }
- return
- }
|