|
@@ -5,12 +5,12 @@ import (
|
|
|
"fmt"
|
|
|
"hongze/hongze_yb/global"
|
|
|
"hongze/hongze_yb/models/response"
|
|
|
- "hongze/hongze_yb/models/tables/yb_community_question_like_roast"
|
|
|
+ "hongze/hongze_yb/models/tables/yb_community_question_like_tease"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-// SetLikeOrRoast 用户对问答进行(取消)点赞或(取消)吐槽
|
|
|
-func SetLikeOrRoast(userId uint64, communityQuestionId uint32, opType, enable, sourceAgent int8) (ybCommunityQuestionLikeRoast *yb_community_question_like_roast.YbCommunityQuestionLikeRoast, likeNum, roastNum int64, err error, errMsg string) {
|
|
|
+// SetLikeOrTease 用户对问答进行(取消)点赞或(取消)吐槽
|
|
|
+func SetLikeOrTease(userId uint64, communityQuestionId uint32, opType, enable, sourceAgent int8) (ybCommunityQuestionLikeTease *yb_community_question_like_tease.YbCommunityQuestionLikeTease, likeNum, teaseNum int64, err error, errMsg string) {
|
|
|
//user.UserID
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -33,16 +33,16 @@ func SetLikeOrRoast(userId uint64, communityQuestionId uint32, opType, enable, s
|
|
|
//}
|
|
|
|
|
|
//查询用户对问答的点赞/吐槽状态
|
|
|
- ybCommunityQuestionLikeRoast, err = yb_community_question_like_roast.GetByUserIdAndCommunityQuestionId(userId, communityQuestionId)
|
|
|
+ ybCommunityQuestionLikeTease, err = yb_community_question_like_tease.GetByUserIdAndCommunityQuestionId(userId, communityQuestionId)
|
|
|
if err != nil {
|
|
|
errMsg = "查询点赞/吐槽记录出错"
|
|
|
return
|
|
|
}
|
|
|
//如果未点赞则新增点赞记录
|
|
|
now := time.Now()
|
|
|
- if ybCommunityQuestionLikeRoast.CommunityQuestionLikeRoastID <= 0 {
|
|
|
- ybCommunityQuestionLikeRoast = &yb_community_question_like_roast.YbCommunityQuestionLikeRoast{
|
|
|
- //CommunityQuestionLikeRoastID: 0,
|
|
|
+ if ybCommunityQuestionLikeTease.CommunityQuestionLikeTeaseID <= 0 {
|
|
|
+ ybCommunityQuestionLikeTease = &yb_community_question_like_tease.YbCommunityQuestionLikeTease{
|
|
|
+ //CommunityQuestionLikeTeaseID: 0,
|
|
|
UserID: userId,
|
|
|
OpType: opType,
|
|
|
Enabled: 1,
|
|
@@ -51,30 +51,30 @@ func SetLikeOrRoast(userId uint64, communityQuestionId uint32, opType, enable, s
|
|
|
CommunityQuestionID: communityQuestionId,
|
|
|
SourceAgent: sourceAgent,
|
|
|
}
|
|
|
- err = ybCommunityQuestionLikeRoast.Create()
|
|
|
+ err = ybCommunityQuestionLikeTease.Create()
|
|
|
if err != nil {
|
|
|
errMsg = err.Error()
|
|
|
err = errors.New("新增点赞/吐槽记录出错")
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
- ybCommunityQuestionLikeRoast.OpType = opType
|
|
|
- ybCommunityQuestionLikeRoast.Enabled = enable
|
|
|
- ybCommunityQuestionLikeRoast.ModifyTime = now
|
|
|
+ ybCommunityQuestionLikeTease.OpType = opType
|
|
|
+ ybCommunityQuestionLikeTease.Enabled = enable
|
|
|
+ ybCommunityQuestionLikeTease.ModifyTime = now
|
|
|
updates := []string{"op_type", "enabled", "modify_time"}
|
|
|
- err = ybCommunityQuestionLikeRoast.Update(updates)
|
|
|
+ err = ybCommunityQuestionLikeTease.Update(updates)
|
|
|
if err != nil {
|
|
|
errMsg = "更新点赞记录出错"
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
//查询总的点赞数
|
|
|
- likeNum, err = yb_community_question_like_roast.GetLikeNumByCommunityQuestionId(communityQuestionId)
|
|
|
+ likeNum, err = yb_community_question_like_tease.GetLikeNumByCommunityQuestionId(communityQuestionId)
|
|
|
if err != nil {
|
|
|
errMsg = err.Error()
|
|
|
err = errors.New("查询点赞数出错")
|
|
|
}
|
|
|
- roastNum, err = yb_community_question_like_roast.GetRoastNumByCommunityQuestionId(communityQuestionId)
|
|
|
+ teaseNum, err = yb_community_question_like_tease.GetTeaseNumByCommunityQuestionId(communityQuestionId)
|
|
|
if err != nil {
|
|
|
errMsg = err.Error()
|
|
|
err = errors.New("查询吐槽数出错")
|
|
@@ -82,8 +82,8 @@ func SetLikeOrRoast(userId uint64, communityQuestionId uint32, opType, enable, s
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-// HandleLikeOrRoastByCommunityQuestionItemList 问答 点赞/吐槽 数据
|
|
|
-func HandleLikeOrRoastByCommunityQuestionItemList(userId uint64, questionList []*response.CommunityQuestionItem) (err error) {
|
|
|
+// HandleLikeOrTeaseByCommunityQuestionItemList 问答 点赞/吐槽 数据
|
|
|
+func HandleLikeOrTeaseByCommunityQuestionItemList(userId uint64, questionList []*response.CommunityQuestionItem) (err error) {
|
|
|
listLen := len(questionList)
|
|
|
if listLen == 0 {
|
|
|
return
|
|
@@ -94,20 +94,20 @@ func HandleLikeOrRoastByCommunityQuestionItemList(userId uint64, questionList []
|
|
|
}
|
|
|
|
|
|
// 获取点赞和吐槽数据
|
|
|
- ybCommunityQuestionLikeRoastMap := make(map[uint32]*yb_community_question_like_roast.YbCommunityQuestionLikeRoast)
|
|
|
- ybCommunityQuestionLikeRoastList, err := yb_community_question_like_roast.GetByUserIdAndCommunityQuestionIds(userId, idArr)
|
|
|
+ ybCommunityQuestionLikeTeaseMap := make(map[uint32]*yb_community_question_like_tease.YbCommunityQuestionLikeTease)
|
|
|
+ ybCommunityQuestionLikeTeaseList, err := yb_community_question_like_tease.GetByUserIdAndCommunityQuestionIds(userId, idArr)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- for _, v := range ybCommunityQuestionLikeRoastList {
|
|
|
- ybCommunityQuestionLikeRoastMap[v.CommunityQuestionID] = v
|
|
|
+ for _, v := range ybCommunityQuestionLikeTeaseList {
|
|
|
+ ybCommunityQuestionLikeTeaseMap[v.CommunityQuestionID] = v
|
|
|
}
|
|
|
|
|
|
// 获取点赞和吐槽汇总数
|
|
|
likeMap := make(map[uint32]int)
|
|
|
- roastMap := make(map[uint32]int)
|
|
|
+ teaseMap := make(map[uint32]int)
|
|
|
|
|
|
- likeList, err := yb_community_question_like_roast.GetLikeNumCommentByCommunityQuestionIds(idArr)
|
|
|
+ likeList, err := yb_community_question_like_tease.GetLikeNumCommentByCommunityQuestionIds(idArr)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -115,29 +115,29 @@ func HandleLikeOrRoastByCommunityQuestionItemList(userId uint64, questionList []
|
|
|
likeMap[v.CommunityQuestionID] = v.Total
|
|
|
}
|
|
|
|
|
|
- roastList, err := yb_community_question_like_roast.GetRoastNumCommentByCommunityQuestionIds(idArr)
|
|
|
+ teaseList, err := yb_community_question_like_tease.GetTeaseNumCommentByCommunityQuestionIds(idArr)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
- for _, v := range roastList {
|
|
|
- roastMap[v.CommunityQuestionID] = v.Total
|
|
|
+ for _, v := range teaseList {
|
|
|
+ teaseMap[v.CommunityQuestionID] = v.Total
|
|
|
}
|
|
|
|
|
|
for _, v := range questionList {
|
|
|
if tmpTotal, ok := likeMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
v.LikeTotal = tmpTotal
|
|
|
}
|
|
|
- if tmpTotal, ok := roastMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
- v.RoastTotal = tmpTotal
|
|
|
+ if tmpTotal, ok := teaseMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
+ v.TeaseTotal = tmpTotal
|
|
|
}
|
|
|
|
|
|
- if ybCommunityQuestionLikeRoast, ok := ybCommunityQuestionLikeRoastMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
- switch ybCommunityQuestionLikeRoast.OpType {
|
|
|
+ if ybCommunityQuestionLikeTease, ok := ybCommunityQuestionLikeTeaseMap[uint32(v.CommunityQuestionID)]; ok {
|
|
|
+ switch ybCommunityQuestionLikeTease.OpType {
|
|
|
//类型. 1-点赞 2-吐槽
|
|
|
case 1:
|
|
|
v.IsLike = true
|
|
|
case 2:
|
|
|
- v.IsRoast = true
|
|
|
+ v.IsTease = true
|
|
|
}
|
|
|
}
|
|
|
}
|