123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "strconv"
- "time"
- )
- func AddActivityVideoHistory(user *models.WxUserItem, activityId, playSeconds int) {
-
- key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ACTIVITYVIDEO + strconv.Itoa(activityId) + "_" + strconv.Itoa(user.UserId)
- if utils.Rc.IsExist(key) {
- return
- }
- utils.Rc.Put(key, 1, 10*time.Minute)
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("添加活动视频的播放记录失败 AddActivityVideoHistory Err:", err.Error(), "活动ID:", activityId, "UserId:", user.UserId), 2)
- }
- }()
- activityVideoInfo, e := models.GetCygxActivityVideoByActivityId(activityId)
- if e != nil {
- err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
- return
- }
- item := new(models.CygxActivityVideoHistory)
- item.UserId = user.UserId
- item.RealName = user.RealName
- item.ActivityId = activityId
- item.VideoId = activityVideoInfo.VideoId
- item.PlaySeconds = strconv.Itoa(playSeconds)
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
- return
- }
- if sellerItem != nil {
- item.SellerName = sellerItem.RealName
- }
-
- e = models.AddCygxActivityVideoHistory(item)
- if e != nil {
- err = errors.New("AddCygxActivityVideoHistory, Err: " + e.Error())
- return
- }
-
- e = models.UpdateActivityVideoCounts(activityId)
- if e != nil {
- err = errors.New("UpdateActivityVideoCounts, Err: " + e.Error())
- return
- }
-
- go ActivityVideoUserRmind(user, activityId, 1)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return
- }
- func AddActivityVoiceHistory(user *models.WxUserItem, activityId, playSeconds int) {
- if playSeconds == 0 {
- return
- }
- key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ACTIVITYVOICE + strconv.Itoa(activityId) + "_" + strconv.Itoa(user.UserId)
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddActivityVoiceHistory Err:", err.Error(), "活动ID:", activityId, "UserId:", user.UserId), 2)
- }
- }()
- item := new(models.CygxActivityVoiceHistory)
- item.UserId = user.UserId
- item.RealName = user.RealName
- item.ActivityId = activityId
- item.PlaySeconds = strconv.Itoa(playSeconds)
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- item.RegisterPlatform = utils.REGISTER_PLATFORM
- sellerItem, e := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetSellerByCompanyIdCheckFicc, Err: " + e.Error())
- return
- }
- if sellerItem != nil {
- item.SellerName = sellerItem.RealName
- }
- if !utils.Rc.IsExist(key) {
-
- e = models.AddCygxActivityVoiceHistory(item)
- if e != nil {
- err = errors.New("AddCygxActivityVoiceHistory, Err: " + e.Error())
- return
- }
-
- e = models.UpdateCygxActivityVoiceCounts(activityId)
- if e != nil {
- err = errors.New("UpdateCygxActivityVoiceCounts, Err: " + e.Error())
- return
- }
- utils.Rc.Put(key, 1, 10*time.Minute)
-
- go ActivityVideoUserRmind(user, activityId, 2)
- } else {
- lastItem, e := models.GetLastCygxActivityVoiceHistory(activityId, user.UserId)
- if e != nil {
- err = errors.New("GetLastCygxActivityVoiceHistory, Err: " + e.Error())
- return
- }
- e = models.UpdateLastCygxActivityVoiceHistory(strconv.Itoa(playSeconds), lastItem.Id)
- if e != nil {
- err = errors.New("UpdateLastCygxActivityVoiceHistory, Err: " + e.Error())
- return
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return
- }
|