xingzai 1 éve
szülő
commit
00cef60097

+ 3 - 0
controllers/base_auth_mobile.go

@@ -38,6 +38,7 @@ func (this *BaseAuthMobileController) Prepare() {
 	if method != "HEAD" {
 		if method == "POST" || method == "GET" {
 			authorization := this.Ctx.Input.Header("Authorization")
+			inviteCompany := this.Ctx.Input.Header("From")
 			if authorization == "" {
 				authorization = this.GetString("Authorization")
 			}
@@ -81,6 +82,8 @@ func (this *BaseAuthMobileController) Prepare() {
 				}
 				this.User = wxUser
 			}
+			this.User.InviteCompany = inviteCompany
+			go services.AddCygxPageHistoryRecord(this.User, this.Ctx)
 		} else {
 			this.JSON(models.BaseResponse{Ret: 408, Msg: "请求异常,请联系客服!", ErrMsg: "POST之外的请求,暂不支持"}, false, false)
 			this.StopRun()

+ 5 - 0
models/page_history_record.go

@@ -21,6 +21,7 @@ type CygxPageHistoryRecord struct {
 	Parameter              string    `description:"参数"`
 	Router                 string    `description:"路由"`
 	PageRouter             string    `description:"前端页面路径"`
+	RegisterPlatform       int       `description:"来源 1小程序,2:网页"`
 }
 
 type CygxPageHistoryRecordRep struct {
@@ -47,6 +48,10 @@ func AddCygxPageHistoryRecord(item *CygxPageHistoryRecord) (lastId int64, err er
 	return
 }
 
+type PageRouter struct {
+	PageRouter string
+}
+
 func GetTimeLineRecordCount(userId, industrialManagementId int) (count int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT COUNT(1) AS count FROM cygx_page_history_record WHERE user_id=? AND router = '/api/report/industry/ArticleList?PageSize=10&CurrentIndex=1&CategoryId=99999&IndustrialManagementId=` + strconv.Itoa(industrialManagementId) + `'`

+ 72 - 0
services/page_history_record.go

@@ -0,0 +1,72 @@
+package services
+
+import (
+	"encoding/json"
+	"fmt"
+	"github.com/beego/beego/v2/server/web/context"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strings"
+	"time"
+)
+
+func AddCygxPageHistoryRecord(user *models.WxUserItem, Ctx *context.Context) {
+	item := new(models.CygxPageHistoryRecord)
+	item.UserId = user.UserId
+	item.CreateTime = time.Now()
+	item.Mobile = user.Mobile
+	item.Email = user.Email
+	item.CompanyId = user.CompanyId
+	item.CompanyName = user.CompanyName
+	item.Router = Ctx.Request.RequestURI
+	item.PageRouter = Ctx.Input.Query("PageRouter")
+	if user.InviteCompany != "" {
+		item.Router += "&From=" + user.InviteCompany
+	}
+	item.RegisterPlatform = utils.REGISTER_PLATFORM
+	index := strings.Index(item.Router, "?")
+	if index != -1 {
+		item.Parameter = item.Router[index+1:]
+	}
+	if Ctx.Input.Method() == "POST" && string(Ctx.Input.RequestBody) != "" {
+		item.Parameter = string(Ctx.Input.RequestBody)
+		var pr models.PageRouter
+		err := json.Unmarshal(Ctx.Input.RequestBody, &pr)
+		if err != nil {
+			fmt.Println(err)
+			utils.FileLog.Info(err.Error())
+		}
+		item.PageRouter = pr.PageRouter
+	}
+	if strings.Contains(item.Router, "/api/article/detail") {
+		//cacheKey := fmt.Sprint("uid:", user.UserId, "_Parameter:", item.Parameter)
+		//isExist := utils.Rc.IsExist(cacheKey)
+		//if !isExist {
+		//	setNX := utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
+		//	if !setNX {
+		//		go utils.SendAlarmMsg("记录用户阅读文章,设置Redis Key 过期时间失败:key"+cacheKey, 3)
+		//	}
+		//	return
+		//}
+
+		sliceParameter := strings.Split(item.Parameter, "&PageRouter=")
+		cacheKey := fmt.Sprint("uid:", user.UserId, "_Parameter:", sliceParameter[0])
+		isExist := utils.Rc.IsExist(cacheKey)
+		if isExist {
+			return
+		}
+		setNX := utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
+		if !setNX {
+			if !setNX {
+				go utils.SendAlarmMsg("记录用户阅读文章,设置Redis Key 过期时间失败:key"+cacheKey, 3)
+			}
+		}
+	}
+
+	_, err := models.AddCygxPageHistoryRecord(item)
+	if err != nil {
+		fmt.Println(err)
+		utils.FileLog.Info(err.Error())
+		return
+	}
+}