xingzai 10 ヶ月 前
コミット
116902e86a

+ 4 - 4
controllers/yanxuan_special.go

@@ -2,7 +2,6 @@ package controllers
 
 import (
 	"encoding/json"
-	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_mfyx/models"
 	"hongze/hongze_mfyx/services"
@@ -1457,7 +1456,7 @@ func (this *YanxuanSpecialController) Like() {
 		br.ErrMsg = "操作失败,Err:" + err.Error()
 		return
 	}
-	fmt.Println("total", total)
+	var msgContent string
 	if doType == 1 {
 		if total == 0 {
 			item := new(models.CygxYanxuanSpecialSpecialLike)
@@ -1478,6 +1477,7 @@ func (this *YanxuanSpecialController) Like() {
 				return
 			}
 		}
+		msgContent = "已点赞"
 	} else {
 		if total > 0 {
 			err = models.DeleteCygxYanxuanSpecialSpecialLike(userId, yanxuanSpecialId, yanxuanSpecialBySpeciaDetail.UserId)
@@ -1487,11 +1487,11 @@ func (this *YanxuanSpecialController) Like() {
 				return
 			}
 		}
+		msgContent = "已取消点赞"
 	}
-
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "操作成功"
+	br.Msg = msgContent
 }
 
 // @Title 作者粉丝列表

+ 31 - 4
controllers/yanxuan_special_message.go

@@ -296,9 +296,30 @@ func (this *YanxuanSpecialMessageController) MessageTop() {
 
 	messageId := req.MessageId
 	doType := req.DoType
+
+	messagerDetail, err := models.GetCygxYanxuanSpecialMessagerDetailById(messageId)
+	if err != nil {
+		br.Msg = "操作失败!"
+		br.ErrMsg = "操作失败,Err:" + err.Error()
+	}
+	yanxuanSpecialId := messagerDetail.YanxuanSpecialId
 	var topTime int
+	var msgContent string
 	if doType == 1 {
+		countTop, err := models.GetCygxYanxuanSpecialMessagerCountTop(yanxuanSpecialId)
+		if err != nil {
+			br.Msg = "操作失败!"
+			br.ErrMsg = "操作失败,Err:" + err.Error()
+			return
+		}
+		if countTop > 0 {
+			br.Msg = "此文章已有置顶留言"
+			return
+		}
 		topTime = int(time.Now().Unix())
+		msgContent = "已置顶"
+	} else {
+		msgContent = "已取消置顶"
 	}
 	err = models.UpdateCygxYanxuanSpecialMessageTopTime(topTime, messageId)
 	if err != nil {
@@ -308,7 +329,7 @@ func (this *YanxuanSpecialMessageController) MessageTop() {
 	}
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "操作成功"
+	br.Msg = msgContent
 }
 
 // @Title 公开/取消公开留言
@@ -341,9 +362,13 @@ func (this *YanxuanSpecialMessageController) MessagePublic() {
 	doType := req.DoType
 	var status int
 	var publicTime string
+	var msgContent string
 	if doType == 1 {
 		status = 1
 		publicTime = time.Now().Format(utils.FormatDateTime)
+		msgContent = "已公开"
+	} else {
+		msgContent = "已取消公开"
 	}
 
 	err = models.UpdateCygxYanxuanSpecialMessageStatus(status, publicTime, messageIds)
@@ -354,7 +379,7 @@ func (this *YanxuanSpecialMessageController) MessagePublic() {
 	}
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "操作成功"
+	br.Msg = msgContent
 }
 
 // @Title 点赞/取消点赞
@@ -393,7 +418,7 @@ func (this *YanxuanSpecialMessageController) MessageLike() {
 		br.ErrMsg = "操作失败,Err:" + err.Error()
 		return
 	}
-
+	var msgContent string
 	if doType == 1 {
 		if total == 0 {
 			item := new(models.CygxYanxuanSpecialMessageLike)
@@ -414,6 +439,7 @@ func (this *YanxuanSpecialMessageController) MessageLike() {
 				return
 			}
 		}
+		msgContent = "已点赞"
 	} else {
 		if total > 0 {
 			err = models.DeleteCygxYanxuanSpecialMessageLike(userId, messageId)
@@ -423,11 +449,12 @@ func (this *YanxuanSpecialMessageController) MessageLike() {
 				return
 			}
 		}
+		msgContent = "已取消点赞"
 	}
 
 	br.Ret = 200
 	br.Success = true
-	br.Msg = "操作成功"
+	br.Msg = msgContent
 }
 
 // @Title 专栏文章留言列表

+ 9 - 1
models/cygx_yanxuan_special_message.go

@@ -79,7 +79,7 @@ func UpdateCygxYanxuanSpecialMessageTopTime(topTime, messageId int) (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 IN (` + utils.GetOrmInReplace(len(messageIds)) + `)  OR  parent_id   IN (` + utils.GetOrmInReplace(len(messageIds)) + `) `
+	sql = `UPDATE cygx_yanxuan_special_message SET  top_time = 0 ,  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
 }
@@ -111,6 +111,14 @@ func GetCygxYanxuanSpecialMessagerCount(condition string, pars []interface{}) (c
 	return
 }
 
+// 获取置顶留言数量数量
+func GetCygxYanxuanSpecialMessagerCountTop(yanxuanSpecialId int) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_yanxuan_special_message WHERE   top_time  > 0 AND yanxuan_special_id = ?  `
+	err = o.Raw(sqlCount, yanxuanSpecialId).QueryRow(&count)
+	return
+}
+
 // 获取留言公开数量
 func GetCygxYanxuanSpecialMessagerPublicCount(yanxuanSpecialId int) (count int, err error) {
 	o := orm.NewOrm()