Browse Source

no message

zhangchuanxing 1 week ago
parent
commit
1b8255f21e
4 changed files with 58 additions and 0 deletions
  1. 1 0
      controllers/chart.go
  2. 26 0
      models/chart_record.go
  3. 1 0
      models/db.go
  4. 30 0
      services/chart.go

+ 1 - 0
controllers/chart.go

@@ -214,6 +214,7 @@ func (this *ChartController) Detail() {
 			detail.IsCollection = true
 		}
 	}
+	go services.ServerAddCygxChartRecord(user, chartId) //用户阅读图表,添加浏览记录
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"

+ 26 - 0
models/chart_record.go

@@ -0,0 +1,26 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxChartRecord struct {
+	RecordId         int       `orm:"column(record_id);pk"`
+	ChartId          int       `description:"图表ID"`
+	UserId           int       `description:"用户ID"`
+	Mobile           string    `description:"手机号"`
+	Email            string    `description:"邮箱"`
+	CompanyId        int       `description:"公司id"`
+	CompanyName      string    `description:"公司名称"`
+	RealName         string    `description:"用户实际名称"`
+	CreateTime       time.Time `description:"创建时间"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+}
+
+// 添加历史信息
+func AddCygxChartRecord(item *CygxChartRecord) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 1 - 0
models/db.go

@@ -115,6 +115,7 @@ func init() {
 		new(CygxChart),
 		new(CygxChartCollect),
 		new(CygxChartTop),
+		new(CygxChartRecord),
 		new(CygxCelueArticleHistoryRecord),
 		new(CygxArticleHistoryRecordAll),
 		new(CygxActivityAppointment),

+ 30 - 0
services/chart.go

@@ -3,6 +3,7 @@ package services
 import (
 	"context"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
@@ -593,3 +594,32 @@ func GetChartDetailByApi(chartId int) (err error) {
 	return
 
 }
+
+// 用户阅读图表,添加浏览记录
+func ServerAddCygxChartRecord(wxUser *models.WxUserItem, ctagId int) {
+	if wxUser.CompanyId < 1 {
+		return
+	}
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg(fmt.Sprint("用户阅读图表,添加浏览记录失败 ctagId", ctagId, "userId", wxUser.UserId, err.Error()), 2)
+		}
+	}()
+	item := new(models.CygxChartRecord)
+	item.UserId = wxUser.UserId
+	item.RealName = wxUser.RealName
+	item.Mobile = wxUser.Mobile
+	item.Email = wxUser.Email
+	item.CompanyId = wxUser.CompanyId
+	item.CompanyName = wxUser.CompanyName
+	item.CreateTime = time.Now()
+	item.RegisterPlatform = utils.REGISTER_PLATFORM
+	_, e := models.AddCygxChartRecord(item)
+	if e != nil {
+		err = errors.New("AddCygxChartRecord" + e.Error())
+		return
+	}
+	return
+}