english_report.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package controllers
  2. import (
  3. "errors"
  4. "eta/eta_report/models"
  5. "eta/eta_report/services"
  6. "eta/eta_report/services/alarm_msg"
  7. "eta/eta_report/utils"
  8. "fmt"
  9. "html"
  10. "time"
  11. )
  12. // EnglishReportShareController 报告分享
  13. type EnglishReportShareController struct {
  14. BaseCommonController
  15. }
  16. // EnglishReportDetail
  17. // @Title 英文研报-分享详情
  18. // @Description 英文研报-分享详情
  19. // @Param ReportCode query string true "报告唯一编码"
  20. // @Param ShareEmail query int false "推送的邮箱ID"
  21. // @Success 200 {object} models.EnglishReportShareDetailResp
  22. // @router /share/detail [get]
  23. func (this *EnglishReportShareController) EnglishReportDetail() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. reportCode := this.GetString("ReportCode")
  30. if reportCode == "" {
  31. br.Msg = "参数错误"
  32. br.ErrMsg = "参数错误,reportCode 为空"
  33. return
  34. }
  35. report, err := models.GetEnglishReportByCode(reportCode)
  36. if err != nil {
  37. br.Msg = "该报告已删除"
  38. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  39. return
  40. }
  41. err = models.UpdateEnglishReportCounts(reportCode)
  42. if err != nil {
  43. br.Msg = "更新失败"
  44. br.ErrMsg = "更新失败,Err:" + err.Error()
  45. return
  46. }
  47. report.ContentSub = html.UnescapeString(report.ContentSub)
  48. report.Content = html.UnescapeString(report.Content)
  49. // 记录邮箱
  50. shareEmail, _ := this.GetInt("ShareEmail", 0)
  51. if shareEmail != 0 {
  52. go func() {
  53. var errMsg error
  54. defer func() {
  55. if errMsg != nil {
  56. fmt.Println(errMsg.Error())
  57. alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
  58. }
  59. }()
  60. userEmail, e := models.GetEnglishReportEmailById(shareEmail)
  61. if e != nil && e.Error() != utils.ErrNoRow() {
  62. errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
  63. return
  64. }
  65. if userEmail == nil {
  66. return
  67. }
  68. // 更新报告邮箱pv(冗余)
  69. if e = models.UpdateEnglishReportEmailCounts(reportCode); e != nil {
  70. errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
  71. return
  72. }
  73. // 记录邮箱PV
  74. pv := &models.EnglishReportEmailPV{
  75. ReportId: report.Id,
  76. EmailId: userEmail.Id,
  77. CreateTime: time.Now().Local(),
  78. }
  79. if e = models.InsertTrialEnglishReportEmailPV(pv); e != nil {
  80. errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
  81. return
  82. }
  83. // 更新阅读量
  84. if e = models.UpdateEnglishReportEmailViewTotal(userEmail.Id); e != nil {
  85. errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
  86. return
  87. }
  88. if userEmail.CompanyId > 0 {
  89. if e = models.UpdateEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
  90. errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
  91. return
  92. }
  93. }
  94. }()
  95. }
  96. resp := new(models.EnglishReportShareDetailResp)
  97. // 免责声明
  98. conf, e := models.GetBusinessConf()
  99. if e != nil {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  102. return
  103. }
  104. // 研报分享抬头
  105. if v, ok := conf[models.BusinessConfH5ShareEnName]; ok {
  106. resp.H5ShareEnName = v
  107. }
  108. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  109. resp.H5ReportShareImg = v
  110. }
  111. if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
  112. resp.WatermarkChart = v
  113. }
  114. if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
  115. resp.WatermarkReport = v
  116. }
  117. if conf[models.BusinessConfDisclaimerEn] != "" {
  118. resp.DisclaimerEn = conf[models.BusinessConfDisclaimerEn]
  119. }
  120. // 报告Logo
  121. if v, ok := conf[models.BusinessConfReportEnLogoShow]; ok {
  122. if v == `true` {
  123. if reportLogo, ok := conf[models.BusinessConfReportLogo]; ok {
  124. resp.ReportLogo = reportLogo
  125. }
  126. }
  127. }
  128. var hasAuth bool
  129. authToken := this.GetString("AuthToken")
  130. if authToken != "" {
  131. key := fmt.Sprint(utils.CACHE_REPORT_AUTH, `en:`, authToken)
  132. redisReportId, err := utils.Rc.GetUInt64(key)
  133. if err == nil && int(redisReportId) == report.Id {
  134. hasAuth = true
  135. }
  136. }
  137. // 报告内图表授权
  138. if v, ok := conf[models.BusinessConfIsOpenChartExpired]; ok {
  139. if v == `true` {
  140. resp.IsOpenChartExpired = true
  141. // 有权限才会添加token
  142. if hasAuth {
  143. tokenMap := make(map[string]string)
  144. report.Content = services.HandleReportContent(report.Content, "add", tokenMap)
  145. }
  146. }
  147. }
  148. resp.Hz = 1
  149. resp.Report = report
  150. br.Ret = 200
  151. br.Success = true
  152. br.Msg = "获取成功"
  153. br.Data = resp
  154. }
  155. // TrialEnglishReportDetail
  156. // @Title 英文研报-分享详情-ETA试用平台
  157. // @Description 英文研报-分享详情
  158. // @Param ReportCode query string true "报告唯一编码"
  159. // @Param ShareEmail query int false "推送的邮箱ID"
  160. // @Success 200 {object} models.EnglishReportShareDetailResp
  161. // @router /trial/share/detail [get]
  162. func (this *EnglishReportShareController) TrialEnglishReportDetail() {
  163. br := new(models.BaseResponse).Init()
  164. defer func() {
  165. this.Data["json"] = br
  166. this.ServeJSON()
  167. }()
  168. reportCode := this.GetString("ReportCode")
  169. if reportCode == "" {
  170. br.Msg = "参数错误"
  171. br.ErrMsg = "参数错误,reportCode 为空"
  172. return
  173. }
  174. report, err := models.GetTrialEnglishReportByCode(reportCode)
  175. if err != nil {
  176. br.Msg = "该报告已删除"
  177. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  178. return
  179. }
  180. err = models.UpdateTrialEnglishReportCounts(reportCode)
  181. if err != nil {
  182. br.Msg = "更新失败"
  183. br.ErrMsg = "更新失败,Err:" + err.Error()
  184. return
  185. }
  186. report.ContentSub = html.UnescapeString(report.ContentSub)
  187. report.Content = html.UnescapeString(report.Content)
  188. // 记录邮箱
  189. shareEmail, _ := this.GetInt("ShareEmail", 0)
  190. if shareEmail != 0 {
  191. go func() {
  192. var errMsg error
  193. defer func() {
  194. if errMsg != nil {
  195. alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
  196. }
  197. }()
  198. userEmail, e := models.GetTrialEnglishReportEmailById(shareEmail)
  199. if e != nil && e.Error() != utils.ErrNoRow() {
  200. errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
  201. return
  202. }
  203. if userEmail == nil {
  204. return
  205. }
  206. // 更新报告邮箱pv(冗余)
  207. if e = models.UpdateTrialEnglishReportEmailCounts(reportCode); e != nil {
  208. errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
  209. return
  210. }
  211. // 记录邮箱PV
  212. pv := &models.EnglishReportEmailPV{
  213. ReportId: report.Id,
  214. EmailId: userEmail.Id,
  215. CreateTime: time.Now().Local(),
  216. }
  217. if e = models.InsertTrialEnglishReportEmailPV(pv); e != nil {
  218. errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
  219. return
  220. }
  221. // 更新阅读量
  222. if e = models.UpdateTrialEnglishReportEmailViewTotal(userEmail.Id); e != nil {
  223. errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
  224. return
  225. }
  226. if userEmail.CompanyId > 0 {
  227. if e = models.UpdateTrialEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
  228. errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
  229. return
  230. }
  231. }
  232. }()
  233. }
  234. resp := new(models.EnglishReportShareDetailResp)
  235. // 免责声明
  236. conf, e := models.GetBusinessConf()
  237. if e != nil {
  238. br.Msg = "获取失败"
  239. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  240. return
  241. }
  242. // 研报分享抬头
  243. if v, ok := conf[models.BusinessConfH5ShareEnName]; ok {
  244. resp.H5ShareEnName = v
  245. }
  246. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  247. resp.H5ReportShareImg = v
  248. }
  249. if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
  250. resp.WatermarkChart = v
  251. }
  252. if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
  253. resp.WatermarkReport = v
  254. }
  255. resp.Hz = 1
  256. resp.Report = report
  257. br.Ret = 200
  258. br.Success = true
  259. br.Msg = "获取成功"
  260. br.Data = resp
  261. }