chatroom.go 920 B

123456789101112131415161718192021222324252627282930
  1. package services
  2. import (
  3. "github.com/jinzhu/gorm"
  4. "lzyd-message-api/common"
  5. "lzyd-message-api/models"
  6. )
  7. func GetChatroom(db *gorm.DB, roomId string) *models.Chatroom {
  8. var chatroom models.Chatroom
  9. db.Where("room_id = ?", roomId).Find(&chatroom)
  10. return &chatroom
  11. }
  12. func GetChatroomUser(db *gorm.DB, roomId int64, userId string) *models.ChatroomUser {
  13. var model models.ChatroomUser
  14. db.Where("room_id = ?", roomId).Where("user_id = ?", userId).Order("join_time DESC").First(&model)
  15. return &model
  16. }
  17. func UserInRoom(creatorId string, bCreatorId string) *models.UsersInRoom {
  18. var user models.UsersInRoom
  19. sql := `select room_id from lzyd_live_chatroom where creator_id = ? && b_creator_id=? || creator_id = ? && b_creator_id=?`
  20. common.DB.Raw(sql, creatorId,bCreatorId,bCreatorId,creatorId).First(&user)
  21. //fmt.Println(222,user,creatorId,bCreatorId)
  22. if len(user.RoomId) <= 0 {
  23. return nil
  24. }
  25. return &user
  26. }