web_archive.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package http
  2. import (
  3. "strconv"
  4. "strings"
  5. "time"
  6. "go-common/app/interface/main/creative/model/archive"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/metadata"
  11. )
  12. func webArchVideos(c *bm.Context) {
  13. params := c.Request.Form
  14. ck := c.Request.Header.Get("Cookie")
  15. midI, ok := c.Get("mid")
  16. if !ok {
  17. c.JSON(nil, ecode.NoLogin)
  18. return
  19. }
  20. mid, _ := midI.(int64)
  21. aidStr := params.Get("aid")
  22. aid, err := strconv.ParseInt(aidStr, 10, 64)
  23. if err != nil || aid == 0 {
  24. c.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. ip := metadata.String(c, metadata.RemoteIP)
  28. ap, err := arcSvc.SimpleArchiveVideos(c, mid, aid, "", ck, ip)
  29. if err != nil {
  30. c.JSON(nil, err)
  31. return
  32. }
  33. c.JSON(ap, nil)
  34. }
  35. func webRecommandCover(c *bm.Context) {
  36. params := c.Request.Form
  37. fnsStr := params.Get("fns")
  38. midI, ok := c.Get("mid")
  39. if !ok {
  40. c.JSON(nil, ecode.NoLogin)
  41. return
  42. }
  43. mid, _ := midI.(int64)
  44. cvs, err := dataSvc.Covers(c, mid, strings.Split(fnsStr, ","), metadata.String(c, metadata.RemoteIP))
  45. if err != nil {
  46. log.Error(" arcSvc.CoverList fnsStr(%s), mid(%d), ip(%s) error(%v)", fnsStr, mid, metadata.String(c, metadata.RemoteIP), err)
  47. c.JSON(nil, err)
  48. return
  49. }
  50. c.JSON(cvs, nil)
  51. }
  52. func webMissionProtocol(c *bm.Context) {
  53. params := c.Request.Form
  54. missionIDStr := params.Get("msid")
  55. missionID, err := strconv.ParseInt(missionIDStr, 10, 64)
  56. if err != nil || missionID <= 0 {
  57. c.JSON(nil, ecode.RequestErr)
  58. return
  59. }
  60. midI, ok := c.Get("mid")
  61. if !ok {
  62. c.JSON(nil, ecode.NoLogin)
  63. return
  64. }
  65. mid, _ := midI.(int64)
  66. missionProtocol, err := arcSvc.MissionProtocol(c, missionID)
  67. if err != nil {
  68. log.Error(" arcSvc.MissionProtocol missionID(%s), mid(%d), ip(%s) error(%v)", missionIDStr, mid, metadata.String(c, metadata.RemoteIP), err)
  69. c.JSON(nil, err)
  70. return
  71. }
  72. c.JSON(map[string]interface{}{
  73. "protocol": missionProtocol.Protocol,
  74. }, nil)
  75. }
  76. func webUgcPayProtocol(c *bm.Context) {
  77. params := c.Request.Form
  78. protocolID := params.Get("protocol_id")
  79. if len(protocolID) == 0 {
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. _, ok := c.Get("mid")
  84. if !ok {
  85. c.JSON(nil, ecode.CreativeNotLogin)
  86. return
  87. }
  88. payProtocol, err := paySvc.Protocol(c, protocolID)
  89. if err != nil {
  90. log.Error("paySvc.Protocol protocolID(%s) error(%v)", protocolID, err)
  91. c.JSON(nil, err)
  92. return
  93. }
  94. c.JSON(map[string]interface{}{
  95. "protocol": payProtocol,
  96. }, nil)
  97. }
  98. func voteAcsByTime(c *bm.Context) {
  99. params := c.Request.Form
  100. startStr := params.Get("start")
  101. endStr := params.Get("end")
  102. start, err := getTimeFromSecStr(startStr)
  103. if err != nil || start == nil || start.After(time.Now()) {
  104. c.JSON(nil, ecode.RequestErr)
  105. return
  106. }
  107. end, err := getTimeFromSecStr(endStr)
  108. if err != nil || start == nil || !isInHalfYear(start, end) {
  109. c.JSON(nil, ecode.RequestErr)
  110. return
  111. }
  112. c.JSON(arcSvc.BIZsByTime(c, start, end, archive.VoteType))
  113. }
  114. func getTimeFromSecStr(secStr string) (t *time.Time, err error) {
  115. sec, err := strconv.ParseInt(secStr, 10, 64)
  116. if err != nil || sec <= 0 {
  117. return
  118. }
  119. ti := time.Unix(sec, 0)
  120. t = &ti
  121. return
  122. }
  123. func isInHalfYear(start, end *time.Time) bool {
  124. return end.Unix() <= start.Add(6*31*24*time.Hour).Unix()
  125. }