蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_comment.go 1.9 KiB

2 weeks ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/svc"
  5. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  6. "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  8. "context"
  9. "errors"
  10. "github.com/gin-gonic/gin"
  11. "github.com/olivere/elastic/v7"
  12. "time"
  13. )
  14. func IsCanComment(c *gin.Context) (isCan bool, err error) {
  15. user := svc.GetUser(c)
  16. //1、检测是否已实名
  17. eggFriendCircleBasicDb := implement.NewEggFriendCircleBasicDb(db.Db)
  18. eggFriendCircleBasic, err := eggFriendCircleBasicDb.EggFriendCircleBasicGet()
  19. if err != nil {
  20. return
  21. }
  22. if eggFriendCircleBasic.CommentIsRealName == 1 && user.IsRealName == 0 {
  23. err = errors.New("当前未实名~")
  24. return
  25. }
  26. //2、检测是否在黑名单中
  27. eggFriendCircleUserBlackListDb := implement.NewEggFriendCircleUserBlackListDb(db.Db)
  28. eggFriendCircleUserBlackList, err := eggFriendCircleUserBlackListDb.EggFriendCircleUserBlackListGet(user.Id)
  29. if err != nil {
  30. return
  31. }
  32. if eggFriendCircleUserBlackList != nil {
  33. err = errors.New("已被拉入黑名单~")
  34. return
  35. }
  36. //3、检测是否已达次数
  37. now := time.Now()
  38. startOfDay := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()).Format("2006-01-02 15:04:05")
  39. 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")
  40. query := elastic.NewBoolQuery().
  41. Must(
  42. elastic.NewTermQuery("uid", user.Id),
  43. elastic.NewRangeQuery("created_at").Gte(startOfDay).Lt(endOfDay), // 根据你的索引结构调整字段名
  44. )
  45. searchResult, err := es.EsClient.Search().Index(md.EggFriendCircleCommentEsAlias).
  46. Query(query).
  47. Size(0). // 只关心总数,不实际返回文档
  48. Do(context.Background())
  49. if err != nil {
  50. return
  51. }
  52. total := searchResult.TotalHits()
  53. if int(total) >= eggFriendCircleBasic.CommentNumsEveryDay {
  54. err = errors.New("今日朋友圈发布数量已达上限~")
  55. return
  56. }
  57. return
  58. }