浏览代码

wip:首页热词未登录调整

wangkaiyue 1 年之前
父节点
当前提交
898900a37e
共有 4 个文件被更改,包括 138 次插入110 次删除
  1. 1 1
      src/config.json
  2. 0 87
      src/jfw/config/config.go
  3. 0 8
      src/jfw/front/classificationTag.go
  4. 137 14
      src/jfw/front/pcIndex.go

文件差异内容过多而无法显示
+ 1 - 1
src/config.json


+ 0 - 87
src/jfw/config/config.go

@@ -6,13 +6,10 @@ import (
 	"app.yhyue.com/moapp/jybase/mail"
 	"app.yhyue.com/moapp/jypkg/middleground"
 	"app.yhyue.com/moapp/jypkg/public"
-	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/os/gcfg"
 	"github.com/gogf/gf/v2/os/gctx"
-	"strings"
 	"sync"
-	"unicode"
 )
 
 var (
@@ -28,7 +25,6 @@ var (
 	Middleground         *middleground.Middleground
 	HotWinnerConfig      HotConfig
 	HotBuyerConfig       HotConfig
-	SubjectMatter        []map[string]interface{}
 	IpList               *ipmatch.WhiteIp
 	IpInitLock           sync.RWMutex //锁
 )
@@ -75,7 +71,6 @@ func init() {
 		RegResourceCenter(g.Cfg().MustGet(ctx, "resourceCenterKey").String()).
 		RegEntManageApplication(g.Cfg().MustGet(ctx, "entManageApplication").String()).
 		RegPublicservice(g.Cfg().MustGet(ctx, "publicserviceKey").String())
-	SubjectMatter = GetLetterMap(util.InterfaceToStr(Sysconfig["hotSubjectMatter"]))
 }
 
 func IpInit() {
@@ -96,85 +91,3 @@ func IpInit() {
 	}
 	IpList = ipmatch.NewRb(nil)
 }
-
-func GetLetterMap(names string) []map[string]interface{} {
-	var (
-		data                                   []map[string]interface{}
-		nameArr1, nameArr2, nameArr3, nameArr4 []string
-	)
-	nameArr := strings.Split(names, ",")
-	for _, v := range nameArr {
-		nameArr1 = append(nameArr1, fmt.Sprintf(`"%s"`, v))
-	}
-	dataArr1 := public.BaseMysql.SelectBySql(fmt.Sprintf(`select a.id,a.name,b.id class_id,b.name class_1 from seo_words.seo_industry a inner join  seo_words.seo_industry_class b on  a.class_1 in (%s) and a.class_1=b.name and  a.class_2 !='药品'  order by a.class_1`, strings.Join(nameArr1, ",")))
-	dataArr2 := public.BaseMysql.SelectBySql(fmt.Sprintf(`select id,name,letter from seo_words.seo_resource where name in (%s) and state=1 order by id desc`, strings.Join(nameArr1, ",")))
-	for _, v1 := range nameArr {
-		var isNormal bool
-		if dataArr1 != nil && len(*dataArr1) > 0 {
-			for _, v2 := range *dataArr1 {
-				if v1 == v2["name"] {
-					isNormal = true
-					data = append(data, map[string]interface{}{
-						"name": v1 + util.ObjToString(Seoconfig["seoKeywordSuffix"]),
-						"url":  fmt.Sprintf("/tags/industry/%v_all_all_%v.html", util.Int64All(v2["id"]), util.Int64All(v2["class_id"])),
-					})
-				}
-			}
-		}
-		if !isNormal {
-			if dataArr2 != nil && len(*dataArr2) > 0 {
-				for _, v2 := range *dataArr2 {
-					if v1 == v2["name"] {
-						isNormal = true
-						letter := util.ObjToString(v2["letter"])
-						id := util.Int64All(v2["id"])
-						v1 += util.ObjToString(Seoconfig["seoKeywordSuffix"])
-						data = append(data, map[string]interface{}{
-							"name": v1,
-							"url":  fmt.Sprintf("/tags/letter/all_all_all_%v_%v.html", letter, id),
-						})
-					}
-				}
-			}
-		}
-		if !isNormal {
-			nameArr2 = append(nameArr2, v1)
-			nameArr3 = append(nameArr3, fmt.Sprintf(`"%s"`, v1))
-			letter := getFirstLetter(v1)
-			nameArr4 = append(nameArr4, fmt.Sprintf(`("%s", "%s", 1)`, v1, letter))
-		}
-	}
-	if len(nameArr2) > 0 {
-		public.BaseMysql.SelectBySql(fmt.Sprintf(`INSERT INTO seo_words.seo_resource (name, letter, state) VALUES %s`, strings.Join(nameArr4, ",")))
-		dataArr3 := public.BaseMysql.SelectBySql(fmt.Sprintf(`select id,name,letter from seo_words.seo_resource where name in (%s) and state=1 order by id desc`, strings.Join(nameArr3, ",")))
-		if dataArr3 != nil {
-			for _, v3 := range *dataArr3 {
-				letter := util.ObjToString(v3["letter"])
-				id := util.Int64All(v3["id"])
-				n := util.ObjToString(v3["name"])
-				n += util.ObjToString(Seoconfig["seoKeywordSuffix"])
-				data = append(data, map[string]interface{}{
-					"name": n,
-					"url":  fmt.Sprintf("/tags/letter/all_all_all_%v_%v.html", letter, id),
-				})
-			}
-		}
-	}
-	return data
-}
-
-// 获取字符串的首字母大写形式
-func getFirstLetter(s string) string {
-	words := strings.Fields(s) // 将字符串分割成单词
-	var result string
-	for _, word := range words {
-		firstChar := []rune(word)[0] // 获取单词的第一个字符
-
-		// 检查字符是否为汉字或英文字母
-		if unicode.Is(unicode.Han, firstChar) || unicode.IsLetter(firstChar) {
-			result += strings.ToUpper(string(firstChar))
-		}
-	}
-
-	return result
-}

+ 0 - 8
src/jfw/front/classificationTag.go

@@ -52,14 +52,6 @@ func RegionAndInformationAndTender() map[string]interface{} {
 	return data
 }
 
-// HotSubjectMatter 热门标的物
-func HotSubjectMatter() []map[string]interface{} {
-	if config.SubjectMatter == nil || len(config.SubjectMatter) == 0 {
-		config.SubjectMatter = config.GetLetterMap(qu.InterfaceToStr(config.Seoconfig["hotSubjectMatter"]))
-	}
-	return config.SubjectMatter
-}
-
 // 最新更新的200中标企业
 func GetWinnerInfo() (data []*BuyerList) {
 	// 取缓存

+ 137 - 14
src/jfw/front/pcIndex.go

@@ -12,6 +12,7 @@ import (
 	"strconv"
 	"strings"
 	"time"
+	"unicode"
 
 	util "app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
@@ -38,18 +39,23 @@ type PcIndex struct {
 	searchResult  xweb.Mapper `xweb:"/list/(\\w+)/(\\w+).html"` //剑鱼标讯分类 地区结果列表
 }
 
-var hotKeyArr = []string{}
+var (
+	hotKeyArrLoginEd                []string
+	subjectMatter, hotKeyArrUnLogin []*hotKeyWord
+)
 
 func init() {
 	xweb.AddAction(&PcIndex{})
 	// 每隔5分钟更新一次随机词
 	go func() {
-		hotKeyArr = GetIndexHotKey()
-		ticker := time.NewTicker(300 * time.Second)
-		for range ticker.C {
-			hotKeyArr = GetIndexHotKey()
+		getIndexHotKeyNoLogin := getIndexHotKeyNoLoginFunc()
+		hotKeyArrLoginEd, hotKeyArrUnLogin = GetIndexHotKey(), getIndexHotKeyNoLogin()
+		for range time.NewTicker(300 * time.Second).C {
+			hotKeyArrLoginEd, hotKeyArrUnLogin = GetIndexHotKey(), getIndexHotKeyNoLogin()
 		}
 	}()
+
+	subjectMatter = getLetterMap(strings.Split(util.InterfaceToStr(config.Sysconfig["hotSubjectMatter"]), ","))
 }
 
 func (this PcIndex) BrandIndex() error {
@@ -71,6 +77,7 @@ func (m *PcIndex) NewSordfish(flag string) error {
 		pageSize = 50
 	}
 	var shareid = m.GetString("id")
+	userId, _ := m.GetSession("userId").(string)
 	pcindexKey := "jypcindex"
 	if cacheKey, _ := config.Sysconfig["pcindexCacheKey"].(string); cacheKey != "" {
 		pcindexKey = cacheKey
@@ -109,7 +116,7 @@ func (m *PcIndex) NewSordfish(flag string) error {
 			return m.Render("/pc/index_tmp.html", &m.T)
 		} else {
 			var entIsNew bool
-			if m.GetSession("userId") != "" {
+			if userId != "" {
 				bigBaseMsg := jy.GetBigVipUserBaseMsg(m.Session(), *config.Middleground)
 				entIsNew = bigBaseMsg.EntIsNew
 			}
@@ -118,7 +125,7 @@ func (m *PcIndex) NewSordfish(flag string) error {
 				m.T[k] = v
 			}
 			//热门标的物
-			m.T["hotSubject"] = HotSubjectMatter()
+			m.T["hotSubject"] = subjectMatter
 			//实用内容推荐
 			m.T["recommend"] = ContentRecommendation()
 			m.T["jycmsLink"] = GetJycmsAreaLink()
@@ -138,11 +145,12 @@ func (m *PcIndex) NewSordfish(flag string) error {
 				}
 			}
 			m.T["strategyList"] = strategyList
-			m.T["hasLogin"] = util.ObjToString(m.GetSession("userId")) != ""
+			m.T["hasLogin"] = userId != ""
 			m.T["includedInfo"] = GetIncludedInfo()
 			m.T["hotWinner"] = GetWinnerInfo()
 			m.T["newbids"] = NewIndexbids(m.Session(), m.Request)
-			m.T["hotkey"] = hotKeyArr
+			m.T["hotkey"] = hotKeyArrLoginEd
+			m.T["hotKeyArrUnLogin"] = hotKeyArrUnLogin
 			m.T["simpleTemplateData"] = map[string]interface{}{"XwebVer": m.T["XwebVer"]} //清除前端js获取模版标签变量
 			return m.Render("/pc/index.html", &m.T)
 		}
@@ -719,20 +727,135 @@ func InSeoContent(arr *[]map[string]interface{}) {
 	}
 }
 
-func GetIndexHotKey() []string {
-	pcIndexHotKey := util.ObjArrToStringArr(config.Sysconfig["pcIndexHotKey"].([]interface{}))
+func GetIndexHotKey() (loginEd []string) {
 	pcIndexHotKeyLimit := util.Int64All(config.Sysconfig["pcIndexHotKeyLimit"])
+	pcIndexHotKey := util.ObjArrToStringArr(config.Sysconfig["pcIndexHotKey"].([]interface{}))
+
 	// 定义一个函数,用于从数组words中随机取出几个词
 	m := map[string]bool{}
 	for _, v := range pcIndexHotKey {
 		m[v] = true
 	}
-	result := []string{}
 	for key, _ := range m {
-		result = append(result, key)
-		if len(result) == int(pcIndexHotKeyLimit) {
+		loginEd = append(loginEd, key)
+		if len(loginEd) == int(pcIndexHotKeyLimit) {
 			break
 		}
 	}
+	return
+}
+
+var getIndexHotKeyNoLoginFunc = func() func() []*hotKeyWord {
+	limit := util.IntAll(config.Sysconfig["pcIndexHotKeyLimit"])
+	//获取未登录关键词
+	configVal, _ := config.Sysconfig["pcIndexHotKeyUnLogin"].([]interface{})
+	rData := getLetterMap(util.ObjArrToStringArr(configVal))
+	rLen := len(rData)
+	return func() (final []*hotKeyWord) {
+		if rData == nil {
+			return nil
+		}
+		if limit > rLen {
+			return rData
+		}
+
+		repeat := map[string]bool{}
+		for len(final) < limit {
+			rand.Seed(time.Now().UnixNano())
+			if val := rData[rand.Intn(rLen)]; !repeat[val.Name] {
+				final = append(final, val)
+				repeat[val.Name] = true
+			}
+		}
+		return
+	}
+}
+
+type hotKeyWord struct {
+	Name string
+	Url  string
+}
+
+// getLetterMap 获取关键词对应的链接,若没有则插入
+func getLetterMap(nameArr []string) []*hotKeyWord {
+	var (
+		data                                   []*hotKeyWord
+		nameArr1, nameArr2, nameArr3, nameArr4 []string
+	)
+	if len(nameArr) == 0 {
+		return nil
+	}
+	for _, v := range nameArr {
+		nameArr1 = append(nameArr1, fmt.Sprintf(`"%s"`, v))
+	}
+	dataArr1 := public.BaseMysql.SelectBySql(fmt.Sprintf(`select a.id,a.name,b.id class_id,b.name class_1 from seo_words.seo_industry a inner join  seo_words.seo_industry_class b on  a.class_1 in (%s) and a.class_1=b.name and  a.class_2 !='药品'  order by a.class_1`, strings.Join(nameArr1, ",")))
+	dataArr2 := public.BaseMysql.SelectBySql(fmt.Sprintf(`select id,name,letter from seo_words.seo_resource where name in (%s) and state=1 order by id desc`, strings.Join(nameArr1, ",")))
+	for _, v1 := range nameArr {
+		var isNormal bool
+		if dataArr1 != nil && len(*dataArr1) > 0 {
+			for _, v2 := range *dataArr1 {
+				if v1 == v2["name"] {
+					isNormal = true
+					data = append(data, &hotKeyWord{
+						Name: v1 + util.ObjToString(config.Seoconfig["seoKeywordSuffix"]),
+						Url:  fmt.Sprintf("/tags/industry/%v_all_all_%v.html", util.Int64All(v2["class_id"]), util.Int64All(v2["id"])),
+					})
+				}
+			}
+		}
+		if !isNormal {
+			if dataArr2 != nil && len(*dataArr2) > 0 {
+				for _, v2 := range *dataArr2 {
+					if v1 == v2["name"] {
+						isNormal = true
+						letter := util.ObjToString(v2["letter"])
+						id := util.Int64All(v2["id"])
+						v1 += util.ObjToString(config.Seoconfig["seoKeywordSuffix"])
+						data = append(data, &hotKeyWord{
+							Name: v1,
+							Url:  fmt.Sprintf("/tags/letter/all_all_all_%v_%v.html", letter, id),
+						})
+					}
+				}
+			}
+		}
+		if !isNormal {
+			nameArr2 = append(nameArr2, v1)
+			nameArr3 = append(nameArr3, fmt.Sprintf(`"%s"`, v1))
+			letter := getFirstLetter(v1)
+			nameArr4 = append(nameArr4, fmt.Sprintf(`("%s", "%s", 1)`, v1, letter))
+		}
+	}
+	if len(nameArr2) > 0 {
+		public.BaseMysql.SelectBySql(fmt.Sprintf(`INSERT INTO seo_words.seo_resource (name, letter, state) VALUES %s`, strings.Join(nameArr4, ",")))
+		dataArr3 := public.BaseMysql.SelectBySql(fmt.Sprintf(`select id,name,letter from seo_words.seo_resource where name in (%s) and state=1 order by id desc`, strings.Join(nameArr3, ",")))
+		if dataArr3 != nil {
+			for _, v3 := range *dataArr3 {
+				letter := util.ObjToString(v3["letter"])
+				id := util.Int64All(v3["id"])
+				n := util.ObjToString(v3["name"])
+				n += util.ObjToString(config.Seoconfig["seoKeywordSuffix"])
+				data = append(data, &hotKeyWord{
+					Name: n,
+					Url:  fmt.Sprintf("/tags/letter/all_all_all_%v_%v.html", letter, id),
+				})
+			}
+		}
+	}
+	return data
+}
+
+// 获取字符串的首字母大写形式
+func getFirstLetter(s string) string {
+	words := strings.Fields(s) // 将字符串分割成单词
+	var result string
+	for _, word := range words {
+		firstChar := []rune(word)[0] // 获取单词的第一个字符
+
+		// 检查字符是否为汉字或英文字母
+		if unicode.Is(unicode.Han, firstChar) || unicode.IsLetter(firstChar) {
+			result += strings.ToUpper(string(firstChar))
+		}
+	}
 	return result
 }

部分文件因为文件数量过多而无法显示