package services import ( "errors" "fmt" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/utils" "strconv" "time" ) // 记录用户活动音频播放记录 func AddActivityVideoHistory(user *models.WxUserItem, activityId, playSeconds int, inviteShareCode string) { // 十分钟之内的合并 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 } //播放记录加1 e = models.UpdateActivityVideoCounts(activityId) if e != nil { err = errors.New("UpdateActivityVideoCounts, Err: " + e.Error()) return } //设置消息提醒 go ActivityVideoUserRmind(user, activityId, 1) go AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_ACTIVITYVIDEO, activityVideoInfo.VideoName, inviteShareCode, activityId) return } // 记录用户活动音频播放记录 func AddActivityVoiceHistory(user *models.WxUserItem, activityId, playSeconds int, inviteShareCode string) { 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 } activityVoiceInfo, e := models.GetCygxActivityVoiceByActivityId(activityId) if e != nil { err = errors.New("GetCygxActivityVoiceByActivityId, Err: " + e.Error()) return } if !utils.Rc.IsExist(key) { //添加记录 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 } utils.Rc.Put(key, 1, 10*time.Minute) //设置消息提醒 go ActivityVideoUserRmind(user, activityId, 2) go AddCygxUserAdminShareHistory(user, utils.CYGX_OBJ_ACTIVITYVOICE, activityVoiceInfo.VoiceName, inviteShareCode, activityId) } 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 }