reco.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/xstr"
  8. )
  9. // Recos fn
  10. func Recos(c *bm.Context) {
  11. params := c.Request.Form
  12. aidStr := params.Get("aid")
  13. aid, err := strconv.ParseInt(aidStr, 10, 64)
  14. if err != nil {
  15. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  16. c.JSON(nil, ecode.RequestErr)
  17. return
  18. }
  19. recos, err := vdpSvc.Recos(c, aid)
  20. if err != nil {
  21. c.JSON(nil, err)
  22. return
  23. }
  24. c.JSON(recos, nil)
  25. }
  26. // RecoUpdate fn
  27. func RecoUpdate(c *bm.Context) {
  28. params := c.Request.Form
  29. recoIdsStr := params.Get("ids")
  30. aidStr := params.Get("aid")
  31. midStr := params.Get("mid")
  32. mid, _ := strconv.ParseInt(midStr, 10, 64)
  33. if mid <= 0 {
  34. log.Error("http.archivesByMid mid(%d) <=0 ", mid)
  35. c.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. aid, err := strconv.ParseInt(aidStr, 10, 64)
  39. if err != nil {
  40. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. recoIds := []int64{}
  45. if len(recoIdsStr) > 0 {
  46. recoIds, err = xstr.SplitInts(recoIdsStr)
  47. }
  48. if err != nil {
  49. log.Error("idsStr splitInts error(%v) | recoIdsStr(%s)", err, recoIdsStr)
  50. c.JSON(nil, ecode.RequestErr)
  51. return
  52. }
  53. if len(recoIds) > 8 {
  54. log.Error("length of idsStr has over Max 8, error(%v) | recoIdsStr(%s)", err, recoIdsStr)
  55. c.JSON(nil, ecode.CreativeRecommendOverMax)
  56. return
  57. }
  58. err = vdpSvc.RecoUpdate(c, mid, aid, recoIds)
  59. if err != nil {
  60. c.JSON(nil, err)
  61. return
  62. }
  63. c.JSON(nil, nil)
  64. }