Browse Source

小程序阅读次数fix

ziwen 3 years ago
parent
commit
4667e87ca4
3 changed files with 116 additions and 2 deletions
  1. 2 0
      go.mod
  2. 84 1
      logic/report/research_report.go
  3. 30 1
      models/tables/user_record/user_record.go

+ 2 - 0
go.mod

@@ -5,6 +5,7 @@ go 1.15
 require (
 	github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
 	github.com/aliyun/aliyun-oss-go-sdk v1.9.8
+	github.com/astaxie/beego v1.12.3 // indirect
 	github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
 	github.com/fsnotify/fsnotify v1.5.1
 	github.com/gin-gonic/gin v1.7.4
@@ -17,6 +18,7 @@ require (
 	github.com/json-iterator/go v1.1.12 // indirect
 	github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
 	github.com/lestrrat-go/strftime v1.0.5 // indirect
+	github.com/lib/pq v1.10.4 // indirect
 	github.com/mattn/go-isatty v0.0.14 // indirect
 	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
 	github.com/op/go-logging v0.0.0-20160315200505-970db520ece7

+ 84 - 1
logic/report/research_report.go

@@ -1,10 +1,17 @@
 package report
 
 import (
+	"errors"
+	"fmt"
+	"hongze/hongze_yb/models/tables/company"
 	"hongze/hongze_yb/models/tables/company_report_permission"
 	"hongze/hongze_yb/models/tables/research_report"
 	"hongze/hongze_yb/models/tables/research_report_type"
+	"hongze/hongze_yb/models/tables/user_record"
+	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/utils"
+	"strconv"
+	"time"
 )
 
 type ResearchReportInfo struct {
@@ -60,6 +67,45 @@ func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchRepo
 		}
 	}
 
+	// 联系人信息
+	strInt64 := strconv.FormatUint(userId, 10)
+	id, _ := strconv.Atoi(strInt64)
+	wxUserInfo, err := wx_user.GetByUserId(id)
+	if err != nil {
+		fmt.Println("GetByUserId:", err.Error())
+		return
+	}
+	companyInfo, tmpErr := company.GetByCompanyId(wxUserInfo.CompanyID)
+	if tmpErr != nil {
+		err = tmpErr
+		if tmpErr == utils.ErrNoRow {
+			err = errors.New("找不到该客户")
+			return
+		}
+		return
+	}
+	userViewHistory := &user_record.UserViewHistory{
+		ViewHistoryId:        0,
+		UserId:               userId,
+		Mobile:               wxUserInfo.Mobile,
+		Email:                wxUserInfo.Email,
+		RealName:             wxUserInfo.RealName,
+		CompanyName:          companyInfo.CompanyName,
+		ViewTitle:            "",
+		ViewPage:             "",
+		ReportChapterModule:  "",
+		CreatedTime:           time.Now(),
+		LastUpdatedTime:      time.Now(),
+		Type:                 "weekly_report",
+		ResearchReportId:     0,
+		ResearchReportTypeId: 0,
+	}
+	historyId, err := user_record.AddUserViewHistory(userViewHistory)
+	if err != nil {
+		fmt.Println("AddUserViewHistory err", err.Error())
+	}
+	fmt.Println("new historyId:", historyId)
+
 	result = ResearchReportInfo{
 		ResearchReportInfo:     reportInfo,
 		ResearchReportTypeList: researchReportTypeList,
@@ -141,7 +187,44 @@ func GetResearchReportTypeContentInfo(researchReportTypeId, userId uint64) (resu
 	if len(researchReportTypeContentList) > 0 {
 		add = 0
 	}
-
+	// 联系人信息
+	strInt64 := strconv.FormatUint(userId, 10)
+	id, _ := strconv.Atoi(strInt64)
+	wxUserInfo, err := wx_user.GetByUserId(id)
+	if err != nil {
+		fmt.Println("GetByUserId:", err.Error())
+		return
+	}
+	companyInfo, tmpErr := company.GetByCompanyId(wxUserInfo.CompanyID)
+	if tmpErr != nil {
+		err = tmpErr
+		if tmpErr == utils.ErrNoRow {
+			err = errors.New("找不到该客户")
+			return
+		}
+		return
+	}
+	userViewHistory := &user_record.UserViewHistory{
+		ViewHistoryId:        0,
+		UserId:               userId,
+		Mobile:               wxUserInfo.Mobile,
+		Email:                wxUserInfo.Email,
+		RealName:             wxUserInfo.RealName,
+		CompanyName:          companyInfo.CompanyName,
+		ViewTitle:            "",
+		ViewPage:             "",
+		ReportChapterModule:  "",
+		CreatedTime:          time.Now(),
+		LastUpdatedTime:      time.Now(),
+		Type:                 "weekly_report",
+		ResearchReportId:     0,
+		ResearchReportTypeId: 0,
+	}
+	historyId, err := user_record.AddUserViewHistory(userViewHistory)
+	if err != nil {
+		fmt.Println("AddUserViewHistory err", err.Error())
+	}
+	fmt.Println("new historyId:", historyId)
 	result = ResearchReportTypeContentInfo{
 		ResearchReportTypeContentList: researchReportTypeContentList,
 		ResearchReportTypeInfo:        researchReportTypeInfo,

+ 30 - 1
models/tables/user_record/user_record.go

@@ -1,6 +1,9 @@
 package user_record
 
-import "time"
+import (
+	"hongze/hongze_yb/global"
+	"time"
+)
 
 // UserRecord 联系人表
 type UserRecord struct {
@@ -63,3 +66,29 @@ var UserRecordColumns = struct {
 	SessionKey:     "session_key",
 	UserID:         "user_id",
 }
+
+type UserViewHistory struct {
+	ViewHistoryId        uint64    `gorm:"primaryKey,column:view_history_id" description:"自增Id"`
+	UserId               uint64    `description:"用户id"`
+	Mobile               string    `description:"手机号"`
+	Email                string    `description:"邮箱"`
+	RealName             string    `description:"用户实际名称"`
+	CompanyName          string    `description:"公司名称"`
+	ViewTitle            string    `description:"访问标题"`
+	ViewPage             string    `description:"访问页面"`
+	ReportChapterModule  string    `description:"访问核心观点或者图文逻辑"`
+	CreatedTime          time.Time `description:"创建时间"`
+	LastUpdatedTime      time.Time `description:"最后更新时间"`
+	Type                 string    `description:"访问历史类型,weekly_report 周报,pdf"`
+	ResearchReportId     uint64    `description:"研报id"`
+	ResearchReportTypeId uint64    `description:"报告章节id,为0时表示查看目录或者首页"`
+}
+
+func (UserViewHistory) TableName() string {
+	return "user_view_history"
+}
+
+func AddUserViewHistory(item *UserViewHistory) (newId int64, err error) {
+	err = global.DEFAULT_MYSQL.Create(item).Error
+	return
+}