askserie_video.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // 记录用户活动音频播放记录
  11. func AddAskserieVideoHistoryRecord(user *models.WxUserItem, askserieVideoId, playSeconds int) {
  12. if playSeconds == 0 {
  13. return
  14. }
  15. key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ASKSERIEVIDEO + strconv.Itoa(askserieVideoId) + "_" + strconv.Itoa(user.UserId)
  16. var err error
  17. defer func() {
  18. if err != nil {
  19. go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddAskserieVideoHistoryRecord Err:", err.Error(), "askserieVideoId:", askserieVideoId, "UserId:", user.UserId), 2)
  20. }
  21. }()
  22. item := new(models.CygxAskserieVideoHistoryRecord)
  23. item.UserId = user.UserId
  24. item.RealName = user.RealName
  25. item.AskserieVideoId = askserieVideoId
  26. item.VideoDuration = playSeconds
  27. item.Mobile = user.Mobile
  28. item.Email = user.Email
  29. item.CompanyId = user.CompanyId
  30. item.CompanyName = user.CompanyName
  31. item.CreateTime = time.Now().Add(-time.Duration(playSeconds) * time.Second) //减去观看时长当做,阅读时间
  32. item.ModifyTime = time.Now()
  33. item.RegisterPlatform = utils.REGISTER_PLATFORM
  34. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  35. if e != nil && e.Error() != utils.ErrNoRow() {
  36. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  37. return
  38. }
  39. if sellerItem != nil {
  40. item.SellerName = sellerItem.RealName
  41. }
  42. fmt.Println(utils.Rc.IsExist(key))
  43. if !utils.Rc.IsExist(key) {
  44. fmt.Println("添加")
  45. //添加记录
  46. e = models.AddCygxAskserieVideoHistoryRecord(item)
  47. if e != nil {
  48. err = errors.New("AddCygxAskserieVideoHistoryRecord, Err: " + e.Error())
  49. return
  50. }
  51. //播放记录加1
  52. e = models.UpdateAskserieVideoCounts(askserieVideoId)
  53. if e != nil {
  54. err = errors.New("UpdateActivityVideoCounts, Err: " + e.Error())
  55. return
  56. }
  57. utils.Rc.Put(key, 1, 10*time.Minute)
  58. } else {
  59. fmt.Println("更新")
  60. //更新停留时长
  61. lastItem, e := models.GetLastCygxAskserieVideoHistoryRecord(askserieVideoId, user.UserId)
  62. if e != nil {
  63. err = errors.New("GetLastCygxActivityVideoHistory, Err: " + e.Error())
  64. return
  65. }
  66. //更新播放时间
  67. e = models.UpdateLastCygxAskserieVideoHistoryRecord(strconv.Itoa(playSeconds), lastItem.Id)
  68. if e != nil {
  69. err = errors.New("UpdateLastCygxAskserieVideoHistoryRecord, Err: " + e.Error())
  70. return
  71. }
  72. }
  73. //if playSeconds != 0 {
  74. // //lastItem, e := models.GetLastCygxAskserieVideoHistoryRecord(askserieVideoId, user.UserId)
  75. // //if e != nil {
  76. // // err = errors.New("GetLastCygxActivityVideoHistory, Err: " + e.Error())
  77. // // return
  78. // //}
  79. // ////更新播放时间
  80. // //e = models.UpdateLastCygxAskserieVideoHistoryRecord(strconv.Itoa(playSeconds), lastItem.Id)
  81. // //if e != nil {
  82. // // err = errors.New("UpdateLastCygxAskserieVideoHistoryRecord, Err: " + e.Error())
  83. // // return
  84. // //}
  85. //
  86. //} else {
  87. // //添加记录
  88. // e = models.AddCygxAskserieVideoHistoryRecord(item)
  89. // if e != nil {
  90. // err = errors.New("AddCygxAskserieVideoHistoryRecord, Err: " + e.Error())
  91. // return
  92. // }
  93. // //播放记录加1
  94. // e = models.UpdateAskserieVideoCounts(askserieVideoId)
  95. // if e != nil {
  96. // err = errors.New("UpdateActivityVideoCounts, Err: " + e.Error())
  97. // return
  98. // }
  99. //}
  100. return
  101. }
  102. // 系列问答视频留言记录
  103. func AddCygxAskserieVideoCollection(user *models.WxUserItem, askserieVideoId int, content string) {
  104. var err error
  105. defer func() {
  106. if err != nil {
  107. go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddAskserieVideoHistoryRecord Err:", err.Error(), "askserieVideoId:", askserieVideoId, "UserId:", user.UserId), 2)
  108. }
  109. }()
  110. item := new(models.CygxAskserieVideoCollection)
  111. item.UserId = user.UserId
  112. item.RealName = user.RealName
  113. item.AskserieVideoId = askserieVideoId
  114. item.Content = content
  115. item.Mobile = user.Mobile
  116. item.Email = user.Email
  117. item.CompanyId = user.CompanyId
  118. item.CompanyName = user.CompanyName
  119. item.CreateTime = time.Now()
  120. item.ModifyTime = time.Now()
  121. item.RegisterPlatform = utils.REGISTER_PLATFORM
  122. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  123. if e != nil && e.Error() != utils.ErrNoRow() {
  124. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  125. return
  126. }
  127. if sellerItem != nil {
  128. item.SellerName = sellerItem.RealName
  129. }
  130. //添加记录
  131. e = models.AddCygxAskserieVideoCollection(item)
  132. if e != nil {
  133. err = errors.New("AddCygxAskserieVideoCollection, Err: " + e.Error())
  134. return
  135. }
  136. //播放记录加1
  137. e = models.UpdateAskserieVideoCommentNum(askserieVideoId)
  138. if e != nil {
  139. err = errors.New("UpdateAskserieVideoCommentNum, Err: " + e.Error())
  140. return
  141. }
  142. return
  143. }