ziwen 2 rokov pred
rodič
commit
6588f0dde3

+ 33 - 11
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,17 +4915,36 @@ 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)
+	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
+		}
+	}
+	err = models.AddCygxActivityVoiceHistory(&item)
 	if err != nil {
 		br.Msg = "操作失败"
 		br.ErrMsg = "操作失败,Err:" + err.Error()

+ 89 - 0
controllers/micro_roadshow.go

@@ -64,3 +64,92 @@ 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.ActivityIdRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	activityId := req.ActivityId
+	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 {
+		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
+		}
+	}
+	err = models.AddCygxActivityVoiceHistory(&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_micro_roadshow_video_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=? `
+	_, err = o.Raw(sql, playSeconds, lastId).Exec()
+	return
+}