Explorar o código

Merge branch 'cygx/cygx_15_0_1' of http://8.136.199.33:3000/hongze/hongze_clpt

zhangchuanxing hai 1 semana
pai
achega
61c4a20dec
Modificáronse 2 ficheiros con 41 adicións e 11 borrados
  1. 33 10
      controllers/search.go
  2. 8 1
      models/search_key_word.go

+ 33 - 10
controllers/search.go

@@ -61,10 +61,10 @@ func (this *MobileSearchController) ListHomeArtAndChart() {
 	}
 	//添加映射关系
 	keyWord = strings.ToUpper(keyWord)
-	keyWordDetail, _ := models.GetCygxCygxIkWordMapDetail(keyWord)
-	if keyWordDetail != nil {
-		keyWord = keyWordDetail.KeyWordMap
-	}
+	//keyWordDetail, _ := models.GetCygxCygxIkWordMapDetail(keyWord)
+	//if keyWordDetail != nil {
+	//	keyWord = keyWordDetail.KeyWordMap
+	//}
 	user := this.User
 	if user == nil {
 		br.Msg = "请重新登录"
@@ -306,24 +306,47 @@ func (this *MobileSearchController) BrowseHistoryList() {
 		return
 	}
 	resp := new(models.ConfigResp)
-	hotSearch, err := models.GetHotSearch()
+	//hotSearch, err := models.GetHotSearch()
+	//if err != nil {
+	//	br.Msg = "获取数据失败"
+	//	br.ErrMsg = "获取数据失败,Err:" + err.Error()
+	//	return
+	//}
+	//slicehotSearch := strings.Split(hotSearch, ",")
+	//for _, v := range slicehotSearch {
+	//	if v == "" {
+	//		continue
+	//	}
+	//	slicehotSearchList := strings.Split(v, "/")
+	//	for _, v2 := range slicehotSearchList {
+	//		item := new(models.KeyWord)
+	//		item.KeyWord = v2
+	//		resp.ListRecommend = append(resp.ListRecommend, item)
+	//	}
+	//}
+
+	detailConfig, err := models.GetConfigByCode("cygx_report_selection_subject")
 	if err != nil {
 		br.Msg = "获取数据失败"
 		br.ErrMsg = "获取数据失败,Err:" + err.Error()
 		return
 	}
-	slicehotSearch := strings.Split(hotSearch, ",")
+	slicehotSearch := strings.Split(detailConfig.ConfigValue, ",")
 	for _, v := range slicehotSearch {
+		if v == "" {
+			continue
+		}
 		item := new(models.KeyWord)
 		item.KeyWord = v
 		resp.ListRecommend = append(resp.ListRecommend, item)
 	}
+
 	var condition string
 	var pars []interface{}
-	currentTime := time.Now()
-	starTime := currentTime.AddDate(0, 0, -8).Format("2006-01-02") + " 00:00:00"
-	endTime := currentTime.AddDate(0, 0, -1).Format("2006-01-02") + " 23:59:59"
-	condition += ` AND create_time < ` + "'" + endTime + "'" + `AND create_time > ` + "'" + starTime + "'"
+	starTime := time.Now().AddDate(0, 0, -8).Format(utils.FormatDate)
+	endTime := time.Now().Format(utils.FormatDate)
+	condition += ` AND create_time > ? AND create_time < ?  AND user_id > 0 `
+	pars = append(pars, starTime, endTime)
 	hotList, err := models.GetSearchKeyWordTop(condition, pars)
 	if err != nil {
 		br.Msg = "获取信息失败"

+ 8 - 1
models/search_key_word.go

@@ -36,7 +36,14 @@ func GetNewSearchKeyWordByThisUser(uid int, keyWord string) (item *CygxSearchKey
 // 获取用户搜索词汇频率较高的词
 func GetSearchKeyWordTop(condition string, pars []interface{}) (items []*CygxSearchKeyWord, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT key_word, MAX(create_time) as create_time, COUNT(*) AS num FROM cygx_search_key_word  WHERE 1=1  ` + condition + ` GROUP BY key_word ORDER BY num DESC,create_time DESC LIMIT 12 `
+	sql := `SELECT
+				key_word,
+				MAX(id) as max_id ,
+				COUNT( DISTINCT user_id ) AS unique_user_searches 
+			FROM
+				cygx_search_key_word 
+			WHERE
+				1 = 1 ` + condition + ` GROUP BY key_word ORDER BY unique_user_searches DESC, max_id DESC LIMIT 12 `
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }