report.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package danmu
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/creative/model/danmu"
  7. dmMdl "go-common/app/interface/main/dm/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _dmReportUpEditURI = "/x/internal/dm/report/up/edit"
  13. _dmReportUpListURI = "/x/internal/dm/report/up/list"
  14. _dmReportUpArchivesURI = "/x/internal/dm/report/up/archives"
  15. )
  16. // ReportUpList fn
  17. func (d *Dao) ReportUpList(c context.Context, mid, pn, ps int64, aidStr, ip string) (result []*dmMdl.RptSearch, total int64, err error) {
  18. result = []*dmMdl.RptSearch{}
  19. params := url.Values{}
  20. params.Set("mid", strconv.FormatInt(mid, 10))
  21. params.Set("aid", aidStr)
  22. params.Set("page", strconv.FormatInt(pn, 10))
  23. params.Set("size", strconv.FormatInt(ps, 10))
  24. var res struct {
  25. Code int `json:"code"`
  26. Data *dmMdl.RptSearchs `json:"data"`
  27. }
  28. if err = d.client.Get(c, d.dmReportUpListURL, ip, params, &res); err != nil {
  29. err = ecode.CreativeDanmuErr
  30. log.Error("d.ReportUpList.Get(%s,%s,%s) err(%v)", d.dmReportUpListURL, ip, params.Encode(), err)
  31. return
  32. }
  33. if res.Code != 0 {
  34. err = ecode.Int(int(res.Code))
  35. log.Error("d.ReportUpList.Get(%s,%s,%s) err(%v)|code(%d)", d.dmReportUpListURL, ip, params.Encode(), err, res.Code)
  36. return
  37. }
  38. result = res.Data.Result
  39. total = res.Data.Total
  40. return
  41. }
  42. // ReportUpArchives fn
  43. func (d *Dao) ReportUpArchives(c context.Context, mid int64, ip string) (ars []*danmu.DmArc, err error) {
  44. ars = []*danmu.DmArc{}
  45. params := url.Values{}
  46. params.Set("mid", strconv.FormatInt(mid, 10))
  47. var res struct {
  48. Code int `json:"code"`
  49. Data *dmMdl.Archives `json:"data"`
  50. }
  51. if err = d.client.Get(c, d.dmReportUpArchivesURL, ip, params, &res); err != nil {
  52. err = ecode.CreativeDanmuErr
  53. log.Error("d.ReportUpArchives.Get(%s,%s,%s) err(%v)", d.dmReportUpArchivesURL, ip, params.Encode(), err)
  54. return
  55. }
  56. if res.Code != 0 {
  57. err = ecode.Int(int(res.Code))
  58. log.Error("d.ReportUpArchives.Get(%s,%s,%s) err(%v)|code(%d)", d.dmReportUpArchivesURL, ip, params.Encode(), err, res.Code)
  59. return
  60. }
  61. if res.Data != nil {
  62. for _, v := range res.Data.Result {
  63. ars = append(ars, &danmu.DmArc{
  64. Aid: v.Aid,
  65. Title: v.Title,
  66. })
  67. }
  68. }
  69. return
  70. }
  71. // ReportUpEdit fn
  72. func (d *Dao) ReportUpEdit(c context.Context, mid, dmid, cid, op int64, ip string) (err error) {
  73. params := url.Values{}
  74. params.Set("mid", strconv.FormatInt(mid, 10))
  75. params.Set("dmid", strconv.FormatInt(dmid, 10))
  76. params.Set("cid", strconv.FormatInt(cid, 10))
  77. params.Set("op", strconv.FormatInt(op, 10))
  78. var res struct {
  79. Code int `json:"code"`
  80. }
  81. if err = d.client.Post(c, d.dmReportUpEditURL, ip, params, &res); err != nil {
  82. err = ecode.CreativeDanmuErr
  83. log.Error("d.dmReportUpEditURL.Post(%s,%s,%s) err(%v)", d.dmReportUpEditURL, ip, params.Encode(), err)
  84. return
  85. }
  86. if res.Code != 0 {
  87. err = ecode.Int(res.Code)
  88. log.Error("d.dmReportUpEditURL.Post(%s,%s,%s) err(%v)|code(%d)", d.dmReportUpEditURL, ip, params.Encode(), err, res.Code)
  89. return
  90. }
  91. return
  92. }