|
@@ -8,7 +8,7 @@ import (
|
|
|
// GetByUserIdAndCommunityQuestionId 根据用户和问答id获取点赞/吐槽记录
|
|
|
func GetByUserIdAndCommunityQuestionId(userId uint64, communityQuestionId uint32) (item *YbCommunityQuestionLikeRoast, err error) {
|
|
|
err = global.DEFAULT_MYSQL.
|
|
|
- Where("user_id = ? and community_question_id = ?", userId, communityQuestionId).
|
|
|
+ Where("user_id = ? AND community_question_id = ?", userId, communityQuestionId).
|
|
|
First(&item).Error
|
|
|
if err == utils.ErrNoRow {
|
|
|
err = nil
|
|
@@ -31,3 +31,42 @@ func GetRoastNumByCommunityQuestionId(communityQuestionId uint32) (num int64, er
|
|
|
Count(&num).Error
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// NumCommentByCommunityQuestionIds 评论统计结构体
|
|
|
+type NumCommentByCommunityQuestionIds struct {
|
|
|
+ CommunityQuestionID uint32 `json:"community_question_id"`
|
|
|
+ Total int `json:"total"`
|
|
|
+}
|
|
|
+
|
|
|
+// GetLikeNumCommentByCommunityQuestionIds 根据问答id列表获取所有问答的点赞数
|
|
|
+func GetLikeNumCommentByCommunityQuestionIds(communityQuestionIds []uint32) (items []*NumCommentByCommunityQuestionIds, err error) {
|
|
|
+ if len(communityQuestionIds) <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionLikeRoast{}).
|
|
|
+ Select("community_question_id, count(1) total").
|
|
|
+ Where("community_question_id in (?) AND enabled=1 AND op_type=1", communityQuestionIds).Scan(&items).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetRoastNumCommentByCommunityQuestionIds 根据问答id列表获取所有问答的吐槽数
|
|
|
+func GetRoastNumCommentByCommunityQuestionIds(communityQuestionIds []uint32) (items []*NumCommentByCommunityQuestionIds, err error) {
|
|
|
+ if len(communityQuestionIds) <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionLikeRoast{}).
|
|
|
+ Select("community_question_id, count(1) total").
|
|
|
+ Where("community_question_id in (?) AND enabled=1 AND op_type=2", communityQuestionIds).Scan(&items).Error
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// GetByUserIdAndCommunityQuestionIds 根据用户id和问答id列表获取成功点赞/吐槽记录
|
|
|
+func GetByUserIdAndCommunityQuestionIds(userId uint64, communityQuestionIds []uint32) (items []*YbCommunityQuestionLikeRoast, err error) {
|
|
|
+ if len(communityQuestionIds) <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = global.DEFAULT_MYSQL.
|
|
|
+ Where("user_id = ? AND enabled=1 AND community_question_id in (?)", userId, communityQuestionIds).
|
|
|
+ Find(&items).Error
|
|
|
+ return
|
|
|
+}
|