getDMConf.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. package dao
  2. import (
  3. "context"
  4. activityService "go-common/app/service/live/activity/api/liverpc/v1"
  5. rankdbService "go-common/app/service/live/rankdb/api/liverpc/v1"
  6. rcService "go-common/app/service/live/rc/api/liverpc/v1"
  7. roomService "go-common/app/service/live/room/api/liverpc/v2"
  8. userextService "go-common/app/service/live/userext/api/liverpc/v1"
  9. acctountService "go-common/app/service/main/account/api"
  10. "go-common/library/log"
  11. "github.com/pkg/errors"
  12. )
  13. //CommentTitle 头衔信息
  14. type CommentTitle struct {
  15. OldTitle string `json:"oldtitle"`
  16. Title string `json:"title"`
  17. }
  18. //GetUnameColor 获取用户的昵称颜色
  19. func (u *UserInfo) GetUnameColor(ctx context.Context, uid int64, rid int64) error {
  20. req := &userextService.ColorGetUnameColorReq{
  21. Uid: uid,
  22. RoomId: rid,
  23. }
  24. resq, err := UserExtServiceClient.V1Color.GetUnameColor(ctx, req)
  25. if err != nil {
  26. if errors.Cause(err) != context.Canceled {
  27. log.Error("DM: UserExt GetUnameColor err: %v", err)
  28. }
  29. u.lock.Lock()
  30. u.UnameColor = ""
  31. u.lock.Unlock()
  32. return nil
  33. }
  34. if resq.Code != 0 {
  35. log.Error("DM: UserExt GetUnameColor errror code: %d", resq.Code)
  36. u.lock.Lock()
  37. u.UnameColor = ""
  38. u.lock.Unlock()
  39. return nil
  40. }
  41. u.lock.Lock()
  42. u.UnameColor = resq.Data.UnameColor
  43. u.lock.Unlock()
  44. return nil
  45. }
  46. //GetSpeicalMedal 获取特殊勋章
  47. func (f *FansMedalInfo) GetSpeicalMedal(ctx context.Context, uid int64, rid int64) error {
  48. //更新special
  49. req := &activityService.UnionFansGetSpecialMedalReq{
  50. Uid: uid,
  51. Ruid: rid,
  52. }
  53. resq, err := ActivityServiceClient.V1UnionFans.GetSpecialMedal(ctx, req)
  54. if err != nil {
  55. if errors.Cause(err) != context.Canceled {
  56. log.Error("DM: GetSpecialMedal err: %v", err)
  57. }
  58. f.lock.Lock()
  59. f.SpecialMedal = ""
  60. f.lock.Unlock()
  61. return nil
  62. }
  63. if resq.Code != 0 {
  64. log.Error("DM: GetSpecialMedal err code: %d", resq.Code)
  65. f.lock.Lock()
  66. f.SpecialMedal = ""
  67. f.lock.Unlock()
  68. return nil
  69. }
  70. f.lock.Lock()
  71. f.SpecialMedal = resq.Data.SpecialMedal
  72. f.lock.Unlock()
  73. return nil
  74. }
  75. //GetUserLevelRank 获取用户等级RANK
  76. func (u *UserInfo) GetUserLevelRank(ctx context.Context, uid int64) error {
  77. defer u.lock.Unlock()
  78. req := &rankdbService.UserRankGetUserRankReq{
  79. Uid: uid,
  80. Type: "user_level",
  81. }
  82. resq, err := RankdbServiceClient.V1UserRank.GetUserRank(ctx, req)
  83. if err != nil {
  84. if errors.Cause(err) != context.Canceled {
  85. log.Error("DM: GetUserRank err: %v", err)
  86. }
  87. u.lock.Lock()
  88. u.ULevelRank = 1000000
  89. return nil
  90. }
  91. if resq.Code != 0 {
  92. log.Error("DM: GetUserRank error code: %d", resq.Code)
  93. u.lock.Lock()
  94. u.ULevelRank = 1000000
  95. return nil
  96. }
  97. u.lock.Lock()
  98. u.ULevelRank = resq.Data.Rank
  99. return nil
  100. }
  101. //GetCommentTitle 获取头衔
  102. func (c *CommentTitle) GetCommentTitle(ctx context.Context) error {
  103. req := &rcService.UserTitleGetCommentTitleReq{}
  104. resq, err := RcServiceClient.V1UserTitle.GetCommentTitle(ctx, req)
  105. if err != nil {
  106. if errors.Cause(err) != context.Canceled {
  107. log.Error("DM: GetCommentTitle err: %v", err)
  108. }
  109. c.OldTitle = ""
  110. c.Title = ""
  111. return nil
  112. }
  113. if resq.Code != 0 {
  114. log.Error("DM: GetCommentTitle error code: %d", resq.Code)
  115. c.OldTitle = ""
  116. c.Title = ""
  117. return nil
  118. }
  119. if len(resq.Data) == 0 {
  120. c.OldTitle = ""
  121. c.Title = ""
  122. return nil
  123. }
  124. c.OldTitle = resq.Data[0]
  125. c.Title = resq.Data[1]
  126. return nil
  127. }
  128. //GetMedalanchorName 获取勋章对应主播的昵称
  129. func (f *FansMedalInfo) GetMedalanchorName(ctx context.Context, uid int64) error {
  130. if uid == 0 {
  131. f.RUName = ""
  132. return nil
  133. }
  134. req := &acctountService.MidReq{
  135. Mid: uid,
  136. }
  137. resp, err := ac.Profile3(ctx, req)
  138. if err != nil {
  139. log.Error("DM: acctountService Profile3 err: %v", err)
  140. f.lock.Lock()
  141. f.RUName = ""
  142. f.lock.Unlock()
  143. return nil
  144. }
  145. f.lock.Lock()
  146. f.RUName = resp.Profile.Name
  147. f.lock.Unlock()
  148. return nil
  149. }
  150. //GetMedalRoomid 获取勋章对应主播的房间
  151. func (f *FansMedalInfo) GetMedalRoomid(ctx context.Context, uid int64) error {
  152. if uid == 0 {
  153. f.lock.Lock()
  154. f.RoomID = 0
  155. f.lock.Unlock()
  156. return nil
  157. }
  158. req := &roomService.RoomRoomIdByUidReq{
  159. Uid: uid,
  160. }
  161. resp, err := RoomServiceClient.V2Room.RoomIdByUid(ctx, req)
  162. if err != nil {
  163. log.Error("DM: room RoomIdByUid err: %v", err)
  164. f.lock.Lock()
  165. f.RoomID = 0
  166. f.lock.Unlock()
  167. return nil
  168. }
  169. if resp.Code == 404 {
  170. f.lock.Lock()
  171. f.RoomID = 0
  172. f.lock.Unlock()
  173. return nil
  174. }
  175. if resp.Code != 0 {
  176. log.Error("DM: room RoomIdByUid err code: %d", resp.Code)
  177. f.lock.Lock()
  178. f.RoomID = 0
  179. f.lock.Unlock()
  180. return nil
  181. }
  182. f.lock.Lock()
  183. f.RoomID = resp.Data.RoomId
  184. f.lock.Unlock()
  185. return nil
  186. }
  187. //GetUserBubble 判断用户是否有气泡
  188. func (u *UserInfo) GetUserBubble(ctx context.Context, uid int64, roomid int64, bubble int64, guardLevel int) error {
  189. req := &userextService.BubbleGetBubbleReq{
  190. Uid: uid,
  191. RoomId: roomid,
  192. BubbleId: bubble,
  193. GuardLevel: int64(guardLevel),
  194. }
  195. defer u.lock.Unlock()
  196. resp, err := UserExtServiceClient.V1Bubble.GetBubble(ctx, req)
  197. if err != nil {
  198. if errors.Cause(err) != context.Canceled {
  199. log.Error("DM: userext Bubble check err: %v", err)
  200. }
  201. u.lock.Lock()
  202. u.Bubble = bubble
  203. return nil
  204. }
  205. if resp.Code != 0 {
  206. log.Error("DM: userext Bubble check err code: %d", resp.Code)
  207. u.lock.Lock()
  208. u.Bubble = bubble
  209. return nil
  210. }
  211. if resp.Data == nil {
  212. log.Error("DM: userext Bubble check err not data")
  213. u.lock.Lock()
  214. u.Bubble = bubble
  215. return nil
  216. }
  217. u.lock.Lock()
  218. u.Bubble = resp.Data.Bubble
  219. return nil
  220. }