cygx_activity_video_history.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // 添加活动的视频播放记录
  11. //func AddActivityVideoHistory(user *models.WxUserItem, activityId int) (err error) {
  12. // activityInfo, errInfo := models.GetCygxActivityVideoByActivityId(activityId)
  13. // if activityInfo == nil {
  14. // return
  15. // }
  16. // if errInfo != nil {
  17. // return
  18. // }
  19. // var sellerName string
  20. // sellerName, err = models.GetCompanySellerName(user.CompanyId)
  21. // if err != nil {
  22. // return
  23. // }
  24. // item := models.CygxActivityVideoHistory{
  25. // ActivityId: activityInfo.ActivityId,
  26. // VideoId: activityInfo.VideoId,
  27. // UserId: user.UserId,
  28. // CreateTime: time.Now(),
  29. // Mobile: user.Mobile,
  30. // Email: user.Email,
  31. // CompanyId: user.CompanyId,
  32. // CompanyName: user.CompanyName,
  33. // RealName: user.RealName,
  34. // SellerName: sellerName,
  35. // ModifyTime: time.Now(),
  36. // }
  37. // err = models.AddCygxActivityVideoHistory(&item)
  38. // if err != nil {
  39. // return
  40. // }
  41. // err = models.UpdateActivityVideoCounts(activityInfo.ActivityId)
  42. // if err != nil {
  43. // return
  44. // }
  45. // go ActivityVideoUserRmind(user, activityId, 1)
  46. // return
  47. //}
  48. // 记录用户活动音频播放记录
  49. func AddActivityVideoHistory(user *models.WxUserItem, activityId, playSeconds int) {
  50. // 十分钟之内的合并
  51. key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ACTIVITYVIDEO + strconv.Itoa(activityId) + "_" + strconv.Itoa(user.UserId)
  52. if utils.Rc.IsExist(key) {
  53. return
  54. }
  55. utils.Rc.Put(key, 1, 10*time.Minute)
  56. var err error
  57. defer func() {
  58. if err != nil {
  59. go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddActivityVoiceHistory Err:", err.Error(), "活动ID:", activityId, "UserId:", user.UserId), 2)
  60. }
  61. }()
  62. activityVideoInfo, e := models.GetCygxActivityVideoByActivityId(activityId)
  63. if e != nil {
  64. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  65. return
  66. }
  67. item := new(models.CygxActivityVideoHistory)
  68. item.UserId = user.UserId
  69. item.RealName = user.RealName
  70. item.ActivityId = activityId
  71. item.VideoId = activityVideoInfo.VideoId
  72. item.PlaySeconds = strconv.Itoa(playSeconds)
  73. item.Mobile = user.Mobile
  74. item.Email = user.Email
  75. item.CompanyId = user.CompanyId
  76. item.CompanyName = user.CompanyName
  77. item.CreateTime = time.Now()
  78. item.ModifyTime = time.Now()
  79. item.RegisterPlatform = utils.REGISTER_PLATFORM
  80. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  81. if e != nil && e.Error() != utils.ErrNoRow() {
  82. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  83. return
  84. }
  85. if sellerItem != nil {
  86. item.SellerName = sellerItem.RealName
  87. }
  88. //添加记录
  89. e = models.AddCygxActivityVideoHistory(item)
  90. if e != nil {
  91. err = errors.New("AddCygxActivityVoiceHistory, Err: " + e.Error())
  92. return
  93. }
  94. //播放记录加1
  95. e = models.UpdateActivityVideoCounts(activityId)
  96. if e != nil {
  97. err = errors.New("UpdateCygxActivityVoiceCounts, Err: " + e.Error())
  98. return
  99. }
  100. //设置消息提醒
  101. go ActivityVideoUserRmind(user, activityId, 1)
  102. return
  103. }
  104. // 记录用户活动音频播放记录
  105. func AddActivityVoiceHistory(user *models.WxUserItem, activityId, playSeconds int) {
  106. key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ACTIVITYVOICE + strconv.Itoa(activityId) + "_" + strconv.Itoa(user.UserId)
  107. if utils.Rc.IsExist(key) {
  108. return
  109. }
  110. utils.Rc.Put(key, 1, 10*time.Minute)
  111. var err error
  112. defer func() {
  113. if err != nil {
  114. go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddActivityVoiceHistory Err:", err.Error(), "活动ID:", activityId, "UserId:", user.UserId), 2)
  115. }
  116. }()
  117. item := new(models.CygxActivityVoiceHistory)
  118. item.UserId = user.UserId
  119. item.RealName = user.RealName
  120. item.ActivityId = activityId
  121. item.PlaySeconds = strconv.Itoa(playSeconds)
  122. item.Mobile = user.Mobile
  123. item.Email = user.Email
  124. item.CompanyId = user.CompanyId
  125. item.CompanyName = user.CompanyName
  126. item.CreateTime = time.Now()
  127. item.ModifyTime = time.Now()
  128. item.RegisterPlatform = utils.REGISTER_PLATFORM
  129. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  130. if e != nil && e.Error() != utils.ErrNoRow() {
  131. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  132. return
  133. }
  134. if sellerItem != nil {
  135. item.SellerName = sellerItem.RealName
  136. }
  137. //添加记录
  138. e = models.AddCygxActivityVoiceHistory(item)
  139. if e != nil {
  140. err = errors.New("AddCygxActivityVoiceHistory, Err: " + e.Error())
  141. return
  142. }
  143. //播放记录加1
  144. e = models.UpdateCygxActivityVoiceCounts(activityId)
  145. if e != nil {
  146. err = errors.New("UpdateCygxActivityVoiceCounts, Err: " + e.Error())
  147. return
  148. }
  149. //设置消息提醒
  150. go ActivityVideoUserRmind(user, activityId, 2)
  151. return
  152. }