roomAdmin.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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/service/live/xuser/api/grpc/v1"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. )
  11. // RoomAdminService struct
  12. type RoomAdminService struct {
  13. conf *conf.Config
  14. // optionally add other properties here, such as dao
  15. // dao *dao.Dao
  16. conn v1.RoomAdminClient
  17. }
  18. //NewRoomAdminService init
  19. func NewRoomAdminService(c *conf.Config) (s *RoomAdminService) {
  20. s = &RoomAdminService{
  21. conf: c,
  22. }
  23. conn, err := v1.NewXuserRoomAdminClient(conf.Conf.Warden)
  24. if err != nil {
  25. panic(err)
  26. }
  27. s.conn = conn
  28. return s
  29. }
  30. // History 相关服务
  31. // ShowEntry implementation
  32. // 根据登录态获取功能入口是否显示, 需要登录态
  33. // `method:"GET" midware:"auth"`
  34. func (s *RoomAdminService) ShowEntry(ctx context.Context, req *v1pb.ShowEntryReq) (resp *v1pb.ShowEntryResp, err error) {
  35. resp = &v1pb.ShowEntryResp{}
  36. mid, _ := metadata.Value(ctx, "mid").(int64)
  37. if mid <= 0 {
  38. err = ecode.NoLogin
  39. return
  40. }
  41. if err != nil {
  42. return
  43. }
  44. ret, err := s.conn.IsAny(ctx, &v1.RoomAdminShowEntryReq{
  45. Uid: mid,
  46. })
  47. log.Info("call IsAny mid(%v) ret(%v)", mid, ret)
  48. resp.HasAdmin = ret.HasAdmin
  49. return
  50. }
  51. // SearchForAdmin implementation
  52. // 查询需要添加的房管
  53. // `method:"POST" midware:"auth"`
  54. func (s *RoomAdminService) SearchForAdmin(ctx context.Context, req *v1pb.RoomAdminSearchForAdminReq) (resp *v1pb.RoomAdminSearchForAdminResp, err error) {
  55. resp = &v1pb.RoomAdminSearchForAdminResp{}
  56. mid, _ := metadata.Value(ctx, "mid").(int64)
  57. keyWord := req.GetKeyWord()
  58. if keyWord == "" {
  59. err = ecode.ParamInvalid
  60. return
  61. }
  62. ret, err := s.conn.SearchForAdmin(ctx, &v1.RoomAdminSearchForAdminReq{
  63. Uid: mid,
  64. KeyWord: keyWord,
  65. })
  66. log.Info("call SearchForAdmin mid(%v) keyword (%v) ret(%v)", mid, keyWord, ret)
  67. if err != nil {
  68. return
  69. }
  70. if ret == nil {
  71. log.Info("call SearchForAdmin nil mid(%v) keyword (%v) err (%v)", mid, keyWord, err)
  72. return
  73. }
  74. if ret.Data == nil {
  75. log.Info("SearchForAdmin(%v) return nil (%v)", keyWord, ret)
  76. return
  77. }
  78. for _, v := range ret.Data {
  79. resp.Data = append(resp.Data, &v1pb.RoomAdminSearchForAdminResp_Data{
  80. Uid: v.Uid,
  81. IsAdmin: v.IsAdmin,
  82. Uname: v.Uname,
  83. Face: v.Face,
  84. MedalName: v.MedalName,
  85. Level: v.Level,
  86. })
  87. }
  88. return
  89. }
  90. // IsAny implementation
  91. // 根据登录态获取功能入口是否显示, 需要登录态
  92. // `method:"GET" midware:"auth"`
  93. func (s *RoomAdminService) IsAny(ctx context.Context, req *v1pb.ShowEntryReq) (resp *v1pb.ShowEntryResp, err error) {
  94. resp = &v1pb.ShowEntryResp{}
  95. mid, _ := metadata.Value(ctx, "mid").(int64)
  96. if mid <= 0 {
  97. err = ecode.NoLogin
  98. return
  99. }
  100. ret, err := s.conn.IsAny(ctx, &v1.RoomAdminShowEntryReq{
  101. Uid: mid,
  102. })
  103. log.Info("call IsAny mid(%v) ret(%v)", mid, ret)
  104. if err != nil {
  105. return
  106. }
  107. if ret == nil {
  108. log.Info("call IsAny nil mid(%v) err (%v)", mid, err)
  109. return
  110. }
  111. resp.HasAdmin = ret.HasAdmin
  112. return
  113. }
  114. // GetByUid implementation
  115. // 获取用户拥有的的所有房管身份
  116. // `method:"GET" midware:"auth"`
  117. func (s *RoomAdminService) GetByUid(ctx context.Context, req *v1pb.RoomAdminGetByUidReq) (resp *v1pb.RoomAdminGetByUidResp, err error) {
  118. resp = &v1pb.RoomAdminGetByUidResp{}
  119. mid, _ := metadata.Value(ctx, "mid").(int64)
  120. page := req.GetPage()
  121. if page <= 0 {
  122. page = 1
  123. }
  124. ret, err := s.conn.GetByUid(ctx, &v1.RoomAdminGetByUidReq{
  125. Uid: mid,
  126. Page: page,
  127. })
  128. log.Info("call GetByUid mid(%v) page (%v) ret(%v)", mid, page, ret)
  129. if err != nil {
  130. return
  131. }
  132. if ret == nil {
  133. log.Info("call GetByUid nil mid(%v) err (%v)", mid, err)
  134. return
  135. }
  136. if nil != ret.Page {
  137. resp.Page = &v1pb.RoomAdminGetByUidResp_Page{
  138. Page: ret.GetPage().GetPage(),
  139. PageSize: ret.GetPage().GetPageSize(),
  140. TotalPage: ret.GetPage().GetTotalPage(),
  141. TotalCount: ret.GetPage().GetTotalCount(),
  142. }
  143. }
  144. if nil != ret.Data {
  145. for _, v := range ret.Data {
  146. resp.Data = append(resp.Data, &v1pb.RoomAdminGetByUidResp_Data{
  147. Uid: v.Uid,
  148. Roomid: v.Roomid,
  149. AnchorId: v.AnchorId,
  150. Uname: v.Uname,
  151. AnchorCover: v.AnchorCover,
  152. Ctime: v.Ctime,
  153. })
  154. }
  155. }
  156. return
  157. }
  158. // Resign implementation
  159. // 辞职房管
  160. // `method:"POST" midware:"auth"`
  161. func (s *RoomAdminService) Resign(ctx context.Context, req *v1pb.RoomAdminResignRoomAdminReq) (resp *v1pb.RoomAdminResignRoomAdminResp, err error) {
  162. resp = &v1pb.RoomAdminResignRoomAdminResp{}
  163. mid, _ := metadata.Value(ctx, "mid").(int64)
  164. roomId := req.GetRoomid()
  165. if roomId <= 0 {
  166. err = ecode.ParamInvalid
  167. return
  168. }
  169. ret, err := s.conn.Resign(ctx, &v1.RoomAdminResignRoomAdminReq{
  170. Roomid: roomId,
  171. Uid: mid,
  172. })
  173. log.Info("call Resign mid(%v) room (%v) ret(%v)", mid, roomId, ret)
  174. if err != nil {
  175. return
  176. }
  177. return
  178. }
  179. // GetByAnchor implementation
  180. // 获取主播拥有的的所有房管身份
  181. // `method:"GET" midware:"auth"`
  182. func (s *RoomAdminService) GetByAnchor(ctx context.Context, req *v1pb.RoomAdminGetByAnchorReq) (resp *v1pb.RoomAdminGetByAnchorResp, err error) {
  183. resp = &v1pb.RoomAdminGetByAnchorResp{}
  184. mid, _ := metadata.Value(ctx, "mid").(int64)
  185. page := req.GetPage()
  186. if page <= 0 {
  187. page = 1
  188. }
  189. ret, err := s.conn.GetByAnchor(ctx, &v1.RoomAdminGetByAnchorReq{
  190. Page: page,
  191. Uid: mid,
  192. })
  193. log.Info("call GetByAnchor mid(%v) page (%v) ret(%v)", mid, page, ret)
  194. if ret == nil {
  195. log.Info("call GetByAnchor nil mid(%v) err (%v)", mid, err)
  196. return
  197. }
  198. if err != nil {
  199. return
  200. }
  201. if nil != ret.GetPage() {
  202. resp.Page = &v1pb.RoomAdminGetByAnchorResp_Page{
  203. Page: ret.GetPage().GetPage(),
  204. PageSize: ret.GetPage().GetPageSize(),
  205. TotalPage: ret.GetPage().GetTotalPage(),
  206. TotalCount: ret.GetPage().GetTotalCount(),
  207. }
  208. }
  209. if nil != ret.Data {
  210. for _, v := range ret.Data {
  211. resp.Data = append(resp.Data, &v1pb.RoomAdminGetByAnchorResp_Data{
  212. Uid: v.GetUid(),
  213. Uname: v.GetUname(),
  214. Face: v.GetFace(),
  215. Ctime: v.GetCtime(),
  216. MedalName: v.GetMedalName(),
  217. Level: v.GetLevel(),
  218. })
  219. }
  220. }
  221. return
  222. }
  223. // Dismiss implementation
  224. // 撤销房管
  225. // `method:"POST" midware:"auth"`
  226. func (s *RoomAdminService) Dismiss(ctx context.Context, req *v1pb.RoomAdminDismissAdminReq) (resp *v1pb.RoomAdminDismissAdminResp, err error) {
  227. resp = &v1pb.RoomAdminDismissAdminResp{}
  228. mid, _ := metadata.Value(ctx, "mid").(int64)
  229. uid := req.GetUid()
  230. if uid <= 0 {
  231. err = ecode.ParamInvalid
  232. return
  233. }
  234. ret, err := s.conn.Dismiss(ctx, &v1.RoomAdminDismissAdminReq{
  235. Uid: uid,
  236. AnchorId: mid,
  237. })
  238. log.Info("call Dismiss mid(%v) user (%v) ret(%v)", mid, uid, ret)
  239. if err != nil {
  240. return
  241. }
  242. return
  243. }
  244. // Appoint implementation
  245. // 添加房管
  246. // `method:"POST" midware:"auth"`
  247. func (s *RoomAdminService) Appoint(ctx context.Context, req *v1pb.RoomAdminAddReq) (resp *v1pb.RoomAdminAddResp, err error) {
  248. resp = &v1pb.RoomAdminAddResp{}
  249. mid, _ := metadata.Value(ctx, "mid").(int64)
  250. uid := req.GetUid()
  251. if uid <= 0 {
  252. err = ecode.ParamInvalid
  253. return
  254. }
  255. ret, err := s.conn.Appoint(ctx, &v1.RoomAdminAddReq{
  256. Uid: uid,
  257. AnchorId: mid,
  258. })
  259. log.Info("call Appoint mid(%v) uid (%v) ret(%v)", mid, uid, ret)
  260. if err != nil {
  261. log.Info("Appoint error statusCode(%v) ret(%v), err(%+v)", ret, err)
  262. }
  263. if nil != ret {
  264. resp = &v1pb.RoomAdminAddResp{
  265. Uid: ret.GetUid(),
  266. Roomid: ret.GetRoomid(),
  267. }
  268. if nil != ret.Userinfo {
  269. userInfo := &v1pb.RoomAdminAddResp_UI{
  270. Uid: ret.GetUserinfo().GetUid(),
  271. Uname: ret.GetUserinfo().GetUname(),
  272. }
  273. resp.Userinfo = userInfo
  274. }
  275. } else {
  276. log.Info("call appoint return nil uid (%v) anchorid (%v)", uid, mid)
  277. }
  278. return
  279. }