payLive.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package v1
  2. import (
  3. "context"
  4. v1pb "go-common/app/admin/live/live-admin/api/http/v1"
  5. "go-common/app/admin/live/live-admin/conf"
  6. "go-common/app/admin/live/live-admin/dao"
  7. v0av "go-common/app/service/live/av/api/liverpc/v0"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. // PayLiveService struct
  12. type PayLiveService struct {
  13. conf *conf.Config
  14. // optionally add other properties here, such as dao
  15. // dao *dao.Dao
  16. }
  17. //NewPayLiveService init
  18. func NewPayLiveService(c *conf.Config) (s *PayLiveService) {
  19. s = &PayLiveService{
  20. conf: c,
  21. }
  22. return s
  23. }
  24. // Add implementation
  25. // `method:"POST" internal:"true"` 生成付费直播信息
  26. func (s *PayLiveService) Add(ctx context.Context, req *v1pb.PayLiveAddReq) (resp *v1pb.PayLiveAddResp, err error) {
  27. resp = &v1pb.PayLiveAddResp{}
  28. log.Info("Add params:%v", req)
  29. r, err := dao.AvApi.V0PayLive.Add(ctx, &v0av.PayLiveAddReq{
  30. Platform: req.Platform,
  31. RoomId: req.RoomId,
  32. Title: req.Title,
  33. Status: req.Status,
  34. StartTime: req.StartTime,
  35. EndTime: req.EndTime,
  36. LiveEndTime: req.LiveEndTime,
  37. LivePic: req.LivePic,
  38. AdPic: req.AdPic,
  39. GoodsLink: req.GoodsLink,
  40. GoodsId: req.GoodsId,
  41. IpLimit: req.IpLimit,
  42. BuyGoodsId: req.BuyGoodsId,
  43. })
  44. if err != nil {
  45. log.Error("call av error,err:%v", err)
  46. return
  47. }
  48. if r.Code != 0 {
  49. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  50. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  51. return
  52. }
  53. return
  54. }
  55. // Update implementation
  56. // `method:"POST" internal:"true"` 更新付费直播信息
  57. func (s *PayLiveService) Update(ctx context.Context, req *v1pb.PayLiveUpdateReq) (resp *v1pb.PayLiveUpdateResp, err error) {
  58. resp = &v1pb.PayLiveUpdateResp{}
  59. log.Info("Update params:%v", req)
  60. r, err := dao.AvApi.V0PayLive.Update(ctx, &v0av.PayLiveUpdateReq{
  61. LiveId: req.LiveId,
  62. Platform: req.Platform,
  63. RoomId: req.RoomId,
  64. Title: req.Title,
  65. Status: req.Status,
  66. StartTime: req.StartTime,
  67. EndTime: req.EndTime,
  68. LiveEndTime: req.LiveEndTime,
  69. LivePic: req.LivePic,
  70. AdPic: req.AdPic,
  71. GoodsLink: req.GoodsLink,
  72. GoodsId: req.GoodsId,
  73. IpLimit: req.IpLimit,
  74. BuyGoodsId: req.BuyGoodsId,
  75. })
  76. if err != nil {
  77. log.Error("call av error,err:%v", err)
  78. return
  79. }
  80. if r.Code != 0 {
  81. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  82. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  83. return
  84. }
  85. return
  86. }
  87. // GetList implementation
  88. // `method:"POST" internal:"true"` 获取付费直播列表
  89. func (s *PayLiveService) GetList(ctx context.Context, req *v1pb.PayLiveGetListReq) (resp *v1pb.PayLiveGetListResp, err error) {
  90. resp = &v1pb.PayLiveGetListResp{}
  91. r, err := dao.AvApi.V0PayLive.GetList(ctx, &v0av.PayLiveGetListReq{
  92. RoomId: req.RoomId,
  93. Title: req.Title,
  94. IpLimit: req.IpLimit,
  95. PageNum: req.PageNum,
  96. PageSize: req.PageSize,
  97. })
  98. if err != nil {
  99. log.Error("call av error,err:%v", err)
  100. return
  101. }
  102. if r.Code != 0 {
  103. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  104. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  105. return
  106. }
  107. data := r.Data
  108. resp.PageInfo = &v1pb.PayLiveGetListResp_PageInfo{
  109. TotalCount: data.PageInfo.TotalCount,
  110. PageNum: data.PageInfo.PageNum,
  111. }
  112. for _, v := range r.Data.GoodsInfo {
  113. tmp := &v1pb.PayLiveGetListResp_GoodsInfo{
  114. LiveId: v.LiveId,
  115. Platform: v.Platform,
  116. RoomId: v.RoomId,
  117. Title: v.Title,
  118. Status: v.Status,
  119. PayLiveStatus: v.PayLiveStatus,
  120. StartTime: v.StartTime,
  121. EndTime: v.EndTime,
  122. LiveEndTime: v.LiveEndTime,
  123. LivePic: v.LivePic,
  124. AdPic: v.AdPic,
  125. GoodsLink: v.GoodsLink,
  126. GoodsId: v.GoodsId,
  127. IpLimit: v.IpLimit,
  128. BuyGoodsId: v.BuyGoodsId,
  129. }
  130. resp.GoodsInfo = append(resp.GoodsInfo, tmp)
  131. }
  132. return
  133. }
  134. // Close implementation
  135. // `method:"POST" internal:"true"` 关闭鉴权
  136. func (s *PayLiveService) Close(ctx context.Context, req *v1pb.PayLiveCloseReq) (resp *v1pb.PayLiveCloseResp, err error) {
  137. resp = &v1pb.PayLiveCloseResp{}
  138. r, err := dao.AvApi.V0PayLive.Close(ctx, &v0av.PayLiveCloseReq{
  139. LiveId: req.LiveId,
  140. })
  141. if err != nil {
  142. log.Error("call av error,err:%v", err)
  143. return
  144. }
  145. if r.Code != 0 {
  146. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  147. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  148. return
  149. }
  150. return
  151. }
  152. // Open implementation
  153. // `method:"POST" internal:"true"` 开启鉴权
  154. func (s *PayLiveService) Open(ctx context.Context, req *v1pb.PayLiveOpenReq) (resp *v1pb.PayLiveOpenResp, err error) {
  155. resp = &v1pb.PayLiveOpenResp{}
  156. r, err := dao.AvApi.V0PayLive.Open(ctx, &v0av.PayLiveOpenReq{
  157. LiveId: req.LiveId,
  158. })
  159. if err != nil {
  160. log.Error("call av error,err:%v", err)
  161. return
  162. }
  163. if err != nil || r.Code != 0 {
  164. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  165. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  166. return
  167. }
  168. return
  169. }