浏览代码

记录视频阅读记录(微路演、活动视频)

xingzai 2 年之前
父节点
当前提交
555eabcc10
共有 4 个文件被更改,包括 100 次插入34 次删除
  1. 46 34
      controllers/micro_roadshow.go
  2. 7 0
      models/activity_video.go
  3. 1 0
      models/micro_roadshow.go
  4. 46 0
      services/cygx_activity_video_history.go

+ 46 - 34
controllers/micro_roadshow.go

@@ -161,7 +161,11 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 
 	videoId := req.VideoId
 	playSeconds := req.PlaySeconds
+	sourceType := req.SourceType
 
+	if sourceType == 0 {
+		sourceType = 1
+	}
 	var sellerName string
 	sellerName, err = models.GetCompanySellerName(user.CompanyId)
 	if err != nil {
@@ -169,44 +173,52 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 		br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
 		return
 	}
-	item := models.CygxMicroRoadshowVideoHistory{
-		VideoId:     videoId,
-		UserId:      uid,
-		Mobile:      user.Mobile,
-		Email:       user.Email,
-		CompanyId:   user.CompanyId,
-		CompanyName: user.CompanyName,
-		RealName:    user.RealName,
-		SellerName:  sellerName,
-		PlaySeconds: strconv.Itoa(playSeconds),
-		CreateTime:  time.Now(),
-		ModifyTime:  time.Now(),
-	}
-
-	if playSeconds != 0 {
-		lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
-		if err != nil {
-			br.Msg = "操作失败"
-			br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
-			return
-		}
-		err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
-		if err != nil {
-			br.Msg = "更新失败"
-			br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
-			return
+	if sourceType == 1 {
+		item := models.CygxMicroRoadshowVideoHistory{
+			VideoId:     videoId,
+			UserId:      uid,
+			Mobile:      user.Mobile,
+			Email:       user.Email,
+			CompanyId:   user.CompanyId,
+			CompanyName: user.CompanyName,
+			RealName:    user.RealName,
+			SellerName:  sellerName,
+			PlaySeconds: strconv.Itoa(playSeconds),
+			CreateTime:  time.Now(),
+			ModifyTime:  time.Now(),
 		}
-	} else {
-		err = models.AddCygxMicroRoadshowVideoHistory(&item)
-		if err != nil {
-			br.Msg = "操作失败"
-			br.ErrMsg = "操作失败,Err:" + err.Error()
-			return
+		if playSeconds != 0 {
+			lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId, user.UserId)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
+				return
+			}
+			err = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
+			if err != nil {
+				br.Msg = "更新失败"
+				br.ErrMsg = "更新失败,UpdateLastCygxActivityVideoHistory Err:" + err.Error()
+				return
+			}
+		} else {
+			err = models.AddCygxMicroRoadshowVideoHistory(&item)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,Err:" + err.Error()
+				return
+			}
+			err = models.UpdateCygxActivityVideoCounts(videoId)
+			if err != nil {
+				br.Msg = "更新失败"
+				br.ErrMsg = "更新失败,Err:" + err.Error()
+				return
+			}
 		}
-		err = models.UpdateCygxActivityVideoCounts(videoId)
+	} else if sourceType == 2 {
+		err = services.AddActivityVideoHistory(user, videoId)
 		if err != nil {
 			br.Msg = "更新失败"
-			br.ErrMsg = "更新失败,Err:" + err.Error()
+			br.ErrMsg = "更新失败,AddActivityVideoHistory Err:" + err.Error()
 			return
 		}
 	}

+ 7 - 0
models/activity_video.go

@@ -62,3 +62,10 @@ func GetCygxActivityVideoByActivityId(activityId int) (item *CygxActivityVideo,
 	err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
 	return
 }
+
+// GetCygxActivityVideoById 获取活动视频
+func GetCygxActivityVideoById(activityId int) (item *CygxActivityVideo, err error) {
+	sql := `SELECT * FROM cygx_activity_video WHERE video_id = ? LIMIT 1 `
+	err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
+	return
+}

+ 1 - 0
models/micro_roadshow.go

@@ -98,6 +98,7 @@ func GetMicroRoadShowVideoPageList(startSize, pageSize int, condition string, pa
 type AddVideoHistoryReq struct {
 	VideoId     int `description:"视频ID"`
 	PlaySeconds int `description:"播放时长"`
+	SourceType  int `description:"视频来源: 1-微路演; 2-活动 (不传默认为1)"`
 }
 
 type CygxMicroRoadshowVideoHistory struct {

+ 46 - 0
services/cygx_activity_video_history.go

@@ -0,0 +1,46 @@
+package services
+
+import (
+	"hongze/hongze_cygx/models"
+	"time"
+)
+
+//添加活动的视频播放记录
+func AddActivityVideoHistory(user *models.WxUserItem, videoId int) (err error) {
+	activityInfo, errInfo := models.GetCygxActivityVideoById(videoId)
+	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
+	}
+
+	return
+}