package services import ( "errors" "fmt" "hongze/hongze_clpt/models" "hongze/hongze_clpt/utils" "strconv" "time" ) // 添加活动的视频播放记录 //func AddActivityVideoHistory(user *models.WxUserItem, activityId int) (err error) { // activityInfo, errInfo := models.GetCygxActivityVideoByActivityId(activityId) // if activityInfo == nil { // return // } // if errInfo != nil { // return // } // var sellerName string // sellerName, err = models.GetCompanySellerName(user.CompanyId) // if err != nil { // return // } // item := models.CygxActivityVideoHistory{ // ActivityId: activityInfo.ActivityId, // VideoId: activityInfo.VideoId, // UserId: user.UserId, // CreateTime: time.Now(), // Mobile: user.Mobile, // Email: user.Email, // CompanyId: user.CompanyId, // CompanyName: user.CompanyName, // RealName: user.RealName, // SellerName: sellerName, // ModifyTime: time.Now(), // } // err = models.AddCygxActivityVideoHistory(&item) // if err != nil { // return // } // err = models.UpdateActivityVideoCounts(activityInfo.ActivityId) // if err != nil { // return // } // go ActivityVideoUserRmind(user, activityId, 1) // return //} // 记录用户活动音频播放记录 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("记录用户活动音频播放记录失败 AddActivityVoiceHistory 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("AddCygxActivityVoiceHistory, Err: " + e.Error()) return } //播放记录加1 e = models.UpdateActivityVideoCounts(activityId) if e != nil { err = errors.New("UpdateCygxActivityVoiceCounts, Err: " + e.Error()) return } //设置消息提醒 go ActivityVideoUserRmind(user, activityId, 1) return } // 记录用户活动音频播放记录 func AddActivityVoiceHistory(user *models.WxUserItem, activityId, playSeconds int) { key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ACTIVITYVOICE + 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("记录用户活动音频播放记录失败 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 } //添加记录 e = models.AddCygxActivityVoiceHistory(item) if e != nil { err = errors.New("AddCygxActivityVoiceHistory, Err: " + e.Error()) return } //播放记录加1 e = models.UpdateCygxActivityVoiceCounts(activityId) if e != nil { err = errors.New("UpdateCygxActivityVoiceCounts, Err: " + e.Error()) return } //设置消息提醒 go ActivityVideoUserRmind(user, activityId, 2) return }