蛋蛋星球-客户端
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.
 
 
 
 
 

79 lines
2.3 KiB

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