Browse Source

新增接口

ziwen 2 years ago
parent
commit
15dcc05307

+ 222 - 0
controllers/report.go

@@ -3088,3 +3088,225 @@ func (this *ReportController) CommentAdd() {
 	br.Success = true
 	br.Msg = "提交成功"
 }
+
+// @Title 记录用户浏览音频回放接口
+// @Description 记录用户浏览音频回放接口
+// @Param	request	body models.ArticleIdReq true "type json string"
+// @Success Ret=200 操作成功
+// @router /voiceHistory/add [post]
+func (this *ReportController) ResearchSummaryVoiceHistoryAdd() {
+	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.ArticleIdReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	articleId := req.ArticleId
+	playSeconds := req.PlaySeconds
+	pageRouter := req.PageRouter
+
+	if pageRouter == "本周研究汇总" {
+		articleInfo, errInfo := models.GetCygxResearchSummaryInfoById(articleId)
+		if articleInfo == nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "文章ID错误,不存在articleId:" + strconv.Itoa(articleId)
+			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.CygxResearchSummaryVoiceHistory{
+			ArticleId:  articleId,
+			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.GetLastCygxResearchSummaryVoiceHistory(articleId, user.UserId)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,GetLastCygxResearchSummaryVoiceHistory Err:" + err.Error()
+				return
+			}
+			err = models.UpdateLastCygxResearchSummaryVoiceHistory(strconv.Itoa(req.PlaySeconds), lastItem.Id)
+			if err != nil {
+				br.Msg = "更新失败"
+				br.ErrMsg = "更新失败,UpdateLastCygxResearchSummaryVoiceHistory Err:" + err.Error()
+				return
+			}
+		} else {
+			err = models.AddCygxResearchSummaryVoiceHistory(&item)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,Err:" + err.Error()
+				return
+			}
+			err = models.UpdateResearchSummaryVoiceCounts(articleId)
+			if err != nil {
+				br.Msg = "更新失败"
+				br.ErrMsg = "更新失败,Err:" + err.Error()
+				return
+			}
+		}
+	} else if pageRouter == "上周纪要汇总" {
+		articleInfo, errInfo := models.GetCygxMinutesSummaryInfoById(articleId)
+		if articleInfo == nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "文章ID错误,不存在articleId:" + strconv.Itoa(articleId)
+			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.CygxMinutesSummaryVoiceHistory{
+			ArticleId:  articleId,
+			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.GetLastCygxMinutesSummaryVoiceHistory(articleId, user.UserId)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,GetLastCygxSummaryVoiceHistory Err:" + err.Error()
+				return
+			}
+			err = models.UpdateLastCygxMinutesSummaryVoiceHistory(strconv.Itoa(req.PlaySeconds), lastItem.Id)
+			if err != nil {
+				br.Msg = "更新失败"
+				br.ErrMsg = "更新失败,UpdateLastCygxSummaryVoiceHistory Err:" + err.Error()
+				return
+			}
+		} else {
+			err = models.AddCygxMinutesSummaryVoiceHistory(&item)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,Err:" + err.Error()
+				return
+			}
+			err = models.UpdateMinutesSummaryVoiceCounts(articleId)
+			if err != nil {
+				br.Msg = "更新失败"
+				br.ErrMsg = "更新失败,Err:" + err.Error()
+				return
+			}
+		}
+	} else if pageRouter == "报告精选" {
+		articleInfo, errInfo := models.GetCygxReportSelectionInfoById(articleId)
+		if articleInfo == nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "文章ID错误,不存在articleId:" + strconv.Itoa(articleId)
+			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.CygxReportSelectionVoiceHistory{
+			ArticleId:  articleId,
+			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.GetLastCygxReportSelectionVoiceHistory(articleId, user.UserId)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,GetLastCygxSummaryVoiceHistory Err:" + err.Error()
+				return
+			}
+			err = models.UpdateLastCygxReportSelectionVoiceHistory(strconv.Itoa(req.PlaySeconds), lastItem.Id)
+			if err != nil {
+				br.Msg = "更新失败"
+				br.ErrMsg = "更新失败,UpdateLastCygxSummaryVoiceHistory Err:" + err.Error()
+				return
+			}
+		} else {
+			err = models.AddCygxReportSelectionVoiceHistory(&item)
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,Err:" + err.Error()
+				return
+			}
+			err = models.UpdateReportSelectionVoiceCounts(articleId)
+			if err != nil {
+				br.Msg = "更新失败"
+				br.ErrMsg = "更新失败,Err:" + err.Error()
+				return
+			}
+		}
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	return
+}

+ 3 - 0
models/db.go

@@ -129,6 +129,9 @@ func init() {
 		new(CygxArticleData),
 		new(CygxArticleComment),
 		new(CygxResourceData),
+		new(CygxResearchSummaryVoiceHistory),
+		new(CygxMinutesSummaryVoiceHistory),
+		new(CygxReportSelectionVoiceHistory),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 43 - 0
models/minutes_summary_voice_history.go

@@ -0,0 +1,43 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxMinutesSummaryVoiceHistory struct {
+	Id          int       `orm:"column(id);pk"`
+	ArticleId  int       `description:"文章ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName      string    `description:"所属销售"`
+	PlaySeconds     string    `description:"播放时间 单位s"`
+	ModifyTime      time.Time `description:"视频修改时间"`
+}
+
+//添加
+func AddCygxMinutesSummaryVoiceHistory(item *CygxMinutesSummaryVoiceHistory) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+func GetLastCygxMinutesSummaryVoiceHistory(articleId, userId int) (item *CygxMinutesSummaryVoiceHistory, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_minutes_summary_voice_history WHERE article_id=? AND user_id=? ORDER BY create_time DESC limit 1 `
+	err = o.Raw(sql, articleId, userId).QueryRow(&item)
+	return
+}
+
+func UpdateLastCygxMinutesSummaryVoiceHistory(playSeconds string, lastId int) (err error) {
+	o := orm.NewOrm()
+	sql := ` UPDATE cygx_minutes_summary_voice_history SET play_seconds =? WHERE id=? `
+	_, err = o.Raw(sql, playSeconds, lastId).Exec()
+	return
+}
+

+ 6 - 0
models/report.go

@@ -903,3 +903,9 @@ FROM
 	_, err = o.Raw(sql, industrialManagementId, industrialManagementId, startSize, pageSize).QueryRows(&items)
 	return
 }
+
+type ArticleIdReq struct {
+	ArticleId  int `description:"文章id"`
+	PlaySeconds int `description:"播放时长"`
+	PageRouter string `description:"页面路径"`
+}

+ 43 - 0
models/report_selection_voice_history.go

@@ -0,0 +1,43 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxReportSelectionVoiceHistory struct {
+	Id          int       `orm:"column(id);pk"`
+	ArticleId  int       `description:"文章ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName      string    `description:"所属销售"`
+	PlaySeconds     string    `description:"播放时间 单位s"`
+	ModifyTime      time.Time `description:"视频修改时间"`
+}
+
+//添加
+func AddCygxReportSelectionVoiceHistory(item *CygxReportSelectionVoiceHistory) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+func GetLastCygxReportSelectionVoiceHistory(articleId, userId int) (item *CygxReportSelectionVoiceHistory, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_report_selction_voice_history WHERE article_id=? AND user_id=? ORDER BY create_time DESC limit 1 `
+	err = o.Raw(sql, articleId, userId).QueryRow(&item)
+	return
+}
+
+func UpdateLastCygxReportSelectionVoiceHistory(playSeconds string, lastId int) (err error) {
+	o := orm.NewOrm()
+	sql := ` UPDATE cygx_report_selction_voice_history SET play_seconds =? WHERE id=? `
+	_, err = o.Raw(sql, playSeconds, lastId).Exec()
+	return
+}
+

+ 21 - 0
models/researchSummary.go

@@ -109,3 +109,24 @@ func GetResearchSummarylogSonListThird(articleId, chartPermissionId int, artType
 	_, err = o.Raw(sql, articleId, artType, chartPermissionId).QueryRows(&items)
 	return
 }
+
+func UpdateResearchSummaryVoiceCounts(articleId int) (err error) {
+	sql := `UPDATE cygx_research_summary SET voice_counts = voice_counts+1 WHERE article_id = ?  `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, articleId).Exec()
+	return
+}
+
+func UpdateMinutesSummaryVoiceCounts(articleId int) (err error) {
+	sql := `UPDATE cygx_minutes_summary SET voice_counts = voice_counts+1 WHERE article_id = ?  `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, articleId).Exec()
+	return
+}
+
+func UpdateReportSelectionVoiceCounts(articleId int) (err error) {
+	sql := `UPDATE cygx_report_selection SET voice_counts = voice_counts+1 WHERE article_id = ?  `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, articleId).Exec()
+	return
+}

+ 43 - 0
models/research_summary_voice_history.go

@@ -0,0 +1,43 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxResearchSummaryVoiceHistory struct {
+	Id          int       `orm:"column(id);pk"`
+	ArticleId  int       `description:"文章ID"`
+	UserId      int       `description:"用户ID"`
+	CreateTime  time.Time `description:"创建时间"`
+	Mobile      string    `description:"手机号"`
+	Email       string    `description:"邮箱"`
+	CompanyId   int       `description:"公司id"`
+	CompanyName string    `description:"公司名称"`
+	RealName    string    `description:"用户实际名称"`
+	SellerName      string    `description:"所属销售"`
+	PlaySeconds     string    `description:"播放时间 单位s"`
+	ModifyTime      time.Time `description:"视频修改时间"`
+}
+
+//添加
+func AddCygxResearchSummaryVoiceHistory(item *CygxResearchSummaryVoiceHistory) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+func GetLastCygxResearchSummaryVoiceHistory(articleId, userId int) (item *CygxResearchSummaryVoiceHistory, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_research_summary_voice_history WHERE article_id=? AND user_id=? ORDER BY create_time DESC limit 1 `
+	err = o.Raw(sql, articleId, userId).QueryRow(&item)
+	return
+}
+
+func UpdateLastCygxResearchSummaryVoiceHistory(playSeconds string, lastId int) (err error) {
+	o := orm.NewOrm()
+	sql := ` UPDATE cygx_research_summary_voice_history SET play_seconds =? WHERE id=? `
+	_, err = o.Raw(sql, playSeconds, lastId).Exec()
+	return
+}
+

+ 9 - 0
routers/commentsRouter.go

@@ -979,6 +979,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ReportController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ReportController"],
+        beego.ControllerComments{
+            Method: "ResearchSummaryVoiceHistoryAdd",
+            Router: `/voiceHistory/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ResearchController"] = append(beego.GlobalControllerRouter["hongze/hongze_cygx/controllers:ResearchController"],
         beego.ControllerComments{
             Method: "ArticleHotList",