Sfoglia il codice sorgente

Merge branch '7.6_local' into cygx/7.6

ziwen 2 anni fa
parent
commit
6170c1b2ba

+ 38 - 15
controllers/activity.go

@@ -4893,7 +4893,10 @@ func (this *ActivityCoAntroller) ActivityVoiceHistoryAdd() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
+
 	activityId := req.ActivityId
+	playSeconds := req.PlaySeconds
+
 	activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
 	if activityInfo == nil {
 		br.Msg = "操作失败"
@@ -4912,21 +4915,41 @@ func (this *ActivityCoAntroller) ActivityVoiceHistoryAdd() {
 		br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
 		return
 	}
-	item := new(models.CygxActivityVoiceHistory)
-	item.UserId = uid
-	item.ActivityId = activityId
-	item.CreateTime = time.Now()
-	item.Mobile = user.Mobile
-	item.Email = user.Email
-	item.CompanyId = user.CompanyId
-	item.CompanyName = user.CompanyName
-	item.SellerName = sellerName
-	item.RealName = user.RealName
-	err = models.AddCygxActivityVoiceHistory(item)
-	if err != nil {
-		br.Msg = "操作失败"
-		br.ErrMsg = "操作失败,Err:" + err.Error()
-		return
+	item := models.CygxActivityVoiceHistory{
+		ActivityId:  activityId,
+		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,
+		ModifyTime:  time.Now(),
+	}
+
+	if playSeconds != ""{
+		lastItem, err := models.GetLastCygxActivityVoiceHistory(activityId)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,GetLastCygxActivityVoiceHistory Err:" + err.Error()
+			return
+		}
+		err = models.UpdateLastCygxActivityVoiceHistory(playSeconds, lastItem.Id)
+		if err != nil {
+			br.Msg = "更新失败"
+			br.ErrMsg = "更新失败,UpdateLastCygxActivityVoiceHistory 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

+ 80 - 0
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"
 )
 
 // 微路演
@@ -64,3 +66,81 @@ func (this *MicroRoadShowController) List() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 记录用户浏览音频回放接口
+// @Description 记录用户浏览音频回放接口
+// @Param	request	body models.ActivityIdRep true "type json string"
+// @Success Ret=200 {object} models.AppointmentResp
+// @router /videoHistory/add [post]
+func (this *MicroRoadShowController) VideoHistoryAdd() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	uid := user.UserId
+	var req models.AddVideoHistoryReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	videoId := req.VideoId
+	playSeconds := req.PlaySeconds
+
+	var sellerName string
+	sellerName, err = models.GetCompanySellerName(user.CompanyId)
+	if err != nil {
+		br.Msg = "报名失败!"
+		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: playSeconds,
+		CreateTime:  time.Now(),
+		ModifyTime:  time.Now(),
+	}
+
+	if playSeconds != ""{
+		lastItem, err := models.GetLastCygxMicroRoadshowVideoHistory(videoId)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,GetLastCygxMicroRoadshowVideoHistory Err:" + err.Error()
+			return
+		}
+		err = models.UpdateLastCygxActivityVoiceHistory(playSeconds, lastItem.Id)
+		if err != nil {
+			br.Msg = "更新失败"
+			br.ErrMsg = "更新失败,UpdateLastCygxActivityVoiceHistory 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
+	br.Msg = "操作成功"
+	return
+}

+ 1 - 0
models/activity.go

@@ -75,6 +75,7 @@ type Activity struct {
 }
 type ActivityIdRep struct {
 	ActivityId int `description:"活动id"`
+	PlaySeconds string `description:"播放时长"`
 }
 
 type ActivitySingnupRep struct {

+ 18 - 1
models/activity_voice_history.go

@@ -15,7 +15,10 @@ type CygxActivityVoiceHistory struct {
 	CompanyId   int       `description:"公司id"`
 	CompanyName string    `description:"公司名称"`
 	RealName    string    `description:"用户实际名称"`
-	SellerName  string    `description:"所属销售"`
+	SellerId        int       `description:"所属销售id"`
+	SellerName      string    `description:"所属销售"`
+	PlaySeconds     string    `description:"播放时间 单位s"`
+	ModifyTime      time.Time `description:"视频修改时间"`
 }
 
 //添加
@@ -24,3 +27,17 @@ func AddCygxActivityVoiceHistory(item *CygxActivityVoiceHistory) (err error) {
 	_, err = o.Insert(item)
 	return
 }
+
+func GetLastCygxActivityVoiceHistory(activityId int) (item *CygxActivityVoiceHistory, err error) {
+	o := orm.NewOrm()
+	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_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
+}