search_key_word.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  17. //新增搜索
  18. func AddSearchKeyWord(item *CygxSearchKeyWord) (lastId int64, err error) {
  19. o := orm.NewOrm()
  20. lastId, err = o.Insert(item)
  21. return
  22. }
  23. //获取用户搜索这个关键词的最新时间
  24. func GetNewSearchKeyWordByThisUser(uid int, keyWord string) (item *CygxSearchKeyWord, err error) {
  25. o := orm.NewOrm()
  26. sql := `SELECT * FROM cygx_search_key_word WHERE user_id = ? AND key_word = ? ORDER BY id DESC LIMIT 1 `
  27. err = o.Raw(sql, uid, keyWord).QueryRow(&item)
  28. return
  29. }
  30. //获取用户搜索词汇频率较高的词
  31. func GetSearchKeyWordTop() (items []*CygxSearchKeyWord, err error) {
  32. o := orm.NewOrm()
  33. sql := `SELECT key_word, COUNT(*) AS num FROM cygx_search_key_word GROUP BY key_word ORDER BY num DESC LIMIT 8 `
  34. _, err = o.Raw(sql).QueryRows(&items)
  35. return
  36. }
  37. func GetCygxSearchKeyWordList(condition string) (items []*CygxSearchKeyWord, err error) {
  38. o := orm.NewOrm()
  39. sql := `SELECT * FROM cygx_search_key_word WHERE 1 = 1 ` + condition + ` GROUP BY user_id `
  40. _, err = o.Raw(sql).QueryRows(&items)
  41. return
  42. }
  43. //修改用户搜索的相关信息
  44. func UpdateCygxSearchKeyWord(wxUser *WxUserItem) (err error) {
  45. o := orm.NewOrm()
  46. var sql string
  47. if wxUser.Mobile != "" {
  48. sql = `UPDATE cygx_search_key_word SET email=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE mobile=? `
  49. _, err = o.Raw(sql, wxUser.Email, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Mobile).Exec()
  50. } else if wxUser.Email != "" {
  51. sql = `UPDATE cygx_search_key_word SET mobile=?,company_id=?,company_name=?,user_id=?,real_name=? WHERE email=? `
  52. _, err = o.Raw(sql, wxUser.Mobile, wxUser.CompanyId, wxUser.CompanyName, wxUser.UserId, wxUser.RealName, wxUser.Email).Exec()
  53. }
  54. return
  55. }