chart.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package controllers
  2. import (
  3. "hongze/hongze_clpt/models"
  4. "hongze/hongze_clpt/services"
  5. "hongze/hongze_clpt/utils"
  6. "strconv"
  7. )
  8. type ChartController struct {
  9. BaseAuthController
  10. }
  11. // @Title 图表详情
  12. // @Description 我的收藏接口
  13. // @Param ChartId query int true "图表ID"
  14. // @Success 200 {object} models.CygxChartDetail
  15. // @router /detail [get]
  16. func (this *ChartController) Detail() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. user := this.User
  23. if user == nil {
  24. br.Msg = "请重新登录"
  25. br.Ret = 408
  26. return
  27. }
  28. mobile := user.Mobile
  29. if mobile == "" {
  30. br.Msg = "请绑定手机号!"
  31. return
  32. }
  33. chartId, _ := this.GetInt("ChartId")
  34. if chartId <= 0 {
  35. br.Msg = "图表信息不存在!"
  36. return
  37. }
  38. detail, err := models.GetChartDetailById(chartId, user.UserId)
  39. if err != nil {
  40. br.Msg = "获取信息失败"
  41. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  42. return
  43. }
  44. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(mobile)
  45. if chartUserTokenByMobile != "" {
  46. GetIsCollectionChart, err := services.GetIsCollectionChart(mobile, chartId)
  47. if err != nil {
  48. br.Msg = "获取信息失败"
  49. br.ErrMsg = "获取三方关注信息失败,Err:" + err.Error()
  50. return
  51. }
  52. detail.IsCollection = GetIsCollectionChart
  53. detail.HttpUrl = utils.CHART_INFO_HTTP_URL + strconv.Itoa(chartId) + "?token=" + chartUserTokenByMobile
  54. } else {
  55. if detail.CollectionNum > 0 {
  56. detail.IsCollection = true
  57. }
  58. }
  59. go services.ServerAddCygxChartRecord(user, chartId) //用户阅读图表,添加浏览记录
  60. go services.KeyChartWxUserRaiLabelRedisAdd(chartId, user.UserId, "") //用户阅读图表,添加浏览记录
  61. br.Ret = 200
  62. br.Success = true
  63. br.Msg = "获取成功"
  64. br.Data = detail
  65. }