hotspots.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/openplatform/article/conf"
  5. "go-common/app/interface/openplatform/article/dao"
  6. "go-common/app/interface/openplatform/article/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. func hotspotArts(c *bm.Context) {
  12. var (
  13. mid int64
  14. rs []*model.MetaWithLike
  15. hot *model.Hotspot
  16. err error
  17. params = c.Request.Form
  18. aids []int64
  19. )
  20. cid, _ := strconv.ParseInt(params.Get("id"), 10, 64)
  21. sort, _ := strconv.Atoi(params.Get("sort"))
  22. pn, _ := strconv.ParseInt(params.Get("pn"), 10, 64)
  23. ps, _ := strconv.ParseInt(params.Get("ps"), 10, 64)
  24. if cid == 0 {
  25. c.JSON(nil, ecode.RequestErr)
  26. return
  27. }
  28. if pn <= 0 {
  29. pn = 1
  30. }
  31. if pn > conf.Conf.Article.MaxRecommendPnSize {
  32. c.JSON(nil, ecode.RequestErr)
  33. return
  34. }
  35. if ps <= 0 {
  36. ps = 20
  37. } else if ps > conf.Conf.Article.MaxRecommendPsSize {
  38. c.JSON(nil, ecode.RequestErr)
  39. return
  40. }
  41. if midInter, ok := c.Get("mid"); ok {
  42. mid = midInter.(int64)
  43. }
  44. if hot, rs, err = artSrv.HotspotArts(c, cid, int(pn), int(ps), aids, int8(sort), mid); err != nil {
  45. c.JSON(nil, err)
  46. dao.PromError("热点运营接口")
  47. log.Error("service.HotspotArts(%d) error(%+v)", mid, err)
  48. return
  49. }
  50. res := make(map[string]interface{})
  51. res["aids_len"] = conf.Conf.Article.RecommendAidLen
  52. if rs == nil {
  53. rs = []*model.MetaWithLike{}
  54. }
  55. res["data"] = &model.HotspotResp{
  56. Hotspot: hot,
  57. Articles: rs,
  58. }
  59. c.JSONMap(res, nil)
  60. }