Преглед изворни кода

Merge branch 'xi_viewTotal'

# Conflicts:
#	logic/report/research_report.go
ziwen пре 3 година
родитељ
комит
a5378e5014
1 измењених фајлова са 95 додато и 0 уклоњено
  1. 95 0
      logic/report/research_report.go

+ 95 - 0
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_view_history"
+	"hongze/hongze_yb/models/tables/wx_user"
 	"hongze/hongze_yb/utils"
+	"strconv"
+	"time"
 )
 
 type ResearchReportInfo struct {
@@ -60,11 +67,61 @@ 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
+	}
+
+	//查询是否读过这篇报告,如果未读过则阅读人数+1
+	_, err = user_view_history.GetReportByUserId(userId, reportInfo.ResearchReportID)
+	if err != nil {
+		err = reportInfo.UpdateViewers()
+		if err != nil {
+			fmt.Println("UpdateViewers err:", err.Error())
+		}
+	}
+
+	//新增userViewHistory记录
+	userViewHistory := &user_view_history.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:     reportInfo.ResearchReportID,
+		ResearchReportTypeID: 0,
+	}
+	err = userViewHistory.AddUserViewHistory()
+	if err != nil {
+		fmt.Println("AddUserViewHistory err", err.Error())
+	}
+
 	result = ResearchReportInfo{
 		ResearchReportInfo:     reportInfo,
 		ResearchReportTypeList: researchReportTypeList,
 		HasMenu:                1,
 	}
+
 	if len(researchReportTypeList) <= 0 {
 
 	} else if len(researchReportTypeList) == 1 {
@@ -141,7 +198,45 @@ 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记录
+	userViewHistory := &user_view_history.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:     reportInfo.ResearchReportID,
+		ResearchReportTypeID: researchReportTypeId,
+	}
+	err = userViewHistory.AddUserViewHistory()
+	if err != nil {
+		fmt.Println("AddUserViewHistory err", err.Error())
+	}
 	result = ResearchReportTypeContentInfo{
 		ResearchReportTypeContentList: researchReportTypeContentList,
 		ResearchReportTypeInfo:        researchReportTypeInfo,