english_report.go 7.0 KB

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