Browse Source

no message

xingzai 8 months ago
parent
commit
abc6bce9f2

+ 213 - 12
controllers/yanxuan_special_message.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_web_mfyx/models"
 	"hongze/hongze_web_mfyx/services"
@@ -323,7 +324,7 @@ func (this *YanxuanSpecialMessageController) MessagePublic() {
 		br.Ret = 408
 		return
 	}
-	var req models.TopCygxYanxuanSpecialMessageReq
+	var req models.PubliceCygxYanxuanSpecialMessageReq
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
 		br.Msg = "参数解析异常!"
@@ -331,7 +332,7 @@ func (this *YanxuanSpecialMessageController) MessagePublic() {
 		return
 	}
 
-	messageId := req.MessageId
+	messageIds := req.MessageIds
 	doType := req.DoType
 	var status int
 	var publicTime string
@@ -339,7 +340,8 @@ func (this *YanxuanSpecialMessageController) MessagePublic() {
 		status = 1
 		publicTime = time.Now().Format(utils.FormatDateTime)
 	}
-	err = models.UpdateCygxYanxuanSpecialMessageStatus(status, messageId, publicTime)
+
+	err = models.UpdateCygxYanxuanSpecialMessageStatus(status, publicTime, messageIds)
 	if err != nil {
 		br.Msg = "操作失败!"
 		br.ErrMsg = "操作失败,Err:" + err.Error()
@@ -350,8 +352,8 @@ func (this *YanxuanSpecialMessageController) MessagePublic() {
 	br.Msg = "操作成功"
 }
 
-// @Title 公开/取消公开留言
-// @Description 公开/取消公开留言接口
+// @Title 点赞/取消点赞
+// @Description  点赞/取消点赞接口
 // @Param	request	body models.TopCygxYanxuanSpecialMessageReq true "type json string"
 // @Success Ret=200 {object}
 // @router /message/like [post]
@@ -378,19 +380,218 @@ func (this *YanxuanSpecialMessageController) MessageLike() {
 
 	messageId := req.MessageId
 	doType := req.DoType
-	var status int
-	var publicTime string
-	if doType == 1 {
-		status = 1
-		publicTime = time.Now().Format(utils.FormatDateTime)
-	}
-	err = models.UpdateCygxYanxuanSpecialMessageStatus(status, messageId, publicTime)
+	userId := user.UserId
+
+	total, err := models.GetCygxYanxuanSpecialMessageLikeCountByUidMid(userId, messageId)
 	if err != nil {
 		br.Msg = "操作失败!"
 		br.ErrMsg = "操作失败,Err:" + err.Error()
 		return
 	}
+
+	if doType == 1 {
+		if total == 0 {
+			item := new(models.CygxYanxuanSpecialMessageLike)
+			item.UserId = userId
+			item.Mobile = user.Mobile
+			item.Email = user.Email
+			item.CompanyId = user.CompanyId
+			item.CompanyName = user.CompanyName
+			item.RealName = user.RealName
+			item.MessageId = messageId
+			item.CreateTime = time.Now()
+			item.ModifyTime = time.Now()
+			item.RegisterPlatform = utils.REGISTER_PLATFORM
+			err = models.AddCygxYanxuanSpecialMessageLike(item)
+			if err != nil {
+				br.Msg = "点赞失败!"
+				br.ErrMsg = "点赞失败,Err:" + err.Error()
+				return
+			}
+		}
+	} else {
+		if total > 0 {
+			err = models.DeleteCygxYanxuanSpecialMessageLike(userId, messageId)
+			if err != nil {
+				br.Msg = "点赞失败!"
+				br.ErrMsg = "点赞失败,Err:" + err.Error()
+				return
+			}
+		}
+	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"
 }
+
+// @Title 专栏文章留言列表
+// @Description 专栏文章留言列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   YanxuanSpecialId   query   int  false       "研选专栏文章ID"
+// @Success 200 {object} models.SpecialListResp
+// @router /message/special/list [get]
+func (this *YanxuanSpecialMessageController) MessageSpecialList() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	yanxuanSpecialId, _ := this.GetInt("YanxuanSpecialId")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	userId := user.UserId
+	resp := new(models.YanxuanSpecialMessageManageRespListResp)
+	var condition string
+	var pars []interface{}
+
+	var conditionMyself string
+	var parsMyself []interface{}
+	conditionMyself += `  AND status = 0  AND  parent_id  = 0  AND   user_id =  ? `
+	parsMyself = append(parsMyself, userId)
+
+	var listMyself []*models.CygxYanxuanSpecialMessage
+	var err error
+	if currentIndex == 1 {
+		//获取自己未公开的留言
+		listMyself, err = models.GetCygxYanxuanSpecialMessageList(conditionMyself, parsMyself, 0, 999)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败, Err:" + err.Error()
+			return
+		}
+	}
+
+	condition += `  AND status =   1 `
+	condition += ` AND yanxuan_special_id  =   ?   `
+	pars = append(pars, yanxuanSpecialId)
+	conditionChildren := condition // 子集留言筛选条件
+	condition += `  AND  parent_id  = 0 `
+	total, err := models.GetCygxYanxuanSpecialMessagerCount(condition, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+	condition += ` ORDER BY message_id DESC `
+	list, err := models.GetCygxYanxuanSpecialMessageList(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败, Err:" + err.Error()
+		return
+	}
+
+	for _, v := range list {
+		listMyself = append(listMyself, v)
+	}
+
+	if len(listMyself) > 0 {
+		var messageIds []int
+		var messageIdsAll []int // 所有的留言消息
+		var userIds []int
+		for _, v := range list {
+			messageIds = append(messageIds, v.MessageId)
+		}
+
+		for _, v := range listMyself {
+			userIds = append(userIds, v.UserId)
+
+		}
+
+		itemChildMap := make(map[int][]*models.CygxYanxuanSpecialMessageManageChildResp)
+		if len(messageIds) > 0 {
+			//获取子集评论
+			conditionChildren += `  AND  parent_id  IN (` + utils.GetOrmInReplace(len(messageIds)) + `) ORDER BY message_id	  ASC `
+			pars = append(pars, messageIds)
+			listChild, err := models.GetCygxYanxuanSpecialMessageList(conditionChildren, pars, 0, 999)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败, Err:" + err.Error()
+				return
+			}
+			for _, v := range listChild {
+				userIds = append(userIds, v.UserId)
+				messageIdsAll = append(messageIdsAll, v.MessageId)
+				itemChild := new(models.CygxYanxuanSpecialMessageManageChildResp)
+				itemChild.MessageId = v.MessageId
+				itemChild.Content = v.Content
+				itemChild.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
+				itemChildMap[v.ParentId] = append(itemChildMap[v.ParentId], itemChild)
+			}
+		}
+
+		likeMap := services.GetYanxuanSpecialMessageLikeMap(userId)
+		fmt.Println(likeMap)
+		//用户头像
+		listUser, err := models.GetWxUserListByUserIdsArr(userIds)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败, Err:" + err.Error()
+			return
+		}
+		mapUserImg := make(map[int]string)
+		for _, v := range listUser {
+			if v.Headimgurl != "" {
+				mapUserImg[v.UserId] = v.Headimgurl
+			} else {
+				mapUserImg[v.UserId] = utils.DefaultHeadimgurl
+			}
+		}
+
+		for _, v := range listMyself {
+			item := new(models.CygxYanxuanSpecialMessageManageResp)
+			item.MessageId = v.MessageId
+			item.RealName = v.RealName
+			item.Headimgurl = mapUserImg[v.UserId]
+			item.YanxuanSpecialId = v.YanxuanSpecialId
+			item.Content = v.Content
+			item.TopTime = v.TopTime
+			item.SourceTitle = v.SourceTitle
+			item.LikeCount = v.LikeCount
+			item.IsLikeCount = likeMap[v.MessageId]
+			if v.UserId == userId {
+				item.IsMySelf = true
+			}
+			item.CreateTime = v.CreateTime.Format(utils.FormatDateTime)
+			if len(itemChildMap[v.MessageId]) > 0 {
+				for _, vm := range itemChildMap[v.MessageId] {
+					vm.IsLikeCount = likeMap[vm.MessageId]
+					vm.Headimgurl = mapUserImg[vm.MessageId]
+					fmt.Println(vm.Headimgurl)
+				}
+				item.ChildList = itemChildMap[v.MessageId]
+			} else {
+				item.ChildList = make([]*models.CygxYanxuanSpecialMessageManageChildResp, 0)
+			}
+			item.CheckIds = make([]int, 0)
+			resp.List = append(resp.List, item)
+		}
+	} else {
+		resp.List = make([]*models.CygxYanxuanSpecialMessageManageResp, 0)
+	}
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp.Paging = page
+	br.Data = resp
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+}

+ 18 - 6
models/cygx_yanxuan_special_message.go

@@ -3,6 +3,7 @@ package models
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hongze_web_mfyx/utils"
 	"time"
 )
 
@@ -39,6 +40,11 @@ type DeleteCygxYanxuanSpecialMessageReq struct {
 	MessageId int `comment:"留言消息ID"`
 }
 
+type PubliceCygxYanxuanSpecialMessageReq struct {
+	MessageIds []int `comment:"留言消息ID"`
+	DoType     int   `comment:"0取消置顶,1置顶"`
+}
+
 type TopCygxYanxuanSpecialMessageReq struct {
 	MessageId int `comment:"留言消息ID"`
 	DoType    int `comment:"0取消置顶,1置顶"`
@@ -69,11 +75,11 @@ func UpdateCygxYanxuanSpecialMessageTopTime(topTime, messageId int) (err error)
 }
 
 // 更新是否公开
-func UpdateCygxYanxuanSpecialMessageStatus(status, messageId int, publicTime string) (err error) {
+func UpdateCygxYanxuanSpecialMessageStatus(status int, publicTime string, messageIds []int) (err error) {
 	o := orm.NewOrm()
 	sql := ``
-	sql = `UPDATE cygx_yanxuan_special_message SET status = ?  ,public_time = ?  WHERE message_id = ? `
-	_, err = o.Raw(sql, status, publicTime, messageId).Exec()
+	sql = `UPDATE cygx_yanxuan_special_message SET status = ?  ,public_time = ?  WHERE message_id IN (` + utils.GetOrmInReplace(len(messageIds)) + `)  OR  parent_id   IN (` + utils.GetOrmInReplace(len(messageIds)) + `) `
+	_, err = o.Raw(sql, status, publicTime, messageIds, messageIds).Exec()
 	return
 }
 
@@ -115,14 +121,20 @@ type CygxYanxuanSpecialMessageManageResp struct {
 	HaveOtherTop     bool                                        `comment:"是否有其它的置顶"`
 	SourceTitle      string                                      `comment:"专栏标题"`
 	CreateTime       string                                      `comment:"创建时间"`
+	LikeCount        int                                         `comment:"点赞数量"`
+	IsLikeCount      bool                                        `comment:"是否点赞"`
+	IsMySelf         bool                                        `comment:"是否属于本人留言"`
 	CheckIds         []int                                       `comment:"空数组前端渲染使用"`
 	ChildList        []*CygxYanxuanSpecialMessageManageChildResp // 留言子集
 }
 
 type CygxYanxuanSpecialMessageManageChildResp struct {
-	MessageId  int    `comment:"留言消息ID"`
-	Content    string `comment:"留言内容"`
-	CreateTime string `comment:"创建时间"`
+	MessageId   int    `comment:"留言消息ID"`
+	Content     string `comment:"留言内容"`
+	Headimgurl  string `comment:"用户头像"`
+	LikeCount   int    `comment:"点赞数量"`
+	IsLikeCount bool   `comment:"是否点赞"`
+	CreateTime  string `comment:"创建时间"`
 }
 
 type YanxuanSpecialMessageManageRespListResp struct {

+ 31 - 4
models/cygx_yanxuan_special_message_like.go

@@ -21,16 +21,43 @@ type CygxYanxuanSpecialMessageLike struct {
 }
 
 // 新增
-func AddCygxYanxuanSpecialMessageLike(item *CygxYanxuanSpecialMessage) (err error) {
+func AddCygxYanxuanSpecialMessageLike(item *CygxYanxuanSpecialMessageLike) (err error) {
 	o := orm.NewOrm()
 	_, err = o.Insert(item)
 	return
 }
 
+// 删除
+func DeleteCygxYanxuanSpecialMessageLike(userId, messageId int) (err error) {
+	o := orm.NewOrm()
+	sql := ` DELETE FROM cygx_yanxuan_special_message WHERE  WHERE user_id  = ? AND  message_id = ?   `
+	_, err = o.Raw(sql, userId, messageId).Exec()
+	return
+}
+
 // 获取数量
-func GetCygxYanxuanSpecialMessageLikeCountByUidMid(userId int, pars []interface{}) (count int, err error) {
+func GetCygxYanxuanSpecialMessageLikeCountByUidMid(userId, messageId int) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_message_like  WHERE user_id  = ? AND  message_id = ? `
+	err = o.Raw(sqlCount, userId, messageId).QueryRow(&count)
+	return
+}
+
+func GetCygxYanxuanSpecialMessageLikeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxYanxuanSpecialMessageLike, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT *
+			FROM
+			cygx_yanxuan_special_message_like
+			WHERE 1 = 1 ` + condition
+	sql += ` LIMIT ?,?  `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// GetCygxYanxuanSpecialMessageLikeByUser 根据用户ID获取所有点赞留言
+func GetCygxYanxuanSpecialMessageLikeByUser(userId int) (items []*CygxYanxuanSpecialMessageLike, err error) {
 	o := orm.NewOrm()
-	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_message WHERE   1= 1  `
-	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	sql := `SELECT message_id  FROM cygx_yanxuan_special_message_like  WHERE 1 =1  AND  user_id =?  `
+	_, err = o.Raw(sql, userId).QueryRows(&items)
 	return
 }

+ 1 - 0
models/db.go

@@ -99,6 +99,7 @@ func init() {
 		new(CygxYanxuanSpecialCompany),
 		new(CygxYanxuanSpecialApprovalLog),
 		new(CygxYanxuanSpecialMessage),
+		new(CygxYanxuanSpecialMessageLike),
 		new(CygxResourceData),
 		new(CygxMorningMeetingReviewChapterHistory),
 		new(CygxAskserieVideoHistoryRecord),

+ 18 - 0
routers/commentsRouter.go

@@ -1105,6 +1105,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialMessageController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialMessageController"],
+        beego.ControllerComments{
+            Method: "MessageLike",
+            Router: `/message/like`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialMessageController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialMessageController"],
         beego.ControllerComments{
             Method: "MessageManageList",
@@ -1123,6 +1132,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialMessageController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialMessageController"],
+        beego.ControllerComments{
+            Method: "MessageSpecialList",
+            Router: `/message/special/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialMessageController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:YanxuanSpecialMessageController"],
         beego.ControllerComments{
             Method: "MessageTop",

+ 24 - 0
services/cygx_yanxuan_special.go

@@ -600,3 +600,27 @@ func GetYanxuanSpecialDetailUserPower(user *models.WxUserItem) (havePower bool,
 	}
 	return
 }
+
+// GetYanxuanSpecialMessageLikeMap 根据用户ID获取所有留言点赞的信息
+func GetYanxuanSpecialMessageLikeMap(userId int) (mapResp map[int]bool) {
+	var err error
+	defer func() {
+		if err != nil {
+			//fmt.Println(err)
+			go utils.SendAlarmMsg("GetYanxuanSpecialMessageLikeMap 根据用户ID获取所有留言点赞的信息失败 ErrMsg:"+err.Error(), 2)
+
+		}
+	}()
+	list, e := models.GetCygxYanxuanSpecialMessageLikeByUser(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("根据用户ID获取所有文章收藏,GetCygxYanxuanSpecialCollectByUser " + e.Error())
+		return
+	}
+	mapResp = make(map[int]bool, 0)
+	if len(list) > 0 {
+		for _, v := range list {
+			mapResp[v.MessageId] = true
+		}
+	}
+	return
+}