Parcourir la source

feat:信息列表数量处理

fuwencai il y a 2 ans
Parent
commit
9cdea63df0

+ 16 - 8
src/jfw/modules/app/src/app/front/tags.go

@@ -93,6 +93,8 @@ onceAgain:
 				PageNum:  1,                                       //当前页码
 				IsSearch: true,                                    //是否进行bidding数据查询
 			}
+			isInfoList bool // 是否是在列表页面
+
 		)
 		areaList, areaToCode, cityToCode, areaToCity = jyutil.GetAllArea()
 		infoTypeList, topMap = jyutil.GetInfoType()
@@ -141,6 +143,7 @@ onceAgain:
 					biddingInfo.PageFormat(codes[1])
 					prevPage = fmt.Sprintf("%s_%d", codes[0], biddingInfo.PageNum-1)
 					nextPage = fmt.Sprintf("%s_%d", codes[0], biddingInfo.PageNum+1)
+					isInfoList = true
 				}
 			}
 		case jyutil.Label["industry"]: //行业
@@ -160,6 +163,7 @@ onceAgain:
 					prevPage = fmt.Sprintf("%s_%s_%d", codes[0], codes[1], biddingInfo.PageNum-1)
 					nextPage = fmt.Sprintf("%s_%s_%d", codes[0], codes[1], biddingInfo.PageNum+1)
 				}
+				isInfoList = true
 			} else if name == "home" {
 				biddingInfo.IsEffective = true
 				biddingInfo.IsSearch = false
@@ -179,6 +183,7 @@ onceAgain:
 			})
 			biddingInfo.IsSearch = false
 			hasIndustryNav = true
+			isInfoList = true
 		case jyutil.Label["winner"]: //中标单位
 			biddingInfo.IsEffective = true
 			biddingInfo.PageFormat(name)
@@ -191,6 +196,7 @@ onceAgain:
 			biddingInfo.IsSearch = false
 			hasIndustryNav = true
 			title = fmt.Sprintf("%s%s", "中标企业", suffix)
+			isInfoList = true
 		case jyutil.Label["home"]: //首页
 			if name == types {
 				biddingInfo.IsEffective = true
@@ -208,14 +214,7 @@ onceAgain:
 			goto onceAgain
 		}
 		//信息类型
-		if biddingInfo.PageNum == 1 {
-			prevPage = ""
-		}
-		if biddingInfo.PageNum == (biddingInfo.Total-1)/biddingInfo.PageSize+1 {
-			nextPage = ""
-		}
-		tg.T["prevPage"] = qu.If(prevPage != "", fmt.Sprintf("/jyapp/tags/%s/%s.html", types, prevPage), "").(string)
-		tg.T["nextPage"] = qu.If(nextPage != "", fmt.Sprintf("/jyapp/tags/%s/%s.html", types, nextPage), "").(string)
+
 		if len(currentLocation) > 0 {
 			currentLocation[len(currentLocation)-1].Url = ""
 		}
@@ -229,6 +228,14 @@ onceAgain:
 		if biddingInfo.IsSearch {
 			tg.T["biddingList"] = biddingInfo.GetBiddingInfo(types, name, currentLocation)
 		}
+		if biddingInfo.PageNum == 1 {
+			prevPage = ""
+		}
+		if biddingInfo.PageNum == (biddingInfo.Total-1)/biddingInfo.PageSize+1 {
+			nextPage = ""
+		}
+		tg.T["prevPage"] = qu.If(prevPage != "", fmt.Sprintf("/jyapp/tags/%s/%s.html", types, prevPage), "").(string)
+		tg.T["nextPage"] = qu.If(nextPage != "", fmt.Sprintf("/jyapp/tags/%s/%s.html", types, nextPage), "").(string)
 		tg.T["totalPage"] = (biddingInfo.Total-1)/biddingInfo.PageSize + 1
 		tg.T["pageNum"] = biddingInfo.PageNum
 		tg.T["hotArea"] = jyutil.GetHotArea()
@@ -253,6 +260,7 @@ onceAgain:
 		tg.T["areaTopTip"] = areaTopTip
 		tg.T["title"] = title
 		tg.T["Home"] = "/jyapp/tags/home/home.html"
+		tg.T["isInfoList"] = isInfoList
 		//模板redis缓存
 		content, _ := tg.Render4Cache("/tags/index.html", &tg.T)
 		redis.Put("seoCache", tagsMobileKey, string(content), qu.IntAll(config.Seoconfig["contentCache"]))

+ 34 - 13
src/jfw/modules/app/src/app/jyutil/tags.go

@@ -22,18 +22,19 @@ import (
 )
 
 var (
-	mobileHref         = "/jyapp/tags/%s/%s.html"
-	infoTypeRedisKey   = "mobile_seo_infoType_home"
-	areaRedisKey       = "mobile_seo_area_home"
-	hotAreaRedisKey    = "mobile_seo_hot_area"
-	biddingListKey     = "mobile_seo_list_%s_%s_%d"
-	industryRedisKey   = "mobile_seo_industry"
-	buyerListRedisKey  = "mobile_seo_buyer_list_%d"
-	winnerListRedisKey = "mobile_seo_winner_list_%d"
-	HotArea            = "北京,山东,陕西,河南,广东"
-	AdCode             = "mobile_seo_ad"
-	randCount          = 600
-	Label              = map[string]string{
+	mobileHref          = "/jyapp/tags/%s/%s.html"
+	infoTypeRedisKey    = "mobile_seo_infoType_home"
+	areaRedisKey        = "mobile_seo_area_home"
+	hotAreaRedisKey     = "mobile_seo_hot_area"
+	biddingListKey      = "mobile_seo_list_%s_%s_%d"
+	biddingListTotalKey = "mobile_seo_list_total_%s_%s"
+	industryRedisKey    = "mobile_seo_industry"
+	buyerListRedisKey   = "mobile_seo_buyer_list_%d"
+	winnerListRedisKey  = "mobile_seo_winner_list_%d"
+	HotArea             = "北京,山东,陕西,河南,广东"
+	AdCode              = "mobile_seo_ad"
+	randCount           = 600
+	Label               = map[string]string{
 		"area":     "area",
 		"infoType": "it",
 		"industry": "indu",
@@ -404,13 +405,21 @@ func (b *BiddingInfo) GetBiddingInfo(types, name string, currentLocation []*SeoI
 	if n := strings.Split(name, "_"); len(n) > 1 {
 		name = strings.Join(n[:len(n)-1], "_")
 	}
+	redisCount := 0
 	redisKey := fmt.Sprintf(biddingListKey, types, name, b.PageNum)
+	redisTotalKey := fmt.Sprintf(biddingListTotalKey, types, name)
 	if b, err := redis.GetBytes("seoCache", redisKey); err == nil && len(*b) > 0 {
 		if err = json.Unmarshal(*b, &birt); err != nil {
 			log.Println(err)
 		}
 	}
-	if len(birt) == 0 {
+	if redisCountByte, err := redis.GetBytes("seoCache", redisTotalKey); err == nil && len(*redisCountByte) > 0 {
+		if err = json.Unmarshal(*redisCountByte, &redisCount); err != nil {
+			log.Println(err)
+		}
+	}
+
+	if len(birt) == 0 || ((b.Total != b.PageSize) && redisCount == 0) {
 		if flag := ReqLimitInit.Limit(context.Background()); flag == 1 {
 			defer ReqLimitInit.Release()
 		} else {
@@ -493,9 +502,21 @@ func (b *BiddingInfo) GetBiddingInfo(types, name string, currentLocation []*SeoI
 							}
 						}
 					}
+					countByte, err := json.Marshal(b.Total)
+					if err == nil && len(countByte) > 0 {
+						if err = redis.PutBytes("seoCache", fmt.Sprintf(biddingListTotalKey, types, name), &countByte, qu.IntAll(config.Seoconfig["cacheTime"])+RandNum.Intn(randCount)); err != nil {
+							log.Println("存缓存失败:", fmt.Sprintf(biddingListTotalKey, types, name), b.Total)
+						}
+					}
+
 				}
+
 			}
 		}
+	} else {
+		if b.Total != b.PageSize {
+			b.Total = redisCount
+		}
 	}
 	return
 }

+ 4 - 6
src/jfw/modules/app/src/web/templates/tags/index.html

@@ -24,12 +24,10 @@
         {{if .T.winnerList}}
             {{include "/tags/template/tag-card-ent.html"}}
         {{end}}
-        {{if .T.biddingList}}
-            {{if or .T.prevPage .T.nextPage}}
-                {{include "/tags/template/tag-card-bidding-info-list.html"}}
-            {{else}}
-                {{include "/tags/template/bidding-card-list.html"}}
-            {{end}}
+        {{if and  .T.biddingList .T.isInfoList}}
+            {{include "/tags/template/tag-card-bidding-info-list.html"}}
+        {{else}}
+            {{include "/tags/template/bidding-card-list.html"}}
         {{end}}
         {{if .T.industryNav}}
             {{include "/tags/template/tag-card-industry-nav.html"}}