reply.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package reply
  2. import (
  3. "context"
  4. xhttp "net/http"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/interface/main/account/conf"
  8. "go-common/app/interface/main/account/model"
  9. "go-common/library/ecode"
  10. "go-common/library/log"
  11. bm "go-common/library/net/http/blademaster"
  12. "go-common/library/xstr"
  13. )
  14. var (
  15. _replyHistoryURI = "/x/internal/v2/reply/record"
  16. _activityPagesURI = "/activity/pages"
  17. )
  18. // Dao dao
  19. type Dao struct {
  20. c *conf.Config
  21. client *bm.Client
  22. replyHistory string
  23. activityPages string
  24. }
  25. // New Dao
  26. func New(c *conf.Config) (d *Dao) {
  27. return &Dao{
  28. c: c,
  29. client: bm.NewClient(c.HTTPClient.Normal),
  30. replyHistory: c.Host.API + _replyHistoryURI,
  31. activityPages: c.Host.WWW + _activityPagesURI,
  32. }
  33. }
  34. // ReplyHistoryList reply history list
  35. func (d *Dao) ReplyHistoryList(c context.Context, mid int64, stime, etime, order, sort string, pn, ps int64, accessKey, cookie, ip string) (rhl *model.ReplyHistory, err error) {
  36. params := url.Values{}
  37. params.Set("mid", strconv.FormatInt(mid, 10))
  38. params.Set("stime", stime)
  39. params.Set("etime", etime)
  40. params.Set("order", order)
  41. params.Set("sort", sort)
  42. params.Set("pn", strconv.FormatInt(pn, 10))
  43. params.Set("ps", strconv.FormatInt(ps, 10))
  44. params.Set("access_key", accessKey)
  45. req, err := d.client.NewRequest(xhttp.MethodGet, d.replyHistory, ip, params)
  46. if err != nil {
  47. return
  48. }
  49. var res struct {
  50. Code int `json:"code"`
  51. Data struct {
  52. Page struct {
  53. Num int `json:"num"`
  54. Size int `json:"size"`
  55. Total int `json:"total"`
  56. } `json:"page"`
  57. Records []struct {
  58. ID int `json:"id"`
  59. Oid int64 `json:"oid"`
  60. Type int64 `json:"type"`
  61. Floor int `json:"floor"`
  62. Like int `json:"like"`
  63. Rcount int `json:"rcount"`
  64. Mid int64 `json:"mid"`
  65. State int `json:"state"`
  66. Message string `json:"message"`
  67. Ctime string `json:"ctime"`
  68. Members []*model.Info `json:"members"`
  69. } `json:"records"`
  70. } `json:"data"`
  71. Message string `json:"message"`
  72. TTL int `json:"ttl"`
  73. }
  74. if err = d.client.Do(c, req, &res); err != nil {
  75. log.Error("member interface reply request reply history list failed, err(%v)", err)
  76. return
  77. }
  78. if res.Code != 0 {
  79. log.Error("member interface reply request reply history list code(%d), err(%v)", res.Code, err)
  80. err = ecode.Int(res.Code)
  81. return
  82. }
  83. rhl = &model.ReplyHistory{
  84. Page: res.Data.Page,
  85. Records: make([]*model.Record, 0),
  86. }
  87. for _, v := range res.Data.Records {
  88. tme := make([]*model.Member, 0)
  89. for _, vt := range v.Members {
  90. m, _ := strconv.ParseInt(vt.Mid, 10, 64)
  91. tmp := &model.Member{
  92. Mid: m,
  93. Uname: vt.Name,
  94. }
  95. tme = append(tme, tmp)
  96. }
  97. rhlt := &model.Record{
  98. ID: v.ID,
  99. Oid: v.Oid,
  100. OidStr: strconv.FormatInt(v.Oid, 10),
  101. Type: v.Type,
  102. Floor: v.Floor,
  103. Like: v.Like,
  104. Rcount: v.Rcount,
  105. Mid: v.Mid,
  106. State: v.State,
  107. Message: v.Message,
  108. Ctime: v.Ctime,
  109. Members: tme,
  110. }
  111. rhl.Records = append(rhl.Records, rhlt)
  112. }
  113. return
  114. }
  115. // ActivityPages activity pages api
  116. func (d *Dao) ActivityPages(c context.Context, mid int64, aids []int64, accessKey, cookie, ip string) (at map[int64]*model.RecordAppend, err error) {
  117. params := url.Values{}
  118. params.Set("mid", strconv.FormatInt(mid, 10))
  119. params.Set("pids", xstr.JoinInts(aids))
  120. params.Set("all", "isOne")
  121. params.Set("access_key", accessKey)
  122. req, err := d.client.NewRequest(xhttp.MethodGet, d.activityPages, ip, params)
  123. if err != nil {
  124. return
  125. }
  126. var res struct {
  127. Code int `json:"code"`
  128. Data struct {
  129. List []struct {
  130. ID int64 `json:"id"`
  131. Name string `json:"name"`
  132. PcURL string `json:"pc_url"`
  133. } `json:"list"`
  134. } `json:"data"`
  135. }
  136. at = make(map[int64]*model.RecordAppend)
  137. if err = d.client.Do(c, req, &res); err != nil {
  138. log.Error("member interface reply request activity failed, err(%v)", err)
  139. return
  140. }
  141. if res.Code != 0 {
  142. log.Error("member interface reply request activity code != 0, err(%v)", err)
  143. err = ecode.Int(res.Code)
  144. return
  145. }
  146. for _, v := range res.Data.List {
  147. at[v.ID] = &model.RecordAppend{
  148. Title: v.Name,
  149. URL: v.PcURL,
  150. }
  151. }
  152. return
  153. }