english_report.go 6.3 KB

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