user_search_key_word.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxUserSearchKeyWord struct {
  7. Id int `orm:"column(id);" description:"id"`
  8. KeyWord string `description:"关键词"`
  9. PageType string `description:"页面类型,活动搜索:ActivitSearch"`
  10. UserId int
  11. CreateTime time.Time
  12. }
  13. //新增
  14. func AddUserSearchKeyWord(item *CygxUserSearchKeyWord) (lastId int64, err error) {
  15. o := orm.NewOrm()
  16. lastId, err = o.Insert(item)
  17. return
  18. }
  19. type UserSearchKeyWord struct {
  20. KeyWord string `description:"关键词"`
  21. }
  22. type UserSearchKeyWordListResp struct {
  23. List []*UserSearchKeyWord
  24. }
  25. //列表
  26. func GetUserSearchKeyWord() (items []*UserSearchKeyWord, err error) {
  27. o := orm.NewOrm()
  28. sql := `SELECT
  29. key_word,
  30. key_word AS kw,
  31. ( SELECT count( 1 ) FROM cygx_user_search_key_word AS k WHERE k.key_word = kw ) AS key_num
  32. FROM
  33. cygx_user_search_key_word
  34. WHERE
  35. page_type = 'ReortSearch'
  36. GROUP BY
  37. key_word
  38. ORDER BY
  39. key_num DESC
  40. LIMIT 8`
  41. _, err = o.Raw(sql).QueryRows(&items)
  42. return
  43. }