room.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package v1
  2. import (
  3. "context"
  4. v1pb "go-common/app/interface/live/app-ucenter/api/http/v1"
  5. "go-common/app/interface/live/app-ucenter/conf"
  6. "go-common/app/interface/live/app-ucenter/dao"
  7. "go-common/library/ecode"
  8. "go-common/library/net/metadata"
  9. "go-common/library/sync/errgroup"
  10. )
  11. // RoomService struct
  12. type RoomService struct {
  13. conf *conf.Config
  14. // optionally add other properties here, such as dao
  15. dao *dao.Dao
  16. }
  17. //NewRoomService init
  18. func NewRoomService(c *conf.Config) (s *RoomService) {
  19. s = &RoomService{
  20. conf: c,
  21. dao: dao.New(c),
  22. }
  23. return s
  24. }
  25. // GetInfo implementation
  26. // 获取房间基本信息
  27. // `method:"GET" midware:"auth"`
  28. func (s *RoomService) GetInfo(ctx context.Context, req *v1pb.GetRoomInfoReq) (resp *v1pb.GetRoomInfoResp, err error) {
  29. uid, ok := metadata.Value(ctx, metadata.Mid).(int64)
  30. if uid <= 0 || !ok {
  31. err = ecode.UidError
  32. return
  33. }
  34. uidArr := make([]int64, 0)
  35. uidArr = append(uidArr, uid)
  36. resp = &v1pb.GetRoomInfoResp{}
  37. resp.Uid = uid
  38. resp.FullText = "V等级5级或UP等级10级才能开通粉丝勋章哦~加油!"
  39. resp.OpenMedalLevel = dao.OpenFansMealLevel
  40. resp.MaxLevel = 40
  41. eg := errgroup.Group{}
  42. eg.Go(func() (err error) {
  43. room, err := s.dao.GetRoomInfosByUids(ctx, uidArr)
  44. if err != nil {
  45. err = ecode.CallRoomError
  46. return
  47. }
  48. roomInfo := room[uid]
  49. if roomInfo == nil {
  50. return
  51. }
  52. LockStatus := 0
  53. //if roomInfo.LockTill >= dao.PERMANENT_LOCK_TIME {
  54. // LockStatus = 1
  55. //}
  56. resp.RoomId = roomInfo.RoomId
  57. resp.Title = roomInfo.Title
  58. resp.LiveStatus = roomInfo.LiveStatus
  59. resp.AreaV2Id = roomInfo.AreaV2Id
  60. resp.AreaV2Name = roomInfo.AreaV2Name
  61. resp.LockTime = roomInfo.LockTill
  62. resp.LockStatus = int64(LockStatus)
  63. resp.ParentId = roomInfo.AreaV2ParentId
  64. resp.ParentName = roomInfo.AreaV2ParentName
  65. return
  66. })
  67. eg.Go(func() (err error) {
  68. user, err := s.dao.GetUserInfo(ctx, uidArr)
  69. if err != nil {
  70. err = ecode.CallUserError
  71. return
  72. }
  73. if user == nil {
  74. err = ecode.UserNotFound
  75. return
  76. }
  77. userInfo, ok := user[uid]
  78. if !ok {
  79. err = ecode.UserNotFound
  80. return
  81. }
  82. resp.Face = userInfo.GetInfo().GetFace()
  83. resp.Uname = userInfo.GetInfo().GetUname()
  84. if userInfo.Exp != nil {
  85. resp.MasterScore = userInfo.Exp.Rcost / 100
  86. if userInfo.Exp.MasterLevel != nil {
  87. masterLevel := userInfo.Exp.MasterLevel.Level
  88. masterNextLevel := masterLevel + 1
  89. if masterNextLevel > 40 {
  90. masterNextLevel = 40
  91. }
  92. resp.MasterLevel = masterLevel
  93. resp.MasterLevelColor = userInfo.Exp.MasterLevel.Color
  94. resp.MasterNextLevel = masterNextLevel
  95. if len(userInfo.Exp.MasterLevel.Next) >= 2 {
  96. resp.MasterNextLevelScore = userInfo.Exp.MasterLevel.Next[1]
  97. }
  98. }
  99. }
  100. return
  101. })
  102. eg.Go(func() (err error) {
  103. relation, err := s.dao.GetUserFc(ctx, uid)
  104. if err != nil {
  105. err = ecode.CallRelationError
  106. return
  107. }
  108. resp.FcNum = relation.Fc
  109. return
  110. })
  111. eg.Go(func() (err error) {
  112. fansMedal, err := s.dao.GetFansMedalInfo(ctx, uid)
  113. if err != nil {
  114. err = ecode.CallFansMedalError
  115. return
  116. }
  117. if fansMedal == nil {
  118. return
  119. }
  120. resp.IsMedal = fansMedal.MasterStatus
  121. resp.MedalName = fansMedal.MedalName
  122. resp.MedalRenameStatus = fansMedal.RenameStatus
  123. resp.MedalStatus = fansMedal.Status
  124. return
  125. })
  126. eg.Go(func() (err error) {
  127. identifyStatus, err := s.dao.GetIdentityStatus(ctx, uid)
  128. if err != nil {
  129. err = ecode.CallMainMemberError
  130. return
  131. }
  132. resp.IdentifyStatus = int64(identifyStatus)
  133. return
  134. })
  135. err = eg.Wait()
  136. return
  137. }
  138. // Create implementation
  139. // 创建房间
  140. // `method:"POST" midware:"auth"`
  141. func (s *RoomService) Create(ctx context.Context, req *v1pb.CreateReq) (resp *v1pb.CreateResp, err error) {
  142. uid, ok := metadata.Value(ctx, metadata.Mid).(int64)
  143. if uid <= 0 || !ok {
  144. err = ecode.UidError
  145. return
  146. }
  147. resp = &v1pb.CreateResp{}
  148. room, err := s.dao.CreateRoom(ctx, uid)
  149. if err != nil {
  150. err = ecode.CallRoomError
  151. return
  152. }
  153. resp.RoomId = room.Roomid
  154. return
  155. }