smart_report.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package controllers
  2. import (
  3. "eta_gn/eta_report/models"
  4. "eta_gn/eta_report/utils"
  5. "fmt"
  6. "strconv"
  7. "strings"
  8. )
  9. type SmartReportController struct {
  10. BaseCommonController
  11. }
  12. // @router /share/detail [get]
  13. func (this *SmartReportController) Detail() {
  14. br := new(models.BaseResponse).Init()
  15. defer func() {
  16. if br.ErrMsg == "" {
  17. br.IsSendEmail = false
  18. }
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. reportCode := this.GetString("ReportCode")
  23. if reportCode == "" {
  24. br.Msg = "获取失败"
  25. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  26. return
  27. }
  28. resp := new(models.SmartReportShareDetailResp)
  29. reportOB := new(models.SmartReport)
  30. cond := ` AND report_code = ?`
  31. pars := make([]interface{}, 0)
  32. pars = append(pars, reportCode)
  33. item, e := reportOB.GetItemByCondition(cond, pars)
  34. if e != nil {
  35. if e.Error() == utils.ErrNoRow() {
  36. br.Msg = "报告不存在, 请刷新页面"
  37. return
  38. }
  39. br.Msg = "获取失败"
  40. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  41. return
  42. }
  43. resp.Report = models.FormatSmartReport2Item(item)
  44. if resp.Report.HeadResourceId > 0 {
  45. headResource, err := models.GetResourceItemById(resp.Report.HeadResourceId)
  46. if err != nil {
  47. br.Msg = "操作失败"
  48. br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
  49. return
  50. }
  51. resp.Report.HeadImg = headResource.ImgUrl
  52. resp.Report.HeadStyle = headResource.Style
  53. }
  54. if resp.Report.EndResourceId > 0 {
  55. endResource, err := models.GetResourceItemById(resp.Report.EndResourceId)
  56. if err != nil {
  57. br.Msg = "操作失败"
  58. br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
  59. return
  60. }
  61. resp.Report.EndImg = endResource.ImgUrl
  62. resp.Report.EndStyle = endResource.Style
  63. }
  64. conf, e := models.GetBusinessConf()
  65. if e != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  68. return
  69. }
  70. if conf[models.BusinessConfDisclaimer] != "" {
  71. resp.Disclaimer = conf[models.BusinessConfDisclaimer]
  72. }
  73. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  74. resp.H5ShareName = v
  75. }
  76. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  77. resp.H5ReportShareImg = v
  78. }
  79. if e = models.UpdateSmartReportPv(item.SmartReportId); e != nil {
  80. br.Msg = "获取失败"
  81. br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
  82. return
  83. }
  84. br.Ret = 200
  85. br.Success = true
  86. br.Msg = "获取成功"
  87. br.Data = resp
  88. }
  89. // @router /wechat_share/detail [get]
  90. func (this *SmartReportController) WechatShareDetail() {
  91. br := new(models.BaseResponse).Init()
  92. defer func() {
  93. if br.ErrMsg == "" {
  94. br.IsSendEmail = false
  95. }
  96. this.Data["json"] = br
  97. this.ServeJSON()
  98. }()
  99. reportCode := this.GetString("ReportCode")
  100. if reportCode == "" {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
  103. return
  104. }
  105. resp := new(models.SmartReportWechatShareDetailResp)
  106. item, e := models.GetReportByCode(reportCode)
  107. if e != nil {
  108. if e.Error() == utils.ErrNoRow() {
  109. br.Msg = "报告不存在, 请刷新页面"
  110. return
  111. }
  112. br.Msg = "获取失败"
  113. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  114. return
  115. }
  116. conf, e := models.GetBusinessConf()
  117. if e != nil {
  118. br.Msg = "获取失败"
  119. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  120. return
  121. }
  122. date := strings.Replace(item.CreateTime, "-", "", -1)
  123. dateStr := date[4:9]
  124. var shareTitle string
  125. if utils.BusinessCode == "E2023080700" || utils.BusinessCode == "E2023080900" || utils.BusinessCode == "E2023080901" {
  126. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期|FICC】" + item.Title + "(" + dateStr + ")"
  127. } else {
  128. shareTitle = "【第" + strconv.Itoa(item.Stage) + "期】" + item.Title + "(" + dateStr + ")"
  129. }
  130. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  131. resp.H5ReportShareImg = v
  132. }
  133. if v, ok := conf[models.BusinessConfH5ShareName]; ok {
  134. resp.H5ShareName = v
  135. }
  136. resp.H5ShareTitle = shareTitle
  137. br.Ret = 200
  138. br.Success = true
  139. br.Msg = "获取成功"
  140. br.Data = resp
  141. }