123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package controllers
- import (
- "eta_gn/eta_report/models"
- "html"
- )
- type ReportShareController struct {
- BaseCommonController
- }
- // @router /share/detail [get]
- func (this *ReportShareController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- reportCode := this.GetString("ReportCode")
- if reportCode == "" {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误,reportCode 为空"
- return
- }
- report, err := models.GetReportByCode(reportCode)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
- return
- }
- report.ContentSub = html.UnescapeString(report.ContentSub)
- report.Content = html.UnescapeString(report.Content)
- report.ContentStruct = html.UnescapeString(report.ContentStruct)
- if report.HeadResourceId > 0 {
- headResource, err := models.GetResourceItemById(report.HeadResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- report.HeadImg = headResource.ImgUrl
- report.HeadStyle = headResource.Style
- }
- if report.EndResourceId > 0 {
- endResource, err := models.GetResourceItemById(report.EndResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
- return
- }
- report.EndImg = endResource.ImgUrl
- report.EndStyle = endResource.Style
- }
- resp := new(models.ReportShareDetailResp)
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- if conf[models.BusinessConfDisclaimer] != "" {
- resp.Disclaimer = conf[models.BusinessConfDisclaimer]
- }
- if v, ok := conf[models.BusinessConfH5ShareName]; ok {
- resp.H5ShareName = v
- }
- if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
- resp.H5ReportShareImg = v
- }
- if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
- resp.WatermarkChart = v
- }
- if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
- resp.WatermarkReport = v
- }
- if v, ok := conf[models.BusinessConfReportCenterLogoShow]; ok {
- if v == `true` {
- if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
- resp.ReportLogo = reportLogo
- }
- }
- }
- resp.Report = new(models.ReportItem)
- reportChapters := make([]*models.ReportChapter, 0)
- if report.HasChapter == 1 {
- chapters, e := models.GetPublishedChapterListByReportId(report.Id)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取章节列表失败, Err: " + e.Error()
- return
- }
- if len(chapters) > 0 {
- for _, chapter := range chapters {
- chapter.Content = html.UnescapeString(chapter.Content)
- chapter.ContentSub = html.UnescapeString(chapter.ContentSub)
- reportChapters = append(reportChapters, chapter)
- }
- }
- }
- if e = models.UpdateReportPv(report.Id); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
- return
- }
- resp.Report.Report = report
- resp.Report.ChapterList = reportChapters
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|