search_key_word.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxSearchKeyWord struct {
  7. Id int `orm:"column(id);" description:"id"`
  8. KeyWord string
  9. UserId int
  10. CreateTime time.Time
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. RealName string `description:"用户实际名称"`
  16. RegisterPlatform int // 来源 1小程序,2:网页、5:研选小程序
  17. }
  18. // 新增搜索
  19. func AddSearchKeyWord(item *CygxSearchKeyWord) (lastId int64, err error) {
  20. o := orm.NewOrm()
  21. lastId, err = o.Insert(item)
  22. return
  23. }
  24. // 获取用户搜索这个关键词的最新时间
  25. func GetNewSearchKeyWordByThisUser(uid int, keyWord string) (item *CygxSearchKeyWord, err error) {
  26. o := orm.NewOrm()
  27. sql := `SELECT * FROM cygx_search_key_word WHERE user_id = ? AND key_word = ? ORDER BY id DESC LIMIT 1 `
  28. err = o.Raw(sql, uid, keyWord).QueryRow(&item)
  29. return
  30. }
  31. // 获取用户搜索词汇频率较高的词
  32. func GetSearchKeyWordTop(condition string, pars []interface{}) (items []*CygxSearchKeyWord, err error) {
  33. o := orm.NewOrm()
  34. 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 `
  35. _, err = o.Raw(sql, pars).QueryRows(&items)
  36. return
  37. }
  38. func GetCygxSearchKeyWordList(condition string) (items []*CygxSearchKeyWord, err error) {
  39. o := orm.NewOrm()
  40. sql := `SELECT * FROM cygx_search_key_word_log WHERE 1 = 1 ` + condition + ` GROUP BY user_id `
  41. _, err = o.Raw(sql).QueryRows(&items)
  42. return
  43. }
  44. // 修改用户搜索的相关信息
  45. func UpdateCygxSearchKeyWord(wxUser *WxUserItem) (err error) {
  46. o := orm.NewOrm()
  47. var sql string
  48. if wxUser.Mobile != "" {
  49. sql = `UPDATE cygx_search_key_word_log SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  50. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  51. } else if wxUser.Email != "" {
  52. sql = `UPDATE cygx_search_key_word_log SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE email=? `
  53. _, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
  54. }
  55. return
  56. }