123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package yb_community_question_comment
- import (
- "hongze/hongze_yb/global"
- "hongze/hongze_yb/utils"
- )
- func GetByCommunityQuestionCommentId(communityQuestionCommentId uint64) (item *YbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Where("community_question_comment_id = ? ", communityQuestionCommentId).First(&item).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetListByUserIdCommunityQuestionID(userId uint64, communityQuestionID, source int) (list []*YbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Where("user_id = ? AND community_question_id = ? AND enabled = 1 AND source = ?", userId, communityQuestionID, source).
- Order("create_time desc, community_question_comment_id desc").
- Scan(&list).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetListTotalByUserIdCommunityQuestionID(userId uint64, communityQuestionID, source int) (total int64, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Where("user_id = ? AND community_question_id = ? AND enabled = 1 AND source = ?", userId, communityQuestionID, source).
- Count(&total).Error
- return
- }
- func GetHotListByCommunityQuestionID(communityQuestionID int, offset, limit, source int) (list []*YbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Where("community_question_id = ? AND enabled = 1 AND type = 1 AND source = ?", communityQuestionID, source).
-
- Order("create_time DESC").
- Offset(offset).
- Limit(limit).
- Scan(&list).Error
- return
- }
- func GetHotListTotalByCommunityQuestionID(communityQuestionID, source int) (total int64, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Where("community_question_id = ? AND enabled = 1 AND type = 1 AND source = ?", communityQuestionID, source).
- Count(&total).Error
- return
- }
- func GetReplyListByReplyCommentId(replyCommentIds []uint64) (list []*YbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Where("enabled = 1 and type = 2 and reply_comment_id in ?", replyCommentIds).
- Order("community_question_comment_id asc").
- Scan(&list).Error
- return
- }
- type SimpleYbCommunityQuestionComment struct {
- CommunityQuestionCommentID uint64 `gorm:"primaryKey;column:community_question_comment_id;type:bigint(20) unsigned;not null" json:"-"`
- UserID uint64 `gorm:"column:user_id;type:bigint(20) unsigned;not null;default:0" json:"userId"`
- Type int8 `gorm:"column:type;type:tinyint(1);not null;default:1" json:"type"`
- Enabled int8 `gorm:"column:enabled;type:tinyint(1);not null;default:1" json:"enabled"`
- }
- func GetSimpleByCommentId(commentId uint64) (item *SimpleYbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Select("community_question_comment_id, user_id, type, enabled").
- Where("community_question_comment_id = ?", commentId).First(&item).Error
- if err == utils.ErrNoRow {
- err = nil
- }
- return
- }
- func GetMyLatestComment(userId uint64) (item *YbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Select("comment_id, user_id, type, enabled, is_show_name").
- Where("user_id = ? and type=1", userId).Order("community_question_comment_id desc").First(&item).Error
- return
- }
- type NumCommentByCommunityQuestion struct {
- CommunityQuestionID uint32 `json:"community_question_id"`
- Total int `json:"total"`
- }
- func GetNumCommentByCommunityQuestionIds(communityQuestionIds []uint32, userId uint64) (item []*NumCommentByCommunityQuestion, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Select("community_question_id, count(1) total").
- Where("community_question_id in (?) and type=1 and enabled = 1 and (is_hot = 1 or user_id=?) ", communityQuestionIds, userId).Group("community_question_id").Scan(&item).Error
- return
- }
- func GetLastHotListByCommunityQuestionIds(communityQuestionIds []uint32) (items []*YbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Where("community_question_comment_id in (SELECT MAX(community_question_comment_id) AS community_question_comment_id FROM yb_community_question_comment WHERE community_question_id IN (?) AND enabled = 1 AND is_hot = 1 AND type = 1 GROUP BY community_question_id)", communityQuestionIds).
- Find(&items).Error
- return
- }
- func GetLastMyListByCommunityQuestionIds(userId uint64, communityQuestionIds []uint32) (items []*YbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Where("community_question_comment_id in (SELECT MAX(community_question_comment_id) AS community_question_comment_id FROM yb_community_question_comment WHERE user_id=? AND community_question_id IN (?) AND enabled = 1 AND type = 1 GROUP BY community_question_id)", userId, communityQuestionIds).
- Find(&items).Error
- return
- }
- type UserAvatarRandom struct {
- AvatarUrl string
- }
- func GetUserAvatarRandom() (item *UserAvatarRandom, err error) {
- sql := ` select * from user_avatar_random order by rand() limit 1 `
- err = global.DEFAULT_MYSQL.Raw(sql).Scan(&item).Error
- return
- }
- func GetHotListByCommunityQuestionIds(communityQuestionIds []uint32, source int) (items []*YbCommunityQuestionComment, err error) {
- err = global.DEFAULT_MYSQL.Model(YbCommunityQuestionComment{}).
- Where("community_question_id IN (?) AND enabled = 1 AND type = 1 AND source = ?", communityQuestionIds, source).
- Order("hot_time DESC").
- Find(&items).Error
- return
- }
|