Browse Source

no message

xingzai 1 year ago
parent
commit
2f086598f3
2 changed files with 14 additions and 7 deletions
  1. 8 1
      controllers/search.go
  2. 6 6
      models/search_key_word.go

+ 8 - 1
controllers/search.go

@@ -7,6 +7,7 @@ import (
 	"hongze/hongze_clpt/services"
 	"hongze/hongze_clpt/utils"
 	"strings"
+	"time"
 )
 
 type SearchController struct {
@@ -308,7 +309,13 @@ func (this *MobileSearchController) BrowseHistoryList() {
 		item.KeyWord = v
 		resp.ListRecommend = append(resp.ListRecommend, item)
 	}
-	hotList, err := models.GetSearchKeyWordTop()
+	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 + "'"
+	hotList, err := models.GetSearchKeyWordTop(condition, pars)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取用户信息失败,Err:" + err.Error()

+ 6 - 6
models/search_key_word.go

@@ -17,14 +17,14 @@ type CygxSearchKeyWord struct {
 	RealName    string `description:"用户实际名称"`
 }
 
-//新增搜索
+// 新增搜索
 func AddSearchKeyWord(item *CygxSearchKeyWord) (lastId int64, err error) {
 	o := orm.NewOrm()
 	lastId, err = o.Insert(item)
 	return
 }
 
-//获取用户搜索这个关键词的最新时间
+// 获取用户搜索这个关键词的最新时间
 func GetNewSearchKeyWordByThisUser(uid int, keyWord string) (item *CygxSearchKeyWord, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM cygx_search_key_word WHERE user_id = ? AND key_word = ? ORDER BY id DESC LIMIT 1 `
@@ -32,8 +32,8 @@ func GetNewSearchKeyWordByThisUser(uid int, keyWord string) (item *CygxSearchKey
 	return
 }
 
-//获取用户搜索词汇频率较高的词
-func GetSearchKeyWordTop() (items []*CygxSearchKeyWord, err error) {
+// 获取用户搜索词汇频率较高的词
+func GetSearchKeyWordTop(condition string, pars []interface{}) (items []*CygxSearchKeyWord, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT key_word, COUNT(*) AS num FROM cygx_search_key_word GROUP BY key_word ORDER BY num DESC LIMIT 8 `
 	_, err = o.Raw(sql).QueryRows(&items)
@@ -47,7 +47,7 @@ func GetCygxSearchKeyWordList(condition string) (items []*CygxSearchKeyWord, err
 	return
 }
 
-//修改用户搜索的相关信息
+// 修改用户搜索的相关信息
 func UpdateCygxSearchKeyWord(wxUser *WxUserItem) (err error) {
 	o := orm.NewOrm()
 	var sql string
@@ -61,7 +61,7 @@ func UpdateCygxSearchKeyWord(wxUser *WxUserItem) (err error) {
 	return
 }
 
-//GetSearchKeyWordByUser 获取用户搜索历史记录
+// GetSearchKeyWordByUser 获取用户搜索历史记录
 func GetSearchKeyWordByUser(uid int) (items []*KeyWord, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT key_word, MAX( id ) AS maxId  FROM	cygx_search_key_word_log WHERE	user_id = ? GROUP BY	key_word ORDER BY	maxId DESC 	LIMIT 8 `