package controllers import ( "errors" "eta_gn/eta_report/models" "eta_gn/eta_report/services/alarm_msg" "eta_gn/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 }