123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package services
- import (
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/utils"
- "strconv"
- "time"
- )
- // 记录用户活动音频播放记录
- func AddAskserieVideoHistoryRecord(user *models.WxUserItem, askserieVideoId, playSeconds int) {
- if playSeconds == 0 {
- return
- }
- key := utils.CYGX_VIDEO_HISTORY_KEY + utils.CYGX_OBJ_ASKSERIEVIDEO + strconv.Itoa(askserieVideoId) + "_" + strconv.Itoa(user.UserId)
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddAskserieVideoHistoryRecord Err:", err.Error(), "askserieVideoId:", askserieVideoId, "UserId:", user.UserId), 2)
- }
- }()
- item := new(models.CygxAskserieVideoHistoryRecord)
- item.UserId = user.UserId
- item.RealName = user.RealName
- item.AskserieVideoId = askserieVideoId
- item.VideoDuration = playSeconds
- item.Mobile = user.Mobile
- item.Email = user.Email
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.CreateTime = time.Now().Add(-time.Duration(playSeconds) * time.Second) //减去观看时长当做,阅读时间
- 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
- }
- fmt.Println(utils.Rc.IsExist(key))
- if !utils.Rc.IsExist(key) {
- fmt.Println("添加")
- //添加记录
- e = models.AddCygxAskserieVideoHistoryRecord(item)
- if e != nil {
- err = errors.New("AddCygxAskserieVideoHistoryRecord, Err: " + e.Error())
- return
- }
- //播放记录加1
- e = models.UpdateAskserieVideoCounts(askserieVideoId)
- if e != nil {
- err = errors.New("UpdateActivityVideoCounts, Err: " + e.Error())
- return
- }
- utils.Rc.Put(key, 1, 10*time.Minute)
- } else {
- fmt.Println("更新")
- //更新停留时长
- lastItem, e := models.GetLastCygxAskserieVideoHistoryRecord(askserieVideoId, user.UserId)
- if e != nil {
- err = errors.New("GetLastCygxActivityVideoHistory, Err: " + e.Error())
- return
- }
- //更新播放时间
- e = models.UpdateLastCygxAskserieVideoHistoryRecord(strconv.Itoa(playSeconds), lastItem.Id)
- if e != nil {
- err = errors.New("UpdateLastCygxAskserieVideoHistoryRecord, Err: " + e.Error())
- return
- }
- }
- //if playSeconds != 0 {
- // //lastItem, e := models.GetLastCygxAskserieVideoHistoryRecord(askserieVideoId, user.UserId)
- // //if e != nil {
- // // err = errors.New("GetLastCygxActivityVideoHistory, Err: " + e.Error())
- // // return
- // //}
- // ////更新播放时间
- // //e = models.UpdateLastCygxAskserieVideoHistoryRecord(strconv.Itoa(playSeconds), lastItem.Id)
- // //if e != nil {
- // // err = errors.New("UpdateLastCygxAskserieVideoHistoryRecord, Err: " + e.Error())
- // // return
- // //}
- //
- //} else {
- // //添加记录
- // e = models.AddCygxAskserieVideoHistoryRecord(item)
- // if e != nil {
- // err = errors.New("AddCygxAskserieVideoHistoryRecord, Err: " + e.Error())
- // return
- // }
- // //播放记录加1
- // e = models.UpdateAskserieVideoCounts(askserieVideoId)
- // if e != nil {
- // err = errors.New("UpdateActivityVideoCounts, Err: " + e.Error())
- // return
- // }
- //}
- return
- }
- // 系列问答视频留言记录
- func AddCygxAskserieVideoCollection(user *models.WxUserItem, askserieVideoId int, content string) {
- var err error
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddAskserieVideoHistoryRecord Err:", err.Error(), "askserieVideoId:", askserieVideoId, "UserId:", user.UserId), 2)
- }
- }()
- item := new(models.CygxAskserieVideoCollection)
- item.UserId = user.UserId
- item.RealName = user.RealName
- item.AskserieVideoId = askserieVideoId
- item.Content = content
- 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.AddCygxAskserieVideoCollection(item)
- if e != nil {
- err = errors.New("AddCygxAskserieVideoCollection, Err: " + e.Error())
- return
- }
- //播放记录加1
- e = models.UpdateAskserieVideoCommentNum(askserieVideoId)
- if e != nil {
- err = errors.New("UpdateAskserieVideoCommentNum, Err: " + e.Error())
- return
- }
- return
- }
|