cygx_yanxuan_special_company.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. "time"
  8. )
  9. // 记录用户阅读时长
  10. func AddSpecialRecord(user *models.WxUserItem, specialId, stopTime int) (err error) {
  11. defer func() {
  12. if err != nil {
  13. go utils.SendAlarmMsg(fmt.Sprint("记录用户阅读时长 失败 AddSpecialRecord Err:"+err.Error(), "userId:", user.UserId, "specialId:", specialId), 2)
  14. }
  15. }()
  16. if user.CompanyId <= 1 {
  17. return
  18. }
  19. var sellerName string
  20. //获取销售信息
  21. sellerName, _ = GetSellerName(user)
  22. if stopTime >= 3 {
  23. //判断一个用户是否阅读过 某一篇研选专栏
  24. totalRecord, e := models.GetCygxYanxuanSpecialRecordCountByUser(user.UserId, specialId)
  25. if e != nil {
  26. err = errors.New("GetCygxYanxuanSpecialRecordCountByUser, Err: " + e.Error())
  27. return
  28. }
  29. item := new(models.CygxYanxuanSpecialRecord)
  30. item.UserId = user.UserId
  31. item.Mobile = user.Mobile
  32. item.Email = user.Email
  33. item.CompanyId = user.CompanyId
  34. item.CompanyName = user.CompanyName
  35. item.RealName = user.RealName
  36. item.SellerName = sellerName
  37. item.CreateTime = time.Now().Add(-time.Duration(stopTime) * time.Second) // 往前推迟的时间就是他的阅读时间
  38. item.ModifyTime = time.Now()
  39. item.RegisterPlatform = utils.REGISTER_PLATFORM
  40. item.YanxuanSpecialId = specialId
  41. item.StopTime = stopTime
  42. _, e = models.AddCygxYanxuanSpecialRecord(item) // 添加历史记录
  43. if e != nil {
  44. err = errors.New("AddCygxYanxuanSpecialRecord, Err: " + e.Error())
  45. return
  46. }
  47. //如果不是弘则研究的人员阅读的,就修改Pv、Uv数量
  48. if user.CompanyId != utils.HZ_COMPANY_ID {
  49. //专栏Pv数量进行加一
  50. e = models.UpdateYanxuanSpecialPv(specialId)
  51. if e != nil {
  52. err = errors.New("UpdateYanxuanSpecialPv, Err: " + e.Error())
  53. return
  54. }
  55. //专栏作者Pv数量进行加一
  56. e = models.UpdateCygxYanxuanSpecialAuthorPv(user.UserId)
  57. if e != nil {
  58. err = errors.New("UpdateCygxYanxuanSpecialAuthorPv, Err: " + e.Error())
  59. return
  60. }
  61. //如果没有阅读过,那么就给专栏文章的UV、作者的UV进行加一
  62. if totalRecord == 0 {
  63. e = models.UpdateYanxuanSpecialUv(specialId)
  64. if e != nil {
  65. err = errors.New("UpdateYanxuanSpecialUv, Err: " + e.Error())
  66. return
  67. }
  68. //专栏作者Uv数量进行加一
  69. e = models.UpdateCygxYanxuanSpecialAuthorUv(user.UserId)
  70. if e != nil {
  71. err = errors.New("UpdateCygxYanxuanSpecialAuthorUv, Err: " + e.Error())
  72. return
  73. }
  74. }
  75. }
  76. }
  77. itemLog := new(models.CygxYanxuanSpecialRecordLog)
  78. itemLog.UserId = user.UserId
  79. itemLog.Mobile = user.Mobile
  80. itemLog.Email = user.Email
  81. itemLog.CompanyId = user.CompanyId
  82. itemLog.CompanyName = user.CompanyName
  83. itemLog.RealName = user.RealName
  84. itemLog.SellerName = sellerName
  85. itemLog.CreateTime = time.Now().Add(-time.Duration(stopTime) * time.Second) // 往前推迟的时间就是他的阅读时间
  86. itemLog.ModifyTime = time.Now()
  87. itemLog.RegisterPlatform = utils.REGISTER_PLATFORM
  88. itemLog.YanxuanSpecialId = specialId
  89. itemLog.StopTime = stopTime
  90. _, e := models.AddCygxYanxuanSpecialRecordLog(itemLog) // 添加历史记录
  91. if e != nil {
  92. err = errors.New("AddCygxYanxuanSpecialRecordLog, Err: " + e.Error())
  93. return
  94. }
  95. return
  96. }
  97. // GetYanxuanSpecialRecordByYanxuanSpecialId 获取研选专栏阅读 pv map
  98. func GetYanxuanSpecialRecordByYanxuanSpecialId(articleIds []int) (mapResp map[int]int) {
  99. var err error
  100. defer func() {
  101. if err != nil {
  102. fmt.Println(err)
  103. go utils.SendAlarmMsg("获取研选专栏阅读,信息失败,GetYanxuanSpecialRecordByYanxuanSpecialId Err:"+err.Error(), 3)
  104. }
  105. }()
  106. lenIds := len(articleIds)
  107. if lenIds == 0 {
  108. return
  109. }
  110. var condition string
  111. var pars []interface{}
  112. condition = ` AND yanxuan_special_id IN (` + utils.GetOrmInReplace(lenIds) + `) `
  113. pars = append(pars, articleIds)
  114. listPv, e := models.GetCygxYanxuanSpecialRecordListPv(condition, pars)
  115. if e != nil {
  116. err = errors.New("GetCygxArticleHistoryRecordNewpvListPvCy, Err: " + e.Error())
  117. return
  118. }
  119. mapResp = make(map[int]int, 0)
  120. for _, v := range listPv {
  121. mapResp[v.YanxuanSpecialId] = v.Pv
  122. }
  123. return
  124. }