cygx_activity_video_history.go 4.5 KB

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