package models import ( "github.com/beego/beego/v2/client/orm" "time" ) type CygxUserSearchKeyWord struct { Id int `orm:"column(id);" description:"id"` KeyWord string `description:"关键词"` PageType string `description:"页面类型,活动搜索:ActivitSearch"` UserId int CreateTime time.Time } //新增 func AddUserSearchKeyWord(item *CygxUserSearchKeyWord) (lastId int64, err error) { o := orm.NewOrm() lastId, err = o.Insert(item) return } type UserSearchKeyWord struct { KeyWord string `description:"关键词"` } type UserSearchKeyWordListResp struct { List []*UserSearchKeyWord } //列表 func GetUserSearchKeyWord() (items []*UserSearchKeyWord, err error) { o := orm.NewOrm() sql := `SELECT key_word, key_word AS kw, ( SELECT count( 1 ) FROM cygx_user_search_key_word AS k WHERE k.key_word = kw ) AS key_num FROM cygx_user_search_key_word WHERE page_type = 'ReortSearch' GROUP BY key_word ORDER BY key_num DESC LIMIT 8` _, err = o.Raw(sql).QueryRows(&items) return }