getCheckInfo.go 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. package dao
  2. import (
  3. "context"
  4. "strconv"
  5. "sync"
  6. fansMedalService "go-common/app/service/live/fans_medal/api/liverpc/v2"
  7. "go-common/app/service/live/live-dm/conf"
  8. liveUserService "go-common/app/service/live/live_user/api/liverpc/v1"
  9. roomService "go-common/app/service/live/room/api/liverpc/v2"
  10. userService "go-common/app/service/live/user/api/liverpc/v3"
  11. userextService "go-common/app/service/live/userext/api/liverpc/v1"
  12. xuserService "go-common/app/service/live/xuser/api/grpc/v1"
  13. acctountService "go-common/app/service/main/account/api"
  14. filterService "go-common/app/service/main/filter/api/grpc/v1"
  15. spyService "go-common/app/service/main/spy/api"
  16. "go-common/library/log"
  17. "github.com/pkg/errors"
  18. )
  19. //UserInfo 用户等级,经验等信息
  20. type UserInfo struct {
  21. Vip int
  22. Svip int
  23. UserLever int64
  24. UserScore int64
  25. ULevelRank int64
  26. ULevelColor int64
  27. UnameColor string
  28. RoomAdmin bool
  29. PrivilegeType int
  30. Bubble int64
  31. MedalInfo *FansMedalInfo
  32. lock sync.Mutex
  33. }
  34. //UserScore 用户真实分已经弹幕ai分
  35. type UserScore struct {
  36. UserScore int64
  37. MsgAI int64
  38. MsgLevel int64
  39. lock sync.Mutex
  40. }
  41. //DMConf 弹幕配置
  42. type DMConf struct {
  43. Mode int64
  44. Color int64
  45. Length int64
  46. }
  47. //FansMedalInfo 粉丝勋章信息
  48. type FansMedalInfo struct {
  49. MedalID int64
  50. RUID int64
  51. RUName string
  52. MedalLevel int64
  53. MedalName string
  54. AnchorName string
  55. RoomID int64
  56. MColor int64
  57. SpecialMedal string
  58. lock sync.Mutex
  59. }
  60. //RoomConf 播主房间配置信息
  61. type RoomConf struct {
  62. UID int64
  63. RoomShield int64
  64. RoomID int64
  65. Anchor string
  66. }
  67. //UserBindInfo 用户手机,实名等信息
  68. type UserBindInfo struct {
  69. Identification int32
  70. MobileVerify int32
  71. Uname string
  72. URank int32
  73. // MobileVirtual int64 无虚拟号段信息
  74. }
  75. //Get 获取用户的弹幕配置信息
  76. func (d *DMConf) Get(ctx context.Context, uid int64, roomid int64, c *conf.Config) error {
  77. req := &userextService.DanmuConfGetAllReq{
  78. Uid: uid,
  79. Roomid: roomid,
  80. }
  81. resp, err := UserExtServiceClient.V1DanmuConf.GetAll(ctx, req)
  82. if err != nil {
  83. if errors.Cause(err) != context.Canceled {
  84. log.Error("DM: userextService GetAll err: %v", err)
  85. }
  86. d.Color = 16777215
  87. d.Mode = 1
  88. d.Length = 20
  89. return nil
  90. }
  91. if resp.Code != 0 {
  92. log.Error("DM: userextService GetAll err code: %d", resp.Code)
  93. d.Color = 16777215
  94. d.Mode = 1
  95. d.Length = 20
  96. return nil
  97. }
  98. d.Color = resp.Data.Color
  99. d.Mode = resp.Data.Mode
  100. d.Length = resp.Data.Length
  101. su := strconv.FormatInt(uid, 10)
  102. if c.DmRules.Nixiang[su] {
  103. d.Mode = 6
  104. }
  105. if c.DmRules.Color[su] != 0 {
  106. d.Color = c.DmRules.Color[su]
  107. }
  108. return nil
  109. }
  110. // Get 获取用户等级,经验等信息
  111. func (u *UserInfo) Get(ctx context.Context, uid int64) error {
  112. req := &userService.UserGetUserLevelInfoReq{
  113. Uid: uid,
  114. }
  115. resp, err := userClient.V3User.GetUserLevelInfo(ctx, req)
  116. if err != nil {
  117. if errors.Cause(err) != context.Canceled {
  118. log.Error("DM: user err: %v", err)
  119. }
  120. u.lock.Lock()
  121. u.UserLever = 0
  122. u.UserScore = 0
  123. u.ULevelColor = 16752445
  124. u.lock.Unlock()
  125. return nil
  126. }
  127. if resp.Code != 0 {
  128. log.Error("DM: user GetUserLevelInfo err code: %d", resp.Code)
  129. u.lock.Lock()
  130. u.UserLever = 0
  131. u.UserScore = 0
  132. u.ULevelColor = 16752445
  133. u.lock.Unlock()
  134. return nil
  135. }
  136. u.lock.Lock()
  137. u.UserLever = resp.Data.Level
  138. u.UserScore = resp.Data.Exp
  139. u.ULevelColor = resp.Data.Color
  140. u.lock.Unlock()
  141. return nil
  142. }
  143. //GetVipInfo 获取用户的老爷等级
  144. func (u *UserInfo) GetVipInfo(ctx context.Context, uid int64) error {
  145. req := &xuserService.UidReq{
  146. Uid: uid,
  147. }
  148. resp, err := vipCli.Info(ctx, req)
  149. if err != nil {
  150. if errors.Cause(err) != context.Canceled {
  151. log.Error("DM: xuserService get vip Info err: %v", err)
  152. }
  153. u.lock.Lock()
  154. u.Vip = 0
  155. u.Svip = 0
  156. u.lock.Unlock()
  157. return nil
  158. }
  159. u.lock.Lock()
  160. u.Vip = resp.Info.Vip
  161. u.Svip = resp.Info.Svip
  162. u.lock.Unlock()
  163. return nil
  164. }
  165. //GetPrivilegeType 获取大航海信息
  166. func (u *UserInfo) GetPrivilegeType(ctx context.Context, uid int64, ruid int64) error {
  167. req := &liveUserService.GuardGetByUidTargetIdReq{
  168. Uid: uid,
  169. TargetId: ruid,
  170. IsLimitOne: 0,
  171. }
  172. resp, err := LiveUserServiceClient.V1Guard.GetByUidTargetId(ctx, req)
  173. if err != nil {
  174. if errors.Cause(err) != context.Canceled {
  175. log.Error("DM: liveUserService GetByUidTargetId err: %v", err)
  176. }
  177. u.lock.Lock()
  178. u.PrivilegeType = 0
  179. u.lock.Unlock()
  180. return nil
  181. }
  182. if resp.Code != 0 {
  183. log.Error("DM: liveUserService GetByUidTargetId err code: %d", resp.Code)
  184. u.lock.Lock()
  185. u.PrivilegeType = 0
  186. u.lock.Unlock()
  187. return nil
  188. }
  189. var PrivilegeType int64
  190. for _, val := range resp.Data {
  191. i := val.PrivilegeType
  192. if PrivilegeType == 0 {
  193. PrivilegeType = i
  194. }
  195. if PrivilegeType != 0 && PrivilegeType > i {
  196. PrivilegeType = i
  197. }
  198. }
  199. u.lock.Lock()
  200. u.PrivilegeType = int(PrivilegeType)
  201. u.lock.Unlock()
  202. return nil
  203. }
  204. //IsRoomAdmin 判断用户是否是房管
  205. func (u *UserInfo) IsRoomAdmin(ctx context.Context, uid int64, roomid int64) error {
  206. defer u.lock.Unlock()
  207. if roomid == 59125 || roomid == 5440 {
  208. u.lock.Lock()
  209. u.RoomAdmin = false
  210. return nil
  211. }
  212. req := &xuserService.RoomAdminIsAdminShortReq{
  213. Uid: uid,
  214. Roomid: roomid,
  215. }
  216. resp, err := isAdmin.IsAdminShort(ctx, req)
  217. if err != nil {
  218. log.Error("DM: xuser IsAdminShort err: %+v", err)
  219. u.lock.Lock()
  220. u.RoomAdmin = false
  221. return nil
  222. }
  223. if resp.Result == 1 {
  224. u.lock.Lock()
  225. u.RoomAdmin = true
  226. return nil
  227. }
  228. u.lock.Lock()
  229. u.RoomAdmin = false
  230. return nil
  231. }
  232. //GetFansMedal 获取主播的粉丝勋章信息
  233. func (f *FansMedalInfo) GetFansMedal(ctx context.Context, uid int64) error {
  234. req := &fansMedalService.HighQpsLiveWearedReq{
  235. Uid: uid,
  236. }
  237. resq, err := FansMedalServiceClient.V2HighQps.LiveWeared(ctx, req)
  238. if err != nil {
  239. if errors.Cause(err) != context.Canceled {
  240. log.Error("DM: fansMedalService LiveWeared err: %v", err)
  241. }
  242. f.RUID = 0
  243. f.MedalLevel = 1
  244. f.MedalName = ""
  245. f.MColor = 0
  246. return nil
  247. }
  248. if resq.Code != 0 {
  249. log.Error("DM: fansMedalService LiveWeared err code: %d", resq.Code)
  250. f.RUID = 0
  251. f.MedalLevel = 1
  252. f.MedalName = ""
  253. f.MColor = 0
  254. return nil
  255. }
  256. f.RUID = resq.Data.TargetId
  257. f.MedalLevel = resq.Data.Level
  258. f.MedalName = resq.Data.MedalName
  259. f.MColor = resq.Data.MedalColor
  260. return nil
  261. }
  262. //Get 获取主播房间配置信息s
  263. func (r *RoomConf) Get(ctx context.Context, roomID int64) error {
  264. req := &roomService.RoomGetByIdsReq{
  265. Ids: []int64{roomID},
  266. }
  267. resp, err := RoomServiceClient.V2Room.GetByIds(ctx, req)
  268. if err != nil {
  269. if errors.Cause(err) != context.Canceled {
  270. log.Error("DM: roomService GetByIds err: %v", err)
  271. }
  272. r.RoomID = roomID
  273. r.UID = 0
  274. r.RoomShield = 0
  275. r.Anchor = ""
  276. return nil
  277. }
  278. if resp.Code != 0 {
  279. log.Error("DM: roomService GetByIds err code: %d", resp.Code)
  280. r.RoomID = roomID
  281. r.UID = 0
  282. r.RoomShield = 0
  283. r.Anchor = ""
  284. return nil
  285. }
  286. if _, ok := resp.Data[roomID]; !ok {
  287. log.Error("DM: roomService GetByIds error roomid:%d", roomID)
  288. r.RoomID = roomID
  289. r.UID = 0
  290. r.RoomShield = 0
  291. r.Anchor = ""
  292. return nil
  293. }
  294. r.RoomID = resp.Data[roomID].Roomid
  295. r.UID = resp.Data[roomID].Uid
  296. r.RoomShield = resp.Data[roomID].RoomShield
  297. r.Anchor = resp.Data[roomID].Uname
  298. return nil
  299. }
  300. //Get 获取用户绑定信息,实名认知,绑定手机等信息
  301. func (u *UserBindInfo) Get(ctx context.Context, uid int64) error {
  302. req := &acctountService.MidReq{
  303. Mid: uid,
  304. }
  305. resp, err := ac.Profile3(ctx, req)
  306. if err != nil {
  307. log.Error("DM: acctountService Profile3 err: %v", err)
  308. u.Identification = 0
  309. u.MobileVerify = 0
  310. u.Uname = ""
  311. u.URank = 0
  312. return nil
  313. }
  314. u.Identification = resp.Profile.Identification
  315. u.MobileVerify = resp.Profile.TelStatus
  316. u.Uname = resp.Profile.Name
  317. u.URank = resp.Profile.Rank
  318. return nil
  319. }
  320. //GetUserScore 用户真实分
  321. func (u *UserScore) GetUserScore(ctx context.Context, uid int64) error {
  322. req := &spyService.InfoReq{
  323. Mid: uid,
  324. }
  325. resp, err := SpyClient.Info(ctx, req)
  326. if err != nil {
  327. log.Error("DM: 获取用户真实分错误 err: %v", err)
  328. u.lock.Lock()
  329. u.UserScore = 0
  330. u.lock.Unlock()
  331. return nil
  332. }
  333. u.lock.Lock()
  334. u.UserScore = int64(resp.Ui.Score)
  335. u.lock.Unlock()
  336. return nil
  337. }
  338. //GetMsgScore 获取弹幕AI分
  339. func (u *UserScore) GetMsgScore(ctx context.Context, msg string) error {
  340. req := &filterService.FilterReq{
  341. Area: "live_danmu",
  342. Message: msg,
  343. }
  344. resp, err := FilterClient.Filter(ctx, req)
  345. if err != nil {
  346. log.Error("DM: main filter err: %v", err)
  347. u.lock.Lock()
  348. u.MsgLevel = 0
  349. u.MsgAI = 0
  350. u.lock.Unlock()
  351. return nil
  352. }
  353. u.lock.Lock()
  354. u.MsgLevel = int64(resp.Level)
  355. if resp.Ai == nil {
  356. log.Error("DM: main filter err: miss ai scores")
  357. u.MsgAI = 0
  358. u.lock.Unlock()
  359. return nil
  360. }
  361. if len(resp.Ai.Scores) == 0 {
  362. u.MsgAI = 0
  363. u.lock.Unlock()
  364. return nil
  365. }
  366. u.MsgAI = int64(resp.Ai.Scores[0] * 10)
  367. u.lock.Unlock()
  368. return nil
  369. }