123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- package controllers
- import (
- "errors"
- "eta/eta_report/models"
- "eta/eta_report/services/alarm_msg"
- "eta/eta_report/utils"
- "fmt"
- "html"
- "time"
- )
- // EnglishReportShareController 报告分享
- type EnglishReportShareController struct {
- BaseCommonController
- }
- // EnglishReportDetail
- // @Title 英文研报-分享详情
- // @Description 英文研报-分享详情
- // @Param ReportCode query string true "报告唯一编码"
- // @Param ShareEmail query int false "推送的邮箱ID"
- // @Success 200 {object} models.EnglishReportShareDetailResp
- // @router /share/detail [get]
- func (this *EnglishReportShareController) EnglishReportDetail() {
- 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.GetEnglishReportByCode(reportCode)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
- return
- }
- err = models.UpdateEnglishReportCounts(reportCode)
- if err != nil {
- br.Msg = "更新失败"
- br.ErrMsg = "更新失败,Err:" + err.Error()
- return
- }
- report.ContentSub = html.UnescapeString(report.ContentSub)
- report.Content = html.UnescapeString(report.Content)
- // 记录邮箱
- shareEmail, _ := this.GetInt("ShareEmail", 0)
- if shareEmail != 0 {
- go func() {
- var errMsg error
- defer func() {
- if errMsg != nil {
- fmt.Println(errMsg.Error())
- alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
- }
- }()
- userEmail, e := models.GetEnglishReportEmailById(shareEmail)
- if e != nil && e.Error() != utils.ErrNoRow() {
- errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
- return
- }
- if userEmail == nil {
- return
- }
- // 更新报告邮箱pv(冗余)
- if e = models.UpdateEnglishReportEmailCounts(reportCode); e != nil {
- errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
- return
- }
- // 记录邮箱PV
- pv := &models.EnglishReportEmailPV{
- ReportId: report.Id,
- EmailId: userEmail.Id,
- CreateTime: time.Now().Local(),
- }
- if e = models.InsertTrialEnglishReportEmailPV(pv); e != nil {
- errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
- return
- }
- // 更新阅读量
- if e = models.UpdateEnglishReportEmailViewTotal(userEmail.Id); e != nil {
- errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
- return
- }
- if userEmail.CompanyId > 0 {
- if e = models.UpdateEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
- errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
- return
- }
- }
- }()
- }
- resp := new(models.EnglishReportShareDetailResp)
- // 免责声明
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- // 研报分享抬头
- if v, ok := conf[models.BusinessConfH5ShareEnName]; ok {
- resp.H5ShareEnName = 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 conf[models.BusinessConfDisclaimerEn] != "" {
- resp.DisclaimerEn = conf[models.BusinessConfDisclaimerEn]
- }
- // 报告Logo
- if v, ok := conf[models.BusinessConfReportEnLogoShow]; ok {
- if v == `true` {
- if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
- resp.ReportLogo = reportLogo
- }
- }
- }
- resp.Hz = 1
- resp.Report = report
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // TrialEnglishReportDetail
- // @Title 英文研报-分享详情-ETA试用平台
- // @Description 英文研报-分享详情
- // @Param ReportCode query string true "报告唯一编码"
- // @Param ShareEmail query int false "推送的邮箱ID"
- // @Success 200 {object} models.EnglishReportShareDetailResp
- // @router /trial/share/detail [get]
- func (this *EnglishReportShareController) TrialEnglishReportDetail() {
- 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.GetTrialEnglishReportByCode(reportCode)
- if err != nil {
- br.Msg = "该报告已删除"
- br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
- return
- }
- err = models.UpdateTrialEnglishReportCounts(reportCode)
- if err != nil {
- br.Msg = "更新失败"
- br.ErrMsg = "更新失败,Err:" + err.Error()
- return
- }
- report.ContentSub = html.UnescapeString(report.ContentSub)
- report.Content = html.UnescapeString(report.Content)
- // 记录邮箱
- shareEmail, _ := this.GetInt("ShareEmail", 0)
- if shareEmail != 0 {
- go func() {
- var errMsg error
- defer func() {
- if errMsg != nil {
- alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
- }
- }()
- userEmail, e := models.GetTrialEnglishReportEmailById(shareEmail)
- if e != nil && e.Error() != utils.ErrNoRow() {
- errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
- return
- }
- if userEmail == nil {
- return
- }
- // 更新报告邮箱pv(冗余)
- if e = models.UpdateTrialEnglishReportEmailCounts(reportCode); e != nil {
- errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
- return
- }
- // 记录邮箱PV
- pv := &models.EnglishReportEmailPV{
- ReportId: report.Id,
- EmailId: userEmail.Id,
- CreateTime: time.Now().Local(),
- }
- if e = models.InsertTrialEnglishReportEmailPV(pv); e != nil {
- errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
- return
- }
- // 更新阅读量
- if e = models.UpdateTrialEnglishReportEmailViewTotal(userEmail.Id); e != nil {
- errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
- return
- }
- if userEmail.CompanyId > 0 {
- if e = models.UpdateTrialEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
- errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
- return
- }
- }
- }()
- }
- resp := new(models.EnglishReportShareDetailResp)
- // 免责声明
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- // 研报分享抬头
- if v, ok := conf[models.BusinessConfH5ShareEnName]; ok {
- resp.H5ShareEnName = 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
- }
- resp.Hz = 1
- resp.Report = report
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|