Browse Source

update

master
dengbiao 1 day ago
parent
commit
f9244325ce
12 changed files with 743 additions and 12 deletions
  1. +13
    -0
      app/db/im/model/friend.go
  2. +168
    -0
      app/hdl/friend_circle/hdl_comment.go
  3. +189
    -0
      app/hdl/friend_circle/hdl_friend_circle.go
  4. +0
    -0
      app/md/comm/md_comm.go
  5. +11
    -0
      app/md/friend_circles/md_comment.go
  6. +49
    -0
      app/md/friend_circles/md_friend_circle.go
  7. +32
    -5
      app/router/router.go
  8. +62
    -0
      app/svc/friend_circle/svc_comment.go
  9. +204
    -0
      app/svc/friend_circle/svc_firend_circle.go
  10. +0
    -4
      app/svc/svc_auth.go
  11. +12
    -0
      app/svc/svc_im.go
  12. +3
    -3
      go.mod

+ 13
- 0
app/db/im/model/friend.go View File

@@ -0,0 +1,13 @@
package model

// Friend 好友
type Friend struct {
Id int64
UserId int64
FriendId int64
Remarks string
Extra string
Status int
CreateTime string
UpdateTime string
}

+ 168
- 0
app/hdl/friend_circle/hdl_comment.go View File

@@ -0,0 +1,168 @@
package friend_circle

import (
"applet/app/e"
"applet/app/md/friend_circles"
"applet/app/svc"
svc2 "applet/app/svc/friend_circle"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
svc3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc"
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"time"
)

// IsCanComment
// @Summary 朋友圈-是否可以评论
// @Tags 朋友圈
// @Description 是否可以评论
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Success 200 {string} "许可链接"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/circleFriends/isCanComment [Get]
func IsCanComment(c *gin.Context) {
isCan, err := svc2.IsCanComment(c)
if err != nil {
fmt.Println("IsCanComment:::::", err.Error())
}
resp := friend_circles.IsCanCommentResp{IsCan: isCan}
e.OutSuc(c, resp, nil)
}

// Comment
// @Summary 朋友圈-评论
// @Tags 朋友圈
// @Description 是否可以评论
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Success 200 {string} "许可链接"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/circleFriends/comment [Get]
func Comment(c *gin.Context) {
var req *friend_circles.CommentReq
if err1 := c.ShouldBindJSON(&req); err1 != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
return
}
isCan, err := svc2.IsCanComment(c)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
if !isCan {
e.OutErr(c, e.ERR, "当前不允许评论!")
return
}

//查找朋友圈记录
doc, err := es.FirstDoc(md.EggFriendCircleEsIndex, req.CircleIndexId)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if !doc.Found { // 表示没找到数据
e.OutErr(c, e.ERR_NOT_FAN, "朋友圈文档记录不存在")
return
}
var circle md.EggFriendCircleEs
err = json.Unmarshal(doc.Source, &circle)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}

//查找评论记录
var comment md.EggFriendCircleCommentEs
if req.CommentIndexId != "" {
doc1, err1 := es.FirstDoc(md.EggFriendCircleCommentEsAlias, req.CircleIndexId)
if err1 != nil {
e.OutErr(c, e.ERR_DB_ORM, err1.Error())
return
}
if !doc1.Found { // 表示没找到数据
e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在")
return
}
err = json.Unmarshal(doc1.Source, &comment)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
}

//新增es记录
user := svc.GetUser(c)
now := time.Now()
imUser, err1 := svc.GetImUser(0, user.Phone)
if err1 != nil {
e.OutErr(c, e.ERR, err1.Error())
return
}
var commentId, replyCommentId string
if &comment != nil {
if comment.CommentId != "" {
replyCommentId = req.CommentIndexId
} else {
commentId = req.CommentIndexId
}
}
createDocRet, err := es.CreateDoc(svc3.GetEggFriendCircleCommentEsIndex(user.Id), svc3.GetEggFriendCircleCommentEsIndexId(user.Id, req.CircleIndexId), md.EggFriendCircleCommentEs{
Uid: user.Id,
ImUid: imUser.UserId,
Kind: 1,
CircleId: req.CircleIndexId,
CommentId: commentId,
ReplyCommentId: replyCommentId,
Content: req.Content,
LikesNums: 0,
CommentNums: 0,
State: 1,
IsPraise: 2,
CreatedAt: now.Format("2006-01-02 15:04:05"),
UpdatedAt: now.Format("2006-01-02 15:04:05"),
})

fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}

//更新朋友圈&&评论记录
_, err = es.UpdateDoc(md.EggFriendCircleEsIndex, req.CircleIndexId, map[string]interface{}{
"comment_nums": circle.CommentNums + 1,
})
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
if &comment != nil {
_, err = es.UpdateDoc(md.EggFriendCircleCommentEsAlias, req.CommentIndexId, map[string]interface{}{
"comment_nums": comment.CommentNums + 1,
})
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
}

e.OutSuc(c, "success", nil)
}

func CommentDelete(c *gin.Context) {
e.OutSuc(c, "success", nil)
}
func CommentShare(c *gin.Context) {
e.OutSuc(c, "success", nil)
}
func CommentLike(c *gin.Context) {
e.OutSuc(c, "success", nil)
}
func CommentCancelLike(c *gin.Context) {
e.OutSuc(c, "success", nil)
}

+ 189
- 0
app/hdl/friend_circle/hdl_friend_circle.go View File

@@ -0,0 +1,189 @@
package friend_circle

import (
"applet/app/e"
"applet/app/md/friend_circles"
"applet/app/svc"
svc2 "applet/app/svc/friend_circle"
"applet/app/utils"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
"time"
)

// MySelfList
// @Summary 通用请求-对象存储-上传许可链接(获取)
// @Tags 对象存储
// @Description 上传许可链接(获取)
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param req body friend_circles.MySelfListReq true "签名上传url"
// @Success 200 {object} friend_circles.MySelfListResp "返回数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/comm/getOssUrl [POST]
func MySelfList(c *gin.Context) {
var args friend_circles.MySelfListReq
err := c.ShouldBindJSON(&args)
if err != nil {
err = svc.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
resp, err := svc2.MySelfList(c, args)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
e.OutSuc(c, resp, nil)
}

// IsCanPublish
// @Summary 朋友圈-是否可以发布朋友圈
// @Tags 朋友圈
// @Description 是否可以发布朋友圈
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Success 200 {string} "success"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/circleFriends/isCanPublish [GET]
func IsCanPublish(c *gin.Context) {
isCan, err := svc2.IsCanPublish(c)
if err != nil {
fmt.Println("IsPublish:::::", err.Error())
}
resp := friend_circles.IsCanCommentResp{IsCan: isCan}
e.OutSuc(c, resp, nil)
}

// Publish
// @Summary 朋友圈-发布朋友圈
// @Tags 朋友圈
// @Description 发布朋友圈
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param req body comm.PublishReq true "请求参数"
// @Success 200 {string} "success"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/circleFriends/public [POST]
func Publish(c *gin.Context) {
var req *friend_circles.PublishReq
if err1 := c.ShouldBindJSON(&req); err1 != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
return
}
isCan, err := svc2.IsCanPublish(c)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
if !isCan {
e.OutErr(c, e.ERR, "当前不允许发朋友圈")
return
}

//插入es记录
user := svc.GetUser(c)
now := time.Now()
createDocRet, err := es.CreateDoc(md.EggFriendCircleEsIndex, strconv.FormatInt(user.Id, 10)+"_"+utils.Int64ToStr(now.Unix()), md.EggFriendCircleEs{
Uid: user.Id,
Kind: 1,
Content: req.Content,
Image: utils.SerializeStr(req.ImageList),
Video: req.Video,
LikesNums: 0,
ShareNums: 0,
CommentNums: 0,
State: 0,
IsTopUp: 0,
CreatedAt: now.Format("2006-01-02 15:04:05"),
UpdatedAt: now.Format("2006-01-02 15:04:05"),
})

fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
e.OutSuc(c, "success", nil)
}

// CommentList
// @Summary 朋友圈-评论列表
// @Tags 朋友圈
// @Description 评论列表
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param circle_index_id query string true "朋友圈文档记录"
// @Success 200 {string} "success"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/circleFriends/commentList [GET]
func CommentList(c *gin.Context) {
circleIndexId := c.DefaultQuery("circle_index_id", "")
//查找朋友圈记录
doc, err := es.FirstDoc(md.EggFriendCircleEsIndex, circleIndexId)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if !doc.Found { // 表示没找到数据
e.OutErr(c, e.ERR_NOT_FAN, "朋友圈文档记录不存在")
return
}

resp, err := svc2.CommentList(circleIndexId)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
e.OutSuc(c, resp, nil)
}

// CommentDetail
// @Summary 朋友圈-评论详情
// @Tags 朋友圈
// @Description 评论详情
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param comment_index_id query string true "评论文档记录"
// @Success 200 {string} "success"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/circleFriends/commentDetail [GET]
func CommentDetail(c *gin.Context) {
commentIndexId := c.DefaultQuery("comment_index_id", "")

//查找评论记录
doc1, err1 := es.FirstDoc(md.EggFriendCircleCommentEsAlias, commentIndexId)
if err1 != nil {
e.OutErr(c, e.ERR_DB_ORM, err1.Error())
return
}
if !doc1.Found { // 表示没找到数据
e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在")
return
}

resp, err := svc2.CommentDetail(commentIndexId)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}
e.OutSuc(c, resp, nil)
}

func Delete(c *gin.Context) {
e.OutSuc(c, "success", nil)
}
func Share(c *gin.Context) {
e.OutSuc(c, "success", nil)
}
func Like(c *gin.Context) {
e.OutSuc(c, "success", nil)
}
func CancelLike(c *gin.Context) {
e.OutSuc(c, "success", nil)
}

app/md/comm/hdl_comm.go → app/md/comm/md_comm.go View File


+ 11
- 0
app/md/friend_circles/md_comment.go View File

@@ -0,0 +1,11 @@
package friend_circles

type IsCanCommentResp struct {
IsCan bool `json:"is_can"`
}

type CommentReq struct {
CircleIndexId string `json:"circle_index_id" example:"朋友圈文档记录"`
CommentIndexId string `json:"comment_index_id" example:"评论文档记录"`
Content string `json:"content,required"` // 文本内容
}

+ 49
- 0
app/md/friend_circles/md_friend_circle.go View File

@@ -0,0 +1,49 @@
package friend_circles

import "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"

type PublishReq struct {
Content string `json:"content,required"` // 文本内容
ImageList []string `json:"image_list"` // 图片
Video string `json:"video"` // 视屏
}
type MySelfListReq struct {
Page int `json:"page"` // 页码
PageSize int `json:"page_size"` // 每页数量
}
type MySelfListResp struct {
Page int `json:"page"` // 页码
PageSize int `json:"page_size"` // 每页数量
Total int64 `json:"total"` // 总量
List []md.EggFriendCircleEs `json:"list"`
}
type CommentListResp struct {
CircleIndexId string `json:"circle_index_id"`
Total int64 `json:"total"` // 总评论数量
List []EggFriendCircleCommentEsStruct `json:"list"`
}

type CommentDetailResp struct {
CircleIndexId string `json:"circle_index_id"`
Total int64 `json:"total"` // 总评论数量
List []EggFriendCircleCommentEsStruct `json:"list"`
}

type EggFriendCircleCommentEsStruct struct {
NickName string `json:"nickname"`
AvatarUrl string `json:"avatar_url"` // 用户头像
Uid int64 `json:"uid" label:"uid"`
ImUid int64 `json:"im_uid" label:"im_uid"`
Kind int32 `json:"kind" label:"类型(1:普通 2:官方)"`
CircleId int64 `json:"circle_id" label:"朋友圈id"`
CommentId int64 `json:"comment_id" label:"评论id"`
ReplyCommentNickname int64 `json:"reply_comment_nickname" label:"回复评论的用户昵称"`
ReplyCommentId int64 `json:"reply_comment_id" label:"回复评论id"`
Content string `json:"content" label:"文本内容"`
LikesNums int `json:"likes_nums" label:"点赞数"`
CommentNums int `json:"comment_nums" label:"评论数"`
State int32 `json:"state" label:"状态(1:正常 2:隐藏)"`
IsPraise int32 `json:"is_praise" label:"是否被表扬(1:是 2:否)"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}

+ 32
- 5
app/router/router.go View File

@@ -4,6 +4,7 @@ import (
"applet/app/cfg"
"applet/app/hdl"
"applet/app/hdl/comm"
"applet/app/hdl/friend_circle"
"applet/app/mw"
_ "applet/docs"
"github.com/gin-gonic/gin"
@@ -84,13 +85,9 @@ func route(r *gin.RouterGroup) {

r.GET("/getModuleSetting", hdl.GetModuleSetting) // 获取页面样式
r.Use(mw.Auth) // 以下接口需要JWT验证
rCircleFriends(r.Group("/circleFriends"))
rComm(r.Group("/comm"))

{
r.POST("/advertising/check", hdl.AdvertisingCheck) //广告位判断能不能看
r.POST("/advertising/state", hdl.AdvertisingState) //广告位状态
}

rHomePage := r.Group("/homePage")
{
rHomePage.GET("/index", hdl.HomePage) // 主页
@@ -99,6 +96,7 @@ func route(r *gin.RouterGroup) {
rHomePage.GET("/isCanSignIn", hdl.IsCanSignIn) // 主页-是否可以观看广告
rHomePage.GET("/isCanGetRedPackage", hdl.IsCanGetRedPackage) // 主页-是否可以获得红包
}

rAddFriend := r.Group("/addFriend")
{
rAddFriend.POST("/eggEnergyDetails", hdl.EggEnergyDetails) // 添加好友-蛋蛋能量明细
@@ -165,6 +163,7 @@ func route(r *gin.RouterGroup) {
{
rNewUserRedPacket.GET("/index", hdl.NewUserRedPacketInfo)
}

rIm := r.Group("/im")
{
rIm.POST("/user/sendRedPackage", hdl.SendRedPackage) // IM-发送红包
@@ -172,6 +171,7 @@ func route(r *gin.RouterGroup) {
rIm.POST("/user/grabRedPackage", hdl.GrabRedPackage) // IM-领取红包
rIm.GET("/redPackageDetail", hdl.RedPackageDetail) // IM-红包详情
}

rFaceRealName := r.Group("/faceRealName") // 实名认证
{
rFaceRealName.GET("/base", hdl.GetRealNameAuthBase) //实名认证基础
@@ -179,7 +179,34 @@ func route(r *gin.RouterGroup) {
}
}

func rCircleFriends(r *gin.RouterGroup) {
r.POST("/mySelfList", friend_circle.MySelfList) // 我的朋友圈列表
r.POST("/recommendList", friend_circle.Publish) // 推荐列表
r.GET("/commentList", friend_circle.CommentList) // 朋友圈详情列表
r.GET("/commentDetail", friend_circle.CommentDetail) // 评论详情
r.POST("/publish", friend_circle.Publish) // 发送朋友圈
r.GET("/isCanPublish", friend_circle.IsCanPublish) // 是否可以发朋友圈

r.DELETE("/delete", friend_circle.Delete) // 删除朋友圈
r.POST("/like", friend_circle.Like) // 点赞
r.POST("/cancelLike", friend_circle.CancelLike) // 取消点赞
r.POST("/share", friend_circle.Share) // 分享

r.POST("/comment", friend_circle.Comment) // 评论
r.GET("/isCanComment", friend_circle.IsCanComment) // 是否可以评论
r.DELETE("/commentDelete", friend_circle.CommentDelete) // 删除评论
r.POST("/commentLike", friend_circle.CommentLike) // 点赞评论
r.POST("/commentCancelLike", friend_circle.CommentCancelLike) // 取消点赞评论
r.POST("/commentShare", friend_circle.CommentShare) // 分享评论
}

func rComm(r *gin.RouterGroup) {
rCommAdvertising := r.Group("/advertising")
{
rCommAdvertising.POST("/advertising/check", hdl.AdvertisingCheck) //广告位判断能不能看
rCommAdvertising.POST("/advertising/state", hdl.AdvertisingState) //广告位状态
}

r.POST("/getOssUrl", comm.GetOssUrl) // 获取阿里云上传PutObject所需的签名URL
r.GET("/accessRecords", comm.AccessRecords) // 访问记录
}

+ 62
- 0
app/svc/friend_circle/svc_comment.go View File

@@ -0,0 +1,62 @@
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
}

+ 204
- 0
app/svc/friend_circle/svc_firend_circle.go View File

@@ -0,0 +1,204 @@
package svc

import (
"applet/app/db"
"applet/app/db/im/model"
"applet/app/md/friend_circles"
"applet/app/svc"
"applet/app/utils/logx"
"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"
"encoding/json"
"errors"
"github.com/gin-gonic/gin"
"github.com/olivere/elastic/v7"
"time"
)

func IsCanPublish(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.PublishIsRealName == 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.EggFriendCircleEsIndex).
Query(query).
Size(0). // 只关心总数,不实际返回文档
Do(context.Background())
if err != nil {
return
}
total := searchResult.TotalHits()
if int(total) >= eggFriendCircleBasic.PublishNumsEveryDay {
err = errors.New("今日朋友圈发布数量已达上限~")
return
}
return
}

func MySelfList(c *gin.Context, req friend_circles.MySelfListReq) (resp friend_circles.MySelfListResp, err error) {
user := svc.GetUser(c)

//获取当前用户在im中的user_id
var friends []*model.Friend
err = db.DbIm.Where("`phone_number`=?", user.Phone).Limit(5000).Find(&friends)
if err != nil {
return
}
var friendIDs []interface{}
for _, v := range friends {
friendIDs = append(friendIDs, v.FriendId)
}
// 分页参数
from := (req.Page - 1) * req.PageSize

// 构建查询
query := elastic.NewBoolQuery()
query.Must(elastic.NewTermsQuery("im_uid", friendIDs...))
query.Must(elastic.NewTermQuery("state", "1"))

searchResult, err := es.EsClient.Search().
Index(md.EggFriendCircleEsIndex). // 替换为你的索引名称
Query(query).
Sort("create_at", false). // 按时间倒排
From(from).
Size(req.PageSize).
Pretty(true).
Do(context.Background())
if err != nil {
logx.Fatalf("Error searching for documents: %v", err)
return
}

// 检查是否有结果
if searchResult.Hits.TotalHits.Value == 0 {
return
}

// 解析结果
for _, hit := range searchResult.Hits.Hits {
var doc md.EggFriendCircleEs
err = json.Unmarshal(hit.Source, &doc)
if err != nil {
return
}
resp.List = append(resp.List, doc)
}

resp.Total = searchResult.TotalHits()
return
}

func CommentList(circleIndexId string) (resp friend_circles.CommentListResp, err error) {
// 查询所有评论
query := elastic.NewBoolQuery()
query.Must(elastic.NewTermQuery("circle_id", circleIndexId))
query.Must(elastic.NewTermQuery("state", "1"))

searchResult, err := es.EsClient.Search().
Index(md.EggFriendCircleCommentEsAlias). // 替换为你的索引名称
Query(query).
Sort("create_at", false). // 按时间倒排
Pretty(true).
Do(context.Background())
if err != nil {
logx.Fatalf("Error searching for documents: %v", err)
return
}

// 检查是否有结果
if searchResult.Hits.TotalHits.Value == 0 {
return
}

// 解析结果
for _, hit := range searchResult.Hits.Hits {
var doc friend_circles.EggFriendCircleCommentEsStruct
err = json.Unmarshal(hit.Source, &doc)
if err != nil {
return
}
user, err1 := svc.GetImUser(doc.ImUid, "")
if err1 != nil {
return friend_circles.CommentListResp{}, err1
}
doc.NickName = user.Nickname
doc.AvatarUrl = user.AvatarUrl
resp.List = append(resp.List, doc)
}

resp.Total = searchResult.TotalHits()
return
}

func CommentDetail(commentIndexId string) (resp friend_circles.CommentDetailResp, err error) {
// 查询所有评论
query := elastic.NewBoolQuery()
query.Must(elastic.NewTermQuery("comment_id", commentIndexId))
query.Must(elastic.NewTermQuery("state", "1"))

searchResult, err := es.EsClient.Search().
Index(md.EggFriendCircleCommentEsAlias). // 替换为你的索引名称
Query(query).
Sort("create_at", false). // 按时间倒排
Pretty(true).
Do(context.Background())
if err != nil {
logx.Fatalf("Error searching for documents: %v", err)
return
}

// 检查是否有结果
if searchResult.Hits.TotalHits.Value == 0 {
return
}

// 解析结果
for _, hit := range searchResult.Hits.Hits {
var doc friend_circles.EggFriendCircleCommentEsStruct
err = json.Unmarshal(hit.Source, &doc)
if err != nil {
return
}
user, err1 := svc.GetImUser(doc.ImUid, "")
if err1 != nil {
return friend_circles.CommentDetailResp{}, err1
}

doc.NickName = user.Nickname
doc.AvatarUrl = user.AvatarUrl
resp.List = append(resp.List, doc)
}

resp.Total = searchResult.TotalHits()
return
}

+ 0
- 4
app/svc/svc_auth.go View File

@@ -69,10 +69,6 @@ func CheckUser(c *gin.Context) (user *model.User, newToken string, err error) {
if err != nil {
return user, newToken, err
}
userInfo, err = userInfoProvider.GetUserInfo(mc.Uid)
if err != nil {
return user, newToken, err
}

// 4、检验账号是否未激活或被冻结
if userInfo.State == int(enum.UserStateForFreeze) {


+ 12
- 0
app/svc/svc_im.go View File

@@ -365,3 +365,15 @@ func BalancePayForRedPackage(user *model.User, money string, req md.SendRedPacka
redPackageId = redPackageOrdId
return resp, redPackageId, nil
}

// GetImUser 获取im用户信息
func GetImUser(userId int64, phone string) (user *pb.User, err error) {
resp, err := utils.GetBusinessExtClient(cfg.ImBusinessRpc.URL, cfg.ImBusinessRpc.PORT).GetUser(utils.GetCtx("", "", ""), &pb.GetUserReq{
UserId: userId,
Phone: phone,
})
if err != nil {
return
}
return resp.User, nil
}

+ 3
- 3
go.mod View File

@@ -3,7 +3,7 @@ module applet
go 1.19

//replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models
//
//replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules

require (
@@ -32,8 +32,8 @@ require (
)

require (
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241202092326-afaf570d445a
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241202080915-050246e21702
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241203152302-b6aa8333c67e
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241203152001-32c4b96d6029
code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible


Loading…
Cancel
Save