Browse Source

no message

xingzai 1 year ago
parent
commit
9ad1024252

+ 1 - 49
controllers/activity.go

@@ -3683,7 +3683,6 @@ func (this *ActivityCoAntroller) ActivityVoiceHistoryAdd() {
 		br.Ret = 408
 		return
 	}
-	uid := user.UserId
 	var req models.ActivityIdRep
 	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
 	if err != nil {
@@ -3706,55 +3705,8 @@ func (this *ActivityCoAntroller) ActivityVoiceHistoryAdd() {
 		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,
-		SellerName:  sellerName,
-		PlaySeconds: strconv.Itoa(req.PlaySeconds),
-		ModifyTime:  time.Now(),
-	}
 
-	if playSeconds != 0 {
-		lastItem, err := models.GetLastCygxActivityVoiceHistory(activityId, user.UserId)
-		if err != nil {
-			br.Msg = "操作失败"
-			br.ErrMsg = "操作失败,GetLastCygxActivityVoiceHistory Err:" + err.Error()
-			return
-		}
-		err = models.UpdateLastCygxActivityVoiceHistory(strconv.Itoa(req.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
-		}
-		err = models.UpdateCygxActivityVoiceCounts(activityId)
-		if err != nil {
-			br.Msg = "更新失败"
-			br.ErrMsg = "更新失败,Err:" + err.Error()
-			return
-		}
-		go services.ActivityVideoUserRmind(user, activityId, 2)
-	}
+	go services.AddActivityVoiceHistory(user, activityId, playSeconds)
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"

+ 0 - 5
controllers/micro_roadshow.go

@@ -261,11 +261,6 @@ func (this *MicroRoadShowController) VideoHistoryAdd() {
 	} else if sourceType == 2 {
 		//添加活动视频的播放记录
 		go services.AddActivityVideoHistory(user, sourceId, playSeconds)
-		//if err != nil {
-		//	br.Msg = "更新失败"
-		//	br.ErrMsg = "更新失败,AddActivityVideoHistory Err:" + err.Error()
-		//	return
-		//}
 	} else if sourceType == 3 {
 		item := models.CygxMicroRoadshowVideoHistory{
 			VideoId:     sourceId,

+ 21 - 0
models/activity_video_history.go

@@ -50,3 +50,24 @@ func UpdateCygxActivityVideoHistory(wxUser *WxUserItem) (err error) {
 	}
 	return
 }
+
+func GetLastCygxActivityVideoHistory(activityId, userId int) (item *CygxActivityVoiceHistory, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_activity_video_history WHERE activity_id=?  AND user_id=? AND register_platform = 1 ORDER BY create_time DESC limit 1 `
+	err = o.Raw(sql, activityId, userId).QueryRow(&item)
+	return
+}
+
+//func UpdateLastCygxActivityVideoHistory(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
+//}
+
+func UpdateLastCygxActivityVideoHistory(playSeconds string, lastId int) (err error) {
+	o := orm.NewOrm()
+	sql := ` UPDATE cygx_activity_video_history SET play_seconds =? WHERE id=? `
+	_, err = o.Raw(sql, playSeconds, lastId).Exec()
+	return
+}

+ 1 - 1
models/activity_voice_history.go

@@ -30,7 +30,7 @@ func AddCygxActivityVoiceHistory(item *CygxActivityVoiceHistory) (err error) {
 
 func GetLastCygxActivityVoiceHistory(activityId, userId int) (item *CygxActivityVoiceHistory, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM cygx_activity_voice_history WHERE activity_id=? AND user_id=? ORDER BY create_time DESC limit 1 `
+	sql := ` SELECT * FROM cygx_activity_voice_history WHERE activity_id=?  AND user_id=? AND register_platform = 1 ORDER BY create_time DESC limit 1 `
 	err = o.Raw(sql, activityId, userId).QueryRow(&item)
 	return
 }

+ 14 - 0
models/askserie_video_history_record.go

@@ -34,3 +34,17 @@ func UpdateAskserieVideoCounts(askserieVideoId int) (err error) {
 	_, err = o.Raw(sql, askserieVideoId).Exec()
 	return
 }
+
+func GetLastCygxAskserieVideoHistoryRecord(activityId, userId int) (item *CygxActivityVoiceHistory, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_askserie_video_history_record WHERE askserie_video_id=?  AND user_id=? AND register_platform = 1 ORDER BY create_time DESC limit 1 `
+	err = o.Raw(sql, activityId, userId).QueryRow(&item)
+	return
+}
+
+func UpdateLastCygxAskserieVideoHistoryRecord(playSeconds string, lastId int) (err error) {
+	o := orm.NewOrm()
+	sql := ` UPDATE cygx_askserie_video_history_record SET video_duration = ? WHERE id=? `
+	_, err = o.Raw(sql, playSeconds, lastId).Exec()
+	return
+}

+ 0 - 7
models/micro_roadshow.go

@@ -543,13 +543,6 @@ func GetHomeNewestListUnionCount(condition string, pars []interface{}) (count in
 	return
 }
 
-func UpdateLastCygxActivityVideoHistory(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
-}
-
 // MicroRoadshowVideo 微路演视频
 type MicroRoadshowVideo struct {
 	VideoId             int       `orm:"column(video_id);pk" description:"视频ID"`

+ 29 - 0
services/askserie_video.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
+	"strconv"
 	"time"
 )
 
@@ -47,6 +48,34 @@ func AddAskserieVideoHistoryRecord(user *models.WxUserItem, askserieVideoId, pla
 		err = errors.New("UpdateAskserieVideoCounts, 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.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
+		if e != nil {
+			err = errors.New("UpdateLastCygxActivityVideoHistory, Err: " + e.Error())
+			return
+		}
+		//播放记录加1
+		e = models.UpdateActivityVideoCounts(askserieVideoId)
+		if e != nil {
+			err = errors.New("UpdateActivityVideoCounts, Err: " + e.Error())
+			return
+		}
+	} else {
+		//添加记录
+		e = models.AddCygxActivityVideoHistory(item)
+		if e != nil {
+			err = errors.New("AddCygxActivityVideoHistory, Err: " + e.Error())
+			return
+		}
+	}
+
 	return
 }
 

+ 57 - 24
services/cygx_activity_video_history.go

@@ -48,16 +48,17 @@ import (
 //	return
 //}
 
-// 记录用户活动音频播放记录
+// 添加活动视频的播放记录
 func AddActivityVideoHistory(user *models.WxUserItem, activityId, playSeconds int) {
 	var err error
 	defer func() {
 		if err != nil {
-			go utils.SendAlarmMsg(fmt.Sprint("记录用户活动音频播放记录失败 AddActivityVoiceHistory Err:", err.Error(), "活动ID:", activityId, "UserId:", user.UserId), 2)
+			go utils.SendAlarmMsg(fmt.Sprint("添加活动视频的播放记录失败 AddActivityVideoHistory Err:", err.Error(), "活动ID:", activityId, "UserId:", user.UserId), 2)
 		}
 	}()
 	item := new(models.CygxActivityVideoHistory)
 	item.UserId = user.UserId
+	item.RealName = user.RealName
 	item.ActivityId = activityId
 	item.PlaySeconds = strconv.Itoa(playSeconds)
 	item.Mobile = user.Mobile
@@ -75,17 +76,33 @@ func AddActivityVideoHistory(user *models.WxUserItem, activityId, playSeconds in
 	if sellerItem != nil {
 		item.SellerName = sellerItem.RealName
 	}
-	//添加记录
-	e = models.AddCygxActivityVideoHistory(item)
-	if e != nil {
-		err = errors.New("AddCygxActivityVoiceHistory, Err: " + e.Error())
-		return
-	}
-	//播放记录加1
-	e = models.UpdateActivityVideoCounts(activityId)
-	if e != nil {
-		err = errors.New("UpdateCygxActivityVoiceCounts, Err: " + e.Error())
-		return
+
+	//小程序端的回传两次,第一次没有播放时长,第二次有播放时长
+	if playSeconds != 0 {
+		lastItem, e := models.GetLastCygxActivityVideoHistory(activityId, user.UserId)
+		if e != nil {
+			err = errors.New("GetLastCygxActivityVideoHistory, Err: " + e.Error())
+			return
+		}
+		//更新播放时间
+		e = models.UpdateLastCygxActivityVideoHistory(strconv.Itoa(playSeconds), lastItem.Id)
+		if e != nil {
+			err = errors.New("UpdateLastCygxActivityVideoHistory, Err: " + e.Error())
+			return
+		}
+		//播放记录加1
+		e = models.UpdateActivityVideoCounts(activityId)
+		if e != nil {
+			err = errors.New("UpdateActivityVideoCounts, Err: " + e.Error())
+			return
+		}
+	} else {
+		//添加记录
+		e = models.AddCygxActivityVideoHistory(item)
+		if e != nil {
+			err = errors.New("AddCygxActivityVideoHistory, Err: " + e.Error())
+			return
+		}
 	}
 	//设置消息提醒
 	go ActivityVideoUserRmind(user, activityId, 1)
@@ -102,6 +119,7 @@ func AddActivityVoiceHistory(user *models.WxUserItem, activityId, playSeconds in
 	}()
 	item := new(models.CygxActivityVoiceHistory)
 	item.UserId = user.UserId
+	item.RealName = user.RealName
 	item.ActivityId = activityId
 	item.PlaySeconds = strconv.Itoa(playSeconds)
 	item.Mobile = user.Mobile
@@ -119,18 +137,33 @@ func AddActivityVoiceHistory(user *models.WxUserItem, activityId, playSeconds in
 	if sellerItem != nil {
 		item.SellerName = sellerItem.RealName
 	}
-	//添加记录
-	e = models.AddCygxActivityVoiceHistory(item)
-	if e != nil {
-		err = errors.New("AddCygxActivityVoiceHistory, Err: " + e.Error())
-		return
-	}
-	//播放记录加1
-	e = models.UpdateCygxActivityVoiceCounts(activityId)
-	if e != nil {
-		err = errors.New("UpdateCygxActivityVoiceCounts, Err: " + e.Error())
-		return
+	//小程序端的回传两次,第一次没有播放时长,第二次有播放时长
+	if playSeconds != 0 {
+		lastItem, e := models.GetLastCygxActivityVoiceHistory(activityId, user.UserId)
+		if e != nil {
+			err = errors.New("GetLastCygxActivityVoiceHistory, Err: " + e.Error())
+			return
+		}
+		e = models.UpdateLastCygxActivityVoiceHistory(strconv.Itoa(playSeconds), lastItem.Id)
+		if e != nil {
+			err = errors.New("UpdateLastCygxActivityVoiceHistory, Err: " + e.Error())
+			return
+		}
+		//播放记录加1
+		e = models.UpdateCygxActivityVoiceCounts(activityId)
+		if e != nil {
+			err = errors.New("UpdateCygxActivityVoiceCounts, Err: " + e.Error())
+			return
+		}
+	} else {
+		//添加记录
+		e = models.AddCygxActivityVoiceHistory(item)
+		if e != nil {
+			err = errors.New("AddCygxActivityVoiceHistory, Err: " + e.Error())
+			return
+		}
 	}
+
 	//设置消息提醒
 	go ActivityVideoUserRmind(user, activityId, 2)
 	return