|
@@ -1,105 +1 @@
|
|
|
package services
|
|
|
-
|
|
|
-import (
|
|
|
- "errors"
|
|
|
- "fmt"
|
|
|
- "hongze/hongze_mfyx/models"
|
|
|
- "hongze/hongze_mfyx/utils"
|
|
|
- "strconv"
|
|
|
- "time"
|
|
|
-)
|
|
|
-
|
|
|
-// 记录用户活动音频播放记录
|
|
|
-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
|
|
|
- }
|
|
|
- //播放记录加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)
|
|
|
- } 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
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //小程序端的回传两次,第一次没有播放时长,第二次有播放时长
|
|
|
- //if playSeconds != 0 {
|
|
|
- // 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
|
|
|
- // }
|
|
|
- // utils.Rc.Put(key, 1, 10*time.Second)
|
|
|
- //} else {
|
|
|
- // //添加记录
|
|
|
- // 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
|
|
|
-}
|