|
@@ -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 = "获取成功"
|
|
|
+}
|