123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package controllers
- import (
- "eta_gn/eta_report/models"
- "eta_gn/eta_report/utils"
- "fmt"
- "strconv"
- "strings"
- )
- type SmartReportController struct {
- BaseCommonController
- }
- // @router /share/detail [get]
- func (this *SmartReportController) Detail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- reportCode := this.GetString("ReportCode")
- if reportCode == "" {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
- return
- }
- resp := new(models.SmartReportShareDetailResp)
- reportOB := new(models.SmartReport)
- cond := ` AND report_code = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, reportCode)
- item, e := reportOB.GetItemByCondition(cond, pars)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "报告不存在, 请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- resp.Report = models.FormatSmartReport2Item(item)
- if resp.Report.HeadResourceId > 0 {
- headResource, err := models.GetResourceItemById(resp.Report.HeadResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
- return
- }
- resp.Report.HeadImg = headResource.ImgUrl
- resp.Report.HeadStyle = headResource.Style
- }
- if resp.Report.EndResourceId > 0 {
- endResource, err := models.GetResourceItemById(resp.Report.EndResourceId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "获取资源库版头失败, Err: " + e.Error()
- return
- }
- resp.Report.EndImg = endResource.ImgUrl
- resp.Report.EndStyle = endResource.Style
- }
- 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 e = models.UpdateSmartReportPv(item.SmartReportId); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "更新报告pv失败, Err: " + e.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @router /wechat_share/detail [get]
- func (this *SmartReportController) WechatShareDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- reportCode := this.GetString("ReportCode")
- if reportCode == "" {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("参数有误, ReportCode: %s", reportCode)
- return
- }
- resp := new(models.SmartReportWechatShareDetailResp)
- item, e := models.GetReportByCode(reportCode)
- if e != nil {
- if e.Error() == utils.ErrNoRow() {
- br.Msg = "报告不存在, 请刷新页面"
- return
- }
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告失败, Err: " + e.Error()
- return
- }
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- date := strings.Replace(item.CreateTime, "-", "", -1)
- dateStr := date[4:9]
- var shareTitle string
- if utils.BusinessCode == "E2023080700" || utils.BusinessCode == "E2023080900" || utils.BusinessCode == "E2023080901" {
- shareTitle = "【第" + strconv.Itoa(item.Stage) + "期|FICC】" + item.Title + "(" + dateStr + ")"
- } else {
- shareTitle = "【第" + strconv.Itoa(item.Stage) + "期】" + item.Title + "(" + dateStr + ")"
- }
- if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
- resp.H5ReportShareImg = v
- }
- if v, ok := conf[models.BusinessConfH5ShareName]; ok {
- resp.H5ShareName = v
- }
- resp.H5ShareTitle = shareTitle
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|