askserie_video.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 AddAskserieVideoHistoryRecord(user *models.WxUserItem, askserieVideoId, playSeconds int) {
  12. // 十分钟之内的合并
  13. key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ASKSERIEVIDEO + strconv.Itoa(askserieVideoId) + "_" + 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("记录用户活动音频播放记录失败 AddAskserieVideoHistoryRecord Err:", err.Error(), "askserieVideoId:", askserieVideoId, "UserId:", user.UserId), 2)
  22. }
  23. }()
  24. item := new(models.CygxAskserieVideoHistoryRecord)
  25. item.UserId = user.UserId
  26. item.RealName = user.RealName
  27. item.AskserieVideoId = askserieVideoId
  28. item.VideoDuration = playSeconds
  29. item.Mobile = user.Mobile
  30. item.Email = user.Email
  31. item.CompanyId = user.CompanyId
  32. item.CompanyName = user.CompanyName
  33. item.CreateTime = time.Now()
  34. item.ModifyTime = time.Now()
  35. item.RegisterPlatform = utils.REGISTER_PLATFORM
  36. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  37. if e != nil && e.Error() != utils.ErrNoRow() {
  38. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  39. return
  40. }
  41. if sellerItem != nil {
  42. item.SellerName = sellerItem.RealName
  43. }
  44. //添加记录
  45. e = models.AddCygxAskserieVideoHistoryRecord(item)
  46. if e != nil {
  47. err = errors.New("AddCygxAskserieVideoHistoryRecord, Err: " + e.Error())
  48. return
  49. }
  50. //播放记录加1
  51. e = models.UpdateAskserieVideoCounts(askserieVideoId)
  52. if e != nil {
  53. err = errors.New("UpdateAskserieVideoCounts, Err: " + e.Error())
  54. return
  55. }
  56. return
  57. }
  58. // 系列问答视频留言记录
  59. func AddCygxAskserieVideoCollection(user *models.WxUserItem, askserieVideoId int, content string) {
  60. var err error
  61. defer func() {
  62. if err != nil {
  63. go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddAskserieVideoHistoryRecord Err:", err.Error(), "askserieVideoId:", askserieVideoId, "UserId:", user.UserId), 2)
  64. }
  65. }()
  66. item := new(models.CygxAskserieVideoCollection)
  67. item.UserId = user.UserId
  68. item.RealName = user.RealName
  69. item.AskserieVideoId = askserieVideoId
  70. item.Content = content
  71. item.Mobile = user.Mobile
  72. item.Email = user.Email
  73. item.CompanyId = user.CompanyId
  74. item.CompanyName = user.CompanyName
  75. item.CreateTime = time.Now()
  76. item.ModifyTime = time.Now()
  77. item.RegisterPlatform = utils.REGISTER_PLATFORM
  78. sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  79. if e != nil && e.Error() != utils.ErrNoRow() {
  80. err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
  81. return
  82. }
  83. if sellerItem != nil {
  84. item.SellerName = sellerItem.RealName
  85. }
  86. //添加记录
  87. e = models.AddCygxAskserieVideoCollection(item)
  88. if e != nil {
  89. err = errors.New("AddCygxAskserieVideoCollection, Err: " + e.Error())
  90. return
  91. }
  92. //播放记录加1
  93. e = models.UpdateAskserieVideoCommentNum(askserieVideoId)
  94. if e != nil {
  95. err = errors.New("UpdateAskserieVideoCommentNum, Err: " + e.Error())
  96. return
  97. }
  98. return
  99. }