mission.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package mission
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "time"
  7. "go-common/app/interface/main/videoup/model/mission"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _msAllURL = "/activity/list/videoall"
  13. _actOnlineByTypeURI = "/activity/online/by/type"
  14. )
  15. // Missions get missions.
  16. func (d *Dao) Missions(c context.Context) (mm map[int]*mission.Mission, err error) {
  17. var res struct {
  18. Code int `json:"code"`
  19. Data []*struct {
  20. ID int `json:"id"`
  21. Name string `json:"name"`
  22. ETime string `json:"etime"`
  23. Tags string `json:"tags"`
  24. } `json:"data"`
  25. }
  26. if err = d.httpR.Get(c, d.missAllURL, "", nil, &res); err != nil {
  27. log.Error("videoup mission list error(%v) | missAllURL(%s)", err, d.missAllURL)
  28. return
  29. }
  30. if res.Code != 0 {
  31. log.Error("videoup mission list res.Code nq zero error(%v) | missAllURL(%s) res(%v)", res.Code, d.missAllURL, res)
  32. err = ecode.CreativeActivityErr
  33. return
  34. }
  35. mm = make(map[int]*mission.Mission, len(res.Data))
  36. for _, m := range res.Data {
  37. miss := &mission.Mission{}
  38. miss.ID = m.ID
  39. miss.Name = m.Name
  40. miss.ETime, _ = time.Parse("2006-01-02 15:04:05", m.ETime)
  41. miss.Tags = m.Tags
  42. mm[miss.ID] = miss
  43. }
  44. return
  45. }
  46. // MissionOnlineByTid fn, 这里默认会返回所有无投稿分区限制要求的通用活动,在做校验的时候允许此类活动投稿到任意分区
  47. func (d *Dao) MissionOnlineByTid(c context.Context, tid int16) (mm map[int]*mission.Mission, err error) {
  48. var res struct {
  49. Code int `json:"code"`
  50. Data []*struct {
  51. ID int `json:"id"`
  52. Name string `json:"name"`
  53. ETime string `json:"etime"`
  54. Tags string `json:"tags"`
  55. } `json:"data"`
  56. }
  57. mm = make(map[int]*mission.Mission)
  58. params := url.Values{}
  59. params.Set("type", strconv.Itoa(int(tid)))
  60. params.Set("plat", "1")
  61. if err = d.httpR.Get(c, d.actOnlineByTypeURL, "", params, &res); err != nil {
  62. log.Error("videoup actOnlineByTypeURL error(%v) | actOnlineByTypeURL(%s)", err, d.actOnlineByTypeURL+"?"+params.Encode())
  63. err = ecode.CreativeActivityErr
  64. return
  65. }
  66. if res.Code != 0 {
  67. log.Error("videoup actOnlineByTypeURL res.Code nq zero error(%v) | actOnlineByTypeURL(%s) res(%v)", res.Code, d.actOnlineByTypeURL+"?"+params.Encode(), res)
  68. err = ecode.CreativeActivityErr
  69. return
  70. }
  71. for _, m := range res.Data {
  72. miss := &mission.Mission{}
  73. miss.ID = m.ID
  74. miss.Name = m.Name
  75. miss.ETime, _ = time.Parse("2006-01-02 15:04:05", m.ETime)
  76. miss.Tags = m.Tags
  77. mm[miss.ID] = miss
  78. }
  79. return
  80. }