english_report.go 6.1 KB

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