payGoods.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. // PayGoodsService struct
  12. type PayGoodsService struct {
  13. conf *conf.Config
  14. // optionally add other properties here, such as dao
  15. // dao *dao.Dao
  16. }
  17. //NewPayGoodsService init
  18. func NewPayGoodsService(c *conf.Config) (s *PayGoodsService) {
  19. s = &PayGoodsService{
  20. conf: c,
  21. }
  22. return s
  23. }
  24. // Add implementation
  25. // * 生成一张付费直播票
  26. func (s *PayGoodsService) Add(ctx context.Context, req *v1pb.PayGoodsAddReq) (resp *v1pb.PayGoodsAddResp, err error) {
  27. resp = &v1pb.PayGoodsAddResp{}
  28. log.Info("Add params:%v", req)
  29. r, err := dao.AvApi.V0PayGoods.Add(ctx, &v0av.PayGoodsAddReq{
  30. Platform: req.Platform,
  31. Title: req.Title,
  32. Type: req.Type,
  33. Price: req.Price,
  34. StartTime: req.StartTime,
  35. EndTime: req.EndTime,
  36. IpLimit: req.IpLimit,
  37. })
  38. if err != nil {
  39. log.Error("call av error,err:%v", err)
  40. return
  41. }
  42. if r.Code != 0 {
  43. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  44. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  45. return
  46. }
  47. return
  48. }
  49. // Update implementation
  50. // * 更新一张付费直播票
  51. func (s *PayGoodsService) Update(ctx context.Context, req *v1pb.PayGoodsUpdateReq) (resp *v1pb.PayGoodsUpdateResp, err error) {
  52. resp = &v1pb.PayGoodsUpdateResp{}
  53. log.Info("Update params:%v", req)
  54. r, err := dao.AvApi.V0PayGoods.Update(ctx, &v0av.PayGoodsUpdateReq{
  55. Id: req.Id,
  56. Platform: req.Platform,
  57. Title: req.Title,
  58. Type: req.Type,
  59. Price: req.Price,
  60. StartTime: req.StartTime,
  61. EndTime: req.EndTime,
  62. IpLimit: req.IpLimit,
  63. })
  64. if err != nil {
  65. log.Error("call av error,err:%v", err)
  66. return
  67. }
  68. if r.Code != 0 {
  69. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  70. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  71. return
  72. }
  73. return
  74. }
  75. // GetList implementation
  76. // * 获取付费直播票列表
  77. func (s *PayGoodsService) GetList(ctx context.Context, req *v1pb.PayGoodsGetListReq) (resp *v1pb.PayGoodsGetListResp, err error) {
  78. resp = &v1pb.PayGoodsGetListResp{}
  79. r, err := dao.AvApi.V0PayGoods.GetList(ctx, &v0av.PayGoodsGetListReq{
  80. Id: req.Id,
  81. Platform: req.Platform,
  82. Title: req.Title,
  83. Type: req.Type,
  84. IpLimit: req.IpLimit,
  85. PageNum: req.PageNum,
  86. PageSize: req.PageSize,
  87. })
  88. if err != nil {
  89. log.Error("call av error,err:%v", err)
  90. return
  91. }
  92. if r.Code != 0 {
  93. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  94. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  95. return
  96. }
  97. data := r.Data
  98. resp.PageInfo = &v1pb.PayGoodsGetListResp_PageInfo{
  99. TotalCount: data.PageInfo.TotalCount,
  100. PageNum: data.PageInfo.PageNum,
  101. }
  102. for _, v := range r.Data.GoodsInfo {
  103. tmp := &v1pb.PayGoodsGetListResp_GoodsInfo{
  104. Id: v.Id,
  105. Title: v.Title,
  106. Platform: v.Platform,
  107. Type: v.Type,
  108. Price: v.Price,
  109. StartTime: v.StartTime,
  110. EndTime: v.EndTime,
  111. IpLimit: v.IpLimit,
  112. Status: v.Status,
  113. }
  114. resp.GoodsInfo = append(resp.GoodsInfo, tmp)
  115. }
  116. return
  117. }
  118. // Close implementation
  119. // * 关闭购票
  120. func (s *PayGoodsService) Close(ctx context.Context, req *v1pb.PayGoodsCloseReq) (resp *v1pb.PayGoodsCloseResp, err error) {
  121. resp = &v1pb.PayGoodsCloseResp{}
  122. r, err := dao.AvApi.V0PayGoods.Close(ctx, &v0av.PayGoodsCloseReq{
  123. Id: req.Id,
  124. })
  125. if err != nil {
  126. log.Error("call av error,err:%v", err)
  127. return
  128. }
  129. if r.Code != 0 {
  130. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  131. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  132. return
  133. }
  134. return
  135. }
  136. // Open implementation
  137. // * 开启购票
  138. func (s *PayGoodsService) Open(ctx context.Context, req *v1pb.PayGoodsOpenReq) (resp *v1pb.PayGoodsOpenResp, err error) {
  139. resp = &v1pb.PayGoodsOpenResp{}
  140. r, err := dao.AvApi.V0PayGoods.Open(ctx, &v0av.PayGoodsOpenReq{
  141. Id: req.Id,
  142. })
  143. if err != nil {
  144. log.Error("call av error,err:%v", err)
  145. return
  146. }
  147. if r.Code != 0 {
  148. log.Error("call av error,code:%v,msg:%v", r.Code, r.Msg)
  149. err = ecode.Error(ecode.Int(int(r.Code)), r.Msg)
  150. return
  151. }
  152. return
  153. }