123456789101112131415161718192021222324252627282930 |
- package services
- import (
- "github.com/jinzhu/gorm"
- "lzyd-message-api/common"
- "lzyd-message-api/models"
- )
- func GetChatroom(db *gorm.DB, roomId string) *models.Chatroom {
- var chatroom models.Chatroom
- db.Where("room_id = ?", roomId).Find(&chatroom)
- return &chatroom
- }
- func GetChatroomUser(db *gorm.DB, roomId int64, userId string) *models.ChatroomUser {
- var model models.ChatroomUser
- db.Where("room_id = ?", roomId).Where("user_id = ?", userId).Order("join_time DESC").First(&model)
- return &model
- }
- func UserInRoom(creatorId string, bCreatorId string) *models.UsersInRoom {
- var user models.UsersInRoom
- sql := `select room_id from lzyd_live_chatroom where creator_id = ? && b_creator_id=? || creator_id = ? && b_creator_id=?`
- common.DB.Raw(sql, creatorId,bCreatorId,bCreatorId,creatorId).First(&user)
- //fmt.Println(222,user,creatorId,bCreatorId)
- if len(user.RoomId) <= 0 {
- return nil
- }
- return &user
- }
|