Browse Source

新增音视频历史接口

ziwen 2 years ago
parent
commit
2fa0b06731
4 changed files with 59 additions and 33 deletions
  1. 7 6
      controllers/activity.go
  2. 16 25
      controllers/micro_roadshow.go
  3. 2 2
      models/activity_voice_history.go
  4. 34 0
      models/micro_roadshow.go

+ 7 - 6
controllers/activity.go

@@ -4943,12 +4943,13 @@ func (this *ActivityCoAntroller) ActivityVoiceHistoryAdd() {
 			br.ErrMsg = "更新失败,UpdateLastCygxActivityVoiceHistory Err:" + err.Error()
 			return
 		}
-	}
-	err = models.AddCygxActivityVoiceHistory(&item)
-	if err != nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "操作失败,Err:" + err.Error()
-		return
+	} else {
+		err = models.AddCygxActivityVoiceHistory(&item)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,Err:" + err.Error()
+			return
+		}
 	}
 	br.Ret = 200
 	br.Success = true

+ 16 - 25
controllers/micro_roadshow.go

@@ -1,10 +1,12 @@
 package controllers
 
 import (
+	"encoding/json"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/services"
 	"hongze/hongze_cygx/utils"
+	"time"
 )
 
 // 微路演
@@ -84,7 +86,7 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 		return
 	}
 	uid := user.UserId
-	var req models.ActivityIdRep
+	var req models.AddVideoHistoryReq
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
 		br.Msg = "参数解析异常!"
@@ -92,20 +94,9 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 		return
 	}
 
-	activityId := req.ActivityId
+	videoId := req.VideoId
 	playSeconds := req.PlaySeconds
 
-	activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
-	if activityInfo == nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
-		return
-	}
-	if errInfo != nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "操作失败,Err:" + errInfo.Error()
-		return
-	}
 	var sellerName string
 	sellerName, err = models.GetCompanySellerName(user.CompanyId)
 	if err != nil {
@@ -113,26 +104,25 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 		br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
 		return
 	}
-	item := models.CygxActivityVoiceHistory{
-		ActivityId:  activityId,
+	item := models.CygxMicroRoadshowVideoHistory{
+		VideoId:     videoId,
 		UserId:      uid,
-		CreateTime:  time.Now(),
 		Mobile:      user.Mobile,
 		Email:       user.Email,
 		CompanyId:   user.CompanyId,
 		CompanyName: user.CompanyName,
 		RealName:    user.RealName,
-		SellerId:    0,
 		SellerName:  sellerName,
 		PlaySeconds: playSeconds,
+		CreateTime:  time.Now(),
 		ModifyTime:  time.Now(),
 	}
 
 	if playSeconds != ""{
-		lastItem, err := models.GetLastCygxActivityVoiceHistory(activityId)
+		lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId)
 		if err != nil {
 			br.Msg = "操作失败"
-			br.ErrMsg = "操作失败,GetLastCygxActivityVoiceHistory Err:" + err.Error()
+			br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
 			return
 		}
 		err = models.UpdateLastCygxActivityVoiceHistory(playSeconds, lastItem.Id)
@@ -141,12 +131,13 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 			br.ErrMsg = "更新失败,UpdateLastCygxActivityVoiceHistory Err:" + err.Error()
 			return
 		}
-	}
-	err = models.AddCygxActivityVoiceHistory(&item)
-	if err != nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "操作失败,Err:" + err.Error()
-		return
+	} else {
+		err = models.AddCygxMicroRoadshowVideoHistory(&item)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,Err:" + err.Error()
+			return
+		}
 	}
 	br.Ret = 200
 	br.Success = true

+ 2 - 2
models/activity_voice_history.go

@@ -30,14 +30,14 @@ func AddCygxActivityVoiceHistory(item *CygxActivityVoiceHistory) (err error) {
 
 func GetLastCygxActivityVoiceHistory(activityId int) (item *CygxActivityVoiceHistory, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM cygx_micro_roadshow_video_history WHERE activity_id=? ORDER BY create_time DESC limit 1 `
+	sql := ` SELECT * FROM cygx_activity_voice_history WHERE activity_id=? ORDER BY create_time DESC limit 1 `
 	err = o.Raw(sql, activityId).QueryRow(&item)
 	return
 }
 
 func UpdateLastCygxActivityVoiceHistory(playSeconds string, lastId int) (err error) {
 	o := orm.NewOrm()
-	sql := ` UPDATE cygx_micro_roadshow_video_history SET play_seconds =? WHERE id=? `
+	sql := ` UPDATE cygx_activity_voice_history SET play_seconds =? WHERE id=? `
 	_, err = o.Raw(sql, playSeconds, lastId).Exec()
 	return
 }

+ 34 - 0
models/micro_roadshow.go

@@ -3,6 +3,7 @@ package models
 import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"time"
 )
 
 // MicroRoadShowListResp 微路演列表响应体
@@ -87,3 +88,36 @@ func GetMicroRoadShowVideoPageList(startSize, pageSize int, condition string, pa
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
 	return
 }
+
+type AddVideoHistoryReq struct {
+	VideoId int  `description:"视频ID"`
+	PlaySeconds string `description:"播放时长"`
+}
+
+type CygxMicroRoadshowVideoHistory struct {
+	Id          int       `orm:"column(id);pk"description:"微路演视频浏览记录表id"`
+	VideoId     int       `description:"微路演视频id"`
+	UserId      int       `description:"用户id"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司Id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName  string    `description:"所属销售"`
+	PlaySeconds string    `description:"播放时间 单位s"`
+	CreateTime  time.Time `description:"视频创建时间"`
+	ModifyTime  time.Time `description:"视频修改时间"`
+}
+
+func GetLastCygxMicroRoadshowVideoHistory(videoId int) (item *CygxMicroRoadshowVideoHistory, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_micro_roadshow_video_history WHERE video_id=? ORDER BY create_time DESC limit 1 `
+	err = o.Raw(sql, videoId).QueryRow(&item)
+	return
+}
+
+func AddCygxMicroRoadshowVideoHistory(item *CygxMicroRoadshowVideoHistory) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}