report_share.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package controllers
  2. import (
  3. "eta_gn/eta_report/models"
  4. "html"
  5. )
  6. type ReportShareController struct {
  7. BaseCommonController
  8. }
  9. // @router /share/detail [get]
  10. func (this *ReportShareController) Detail() {
  11. br := new(models.BaseResponse).Init()
  12. defer func() {
  13. this.Data["json"] = br
  14. this.ServeJSON()
  15. }()
  16. reportCode := this.GetString("ReportCode")
  17. if reportCode == "" {
  18. br.Msg = "参数错误"
  19. br.ErrMsg = "参数错误,reportCode 为空"
  20. return
  21. }
  22. report, err := models.GetReportByCode(reportCode)
  23. if err != nil {
  24. br.Msg = "该报告已删除"
  25. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  26. return
  27. }
  28. report.ContentSub = html.UnescapeString(report.ContentSub)
  29. report.Content = html.UnescapeString(report.Content)
  30. report.ContentStruct = html.UnescapeString(report.ContentStruct)
  31. if report.HeadResourceId > 0 {
  32. headResource, err := models.GetResourceItemById(report.HeadResourceId)
  33. if err != nil {
  34. br.Msg = "操作失败"
  35. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  36. return
  37. }
  38. report.HeadImg = headResource.ImgUrl
  39. report.HeadStyle = headResource.Style
  40. }
  41. if report.EndResourceId > 0 {
  42. endResource, err := models.GetResourceItemById(report.EndResourceId)
  43. if err != nil {
  44. br.Msg = "操作失败"
  45. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  46. return
  47. }
  48. report.EndImg = endResource.ImgUrl
  49. report.EndStyle = endResource.Style
  50. }
  51. resp := new(models.ReportShareDetailResp)
  52. conf, e := models.GetBusinessConf()
  53. if e != nil {
  54. br.Msg = "获取失败"
  55. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  56. return
  57. }
  58. if conf[models.BusinessConfDisclaimer] != "" {
  59. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  60. }
  61. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  62. resp.H5ShareName = v
  63. }
  64. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  65. resp.H5ReportShareImg = v
  66. }
  67. if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
  68. resp.WatermarkChart = v
  69. }
  70. if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
  71. resp.WatermarkReport = v
  72. }
  73. if v, ok := conf[models.BusinessConfReportCenterLogoShow]; ok {
  74. if v == `true` {
  75. if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
  76. resp.ReportLogo = reportLogo
  77. }
  78. }
  79. }
  80. resp.Report = new(models.ReportItem)
  81. reportChapters := make([]*models.ReportChapter, 0)
  82. if report.HasChapter == 1 {
  83. chapters, e := models.GetPublishedChapterListByReportId(report.Id)
  84. if e != nil {
  85. br.Msg = "获取失败"
  86. br.ErrMsg = "获取章节列表失败, Err: " + e.Error()
  87. return
  88. }
  89. if len(chapters) > 0 {
  90. for _, chapter := range chapters {
  91. chapter.Content = html.UnescapeString(chapter.Content)
  92. chapter.ContentSub = html.UnescapeString(chapter.ContentSub)
  93. reportChapters = append(reportChapters, chapter)
  94. }
  95. }
  96. }
  97. if e = models.UpdateReportPv(report.Id); e != nil {
  98. br.Msg = "获取失败"
  99. br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
  100. return
  101. }
  102. resp.Report.Report = report
  103. resp.Report.ChapterList = reportChapters
  104. br.Ret = 200
  105. br.Success = true
  106. br.Msg = "获取成功"
  107. br.Data = resp
  108. }