123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package yb_community_question_like_tease
- import (
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/utils"
- )
- // GetByUserIdAndCommunityQuestionId 根据用户和问答id获取点赞/吐槽记录
- func GetByUserIdAndCommunityQuestionId(userId uint64, communityQuestionId uint32) (item *YbCommunityQuestionLikeTease, err error) {
- err = global.DEFAULT_MYSQL.
- Where("user_id = ? AND community_question_id = ?", userId, communityQuestionId).
- First(&item).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- // GetLikeNumByCommunityQuestionId 获取某个问答的点赞数
- func GetLikeNumByCommunityQuestionId(communityQuestionId uint32) (num int64, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionLikeTease{}).
- Where(" community_question_id = ? AND enabled=1 AND op_type = 1 ", communityQuestionId).
- Count(&num).Error
- return
- }
- // GetTeaseNumByCommunityQuestionId 获取某个问答的吐槽数
- func GetTeaseNumByCommunityQuestionId(communityQuestionId uint32) (num int64, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionLikeTease{}).
- Where(" community_question_id = ? AND enabled=1 AND op_type = 2 ", communityQuestionId).
- 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(YbCommunityQuestionLikeTease{}).
- Select("community_question_id, count(1) total").
- Where("community_question_id in (?) AND enabled=1 AND op_type=1", communityQuestionIds).Group("community_question_id").Scan(&items).Error
- return
- }
- // GetTeaseNumCommentByCommunityQuestionIds 根据问答id列表获取所有问答的吐槽数
- func GetTeaseNumCommentByCommunityQuestionIds(communityQuestionIds []uint32) (items []*NumCommentByCommunityQuestionIds, err error) {
- if len(communityQuestionIds) <= 0 {
- return
- }
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionLikeTease{}).
- Select("community_question_id, count(1) total").
- Where("community_question_id in (?) AND enabled=1 AND op_type=2", communityQuestionIds).Group("community_question_id").Scan(&items).Error
- return
- }
- // GetByUserIdAndCommunityQuestionIds 根据用户id和问答id列表获取成功点赞/吐槽记录
- func GetByUserIdAndCommunityQuestionIds(userId uint64, communityQuestionIds []uint32) (items []*YbCommunityQuestionLikeTease, err error) {
- if len(communityQuestionIds) <= 0 {
- return
- }
- err = global.DEFAULT_MYSQL.
- Where("user_id = ? AND enabled=1 AND community_question_id in (?)", userId, communityQuestionIds).Group("community_question_id").
- Find(&items).Error
- return
- }
|