瀏覽代碼

feat:p510 entniche_new 画像浏览记录

fuwencai 11 月之前
父節點
當前提交
5f83aed7a4
共有 2 個文件被更改,包括 59 次插入0 次删除
  1. 8 0
      entniche_new/src/service/portrait/subvipPortraitAction.go
  2. 51 0
      entniche_new/src/util/history.go

+ 8 - 0
entniche_new/src/service/portrait/subvipPortraitAction.go

@@ -9,6 +9,7 @@ import (
 	. "app.yhyue.com/moapp/jypkg/ent/util"
 	db "app.yhyue.com/moapp/jypkg/ent/util"
 	"entniche_new/src/entity"
+	"entniche_new/src/util"
 	"fmt"
 	"log"
 	"strings"
@@ -146,6 +147,13 @@ func (this *EntPortrait) BuyerPortrait() {
 		if buyerName == "" {
 			return nil, fmt.Errorf("参数异常")
 		}
+		// p510 保存浏览记录
+		if userId != "" {
+			go func() {
+				redisKey := util.HistoryRedisKeyMap[util.TypeBuyerView]
+				util.SaveHistory(buyerName, userId, redisKey)
+			}()
+		}
 		cepm, hasPower, err := entity.CreatePortraitManager(this.Session())
 		err = entity.SubVipPortraitTimesCheck(Mysql, buyerName, userId)
 		if err != nil {

+ 51 - 0
entniche_new/src/util/history.go

@@ -0,0 +1,51 @@
+package util
+
+import (
+	"app.yhyue.com/moapp/jybase/redis"
+	"fmt"
+	"strings"
+)
+
+const (
+	TypeSearch      = "1" // 标讯搜索历史记录
+	TypeEntSearch   = "2" // 企业历史搜索
+	TypeEntView     = "3" // 企业历史浏览
+	TypeBuyerSearch = "4" // 采购单位历史搜索
+	TypeBuyerView   = "5" // 采购单位历史浏览
+	RedisName       = "other"
+)
+
+var (
+	// HistoryRedisKeyMap 历史记录对应的Rediskey
+	HistoryRedisKeyMap = map[string]string{
+		TypeSearch:      "s_%s",
+		TypeEntSearch:   "history_ent_s_%s",
+		TypeEntView:     "history_ent_v_%s",
+		TypeBuyerSearch: "history_buyer_s_%s",
+		TypeBuyerView:   "history_buyer_v_%s",
+	}
+)
+
+// SaveHistory 保存历史记录
+func SaveHistory(matchKey string, userId string, redisKey string) bool {
+	redisKey = fmt.Sprintf(redisKey, userId)
+	history := redis.GetStr(RedisName, redisKey)
+	arrS := []string{}
+	arrS = strings.Split(history, ",")
+	//新增历史记录
+	if history == "" {
+		arrS = make([]string, 0)
+	}
+	for k, v := range arrS {
+		if v == strings.TrimSpace(matchKey) {
+			arrS = append(arrS[:k], arrS[k+1:]...)
+			break
+		}
+	}
+
+	arrS = append(arrS, strings.TrimSpace(matchKey))
+	if len(arrS) > 10 {
+		arrS = arrS[len(arrS)-10:]
+	}
+	return redis.Put(RedisName, redisKey, strings.Join(arrS, ","), -1)
+}