english_report.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. // 报告内图表授权
  129. if v, ok := conf[models.BusinessConfIsOpenChartExpired]; ok {
  130. if v == `true` {
  131. tokenMap := make(map[string]string)
  132. report.Content = services.HandleReportContent(report.Content, "add", tokenMap)
  133. }
  134. }
  135. resp.Hz = 1
  136. resp.Report = report
  137. br.Ret = 200
  138. br.Success = true
  139. br.Msg = "获取成功"
  140. br.Data = resp
  141. }
  142. // TrialEnglishReportDetail
  143. // @Title 英文研报-分享详情-ETA试用平台
  144. // @Description 英文研报-分享详情
  145. // @Param ReportCode query string true "报告唯一编码"
  146. // @Param ShareEmail query int false "推送的邮箱ID"
  147. // @Success 200 {object} models.EnglishReportShareDetailResp
  148. // @router /trial/share/detail [get]
  149. func (this *EnglishReportShareController) TrialEnglishReportDetail() {
  150. br := new(models.BaseResponse).Init()
  151. defer func() {
  152. this.Data["json"] = br
  153. this.ServeJSON()
  154. }()
  155. reportCode := this.GetString("ReportCode")
  156. if reportCode == "" {
  157. br.Msg = "参数错误"
  158. br.ErrMsg = "参数错误,reportCode 为空"
  159. return
  160. }
  161. report, err := models.GetTrialEnglishReportByCode(reportCode)
  162. if err != nil {
  163. br.Msg = "该报告已删除"
  164. br.ErrMsg = "获取报告详情失败,Err:" + err.Error()
  165. return
  166. }
  167. err = models.UpdateTrialEnglishReportCounts(reportCode)
  168. if err != nil {
  169. br.Msg = "更新失败"
  170. br.ErrMsg = "更新失败,Err:" + err.Error()
  171. return
  172. }
  173. report.ContentSub = html.UnescapeString(report.ContentSub)
  174. report.Content = html.UnescapeString(report.Content)
  175. // 记录邮箱
  176. shareEmail, _ := this.GetInt("ShareEmail", 0)
  177. if shareEmail != 0 {
  178. go func() {
  179. var errMsg error
  180. defer func() {
  181. if errMsg != nil {
  182. alarm_msg.SendAlarmMsg(utils.APPNAME+"更新英文报告邮箱PV失败, Err: "+errMsg.Error(), 2)
  183. }
  184. }()
  185. userEmail, e := models.GetTrialEnglishReportEmailById(shareEmail)
  186. if e != nil && e.Error() != utils.ErrNoRow() {
  187. errMsg = errors.New("获取客户邮箱信息失败, Err:" + e.Error())
  188. return
  189. }
  190. if userEmail == nil {
  191. return
  192. }
  193. // 更新报告邮箱pv(冗余)
  194. if e = models.UpdateTrialEnglishReportEmailCounts(reportCode); e != nil {
  195. errMsg = errors.New("更新报告邮箱PV失败, Err:" + e.Error())
  196. return
  197. }
  198. // 记录邮箱PV
  199. pv := &models.EnglishReportEmailPV{
  200. ReportId: report.Id,
  201. EmailId: userEmail.Id,
  202. CreateTime: time.Now().Local(),
  203. }
  204. if e = models.InsertTrialEnglishReportEmailPV(pv); e != nil {
  205. errMsg = errors.New("新增邮箱PV失败, Err: " + e.Error())
  206. return
  207. }
  208. // 更新阅读量
  209. if e = models.UpdateTrialEnglishReportEmailViewTotal(userEmail.Id); e != nil {
  210. errMsg = errors.New("更新英文联系人阅读量失败, Err: " + e.Error())
  211. return
  212. }
  213. if userEmail.CompanyId > 0 {
  214. if e = models.UpdateTrialEnglishCompanyViewTotal(userEmail.CompanyId); e != nil {
  215. errMsg = errors.New("更新英文客户阅读量, Err: " + e.Error())
  216. return
  217. }
  218. }
  219. }()
  220. }
  221. resp := new(models.EnglishReportShareDetailResp)
  222. // 免责声明
  223. conf, e := models.GetBusinessConf()
  224. if e != nil {
  225. br.Msg = "获取失败"
  226. br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
  227. return
  228. }
  229. // 研报分享抬头
  230. if v, ok := conf[models.BusinessConfH5ShareEnName]; ok {
  231. resp.H5ShareEnName = v
  232. }
  233. if v, ok := conf[models.BusinessConfH5ReportShareImg]; ok {
  234. resp.H5ReportShareImg = v
  235. }
  236. if v, ok := conf[models.BusinessConfWatermarkChart]; ok {
  237. resp.WatermarkChart = v
  238. }
  239. if v, ok := conf[models.BusinessConfWatermarkReport]; ok {
  240. resp.WatermarkReport = v
  241. }
  242. resp.Hz = 1
  243. resp.Report = report
  244. br.Ret = 200
  245. br.Success = true
  246. br.Msg = "获取成功"
  247. br.Data = resp
  248. }