user_label.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxUserLabelLogRedis struct {
  7. UserId int `description:"用户ID"`
  8. SourceId int `description:"资源ID"`
  9. SourceType int `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
  10. IsFllow int `description:"1关注、0取消关注"`
  11. CreateTime time.Time `description:"创建时间"`
  12. }
  13. type CygxUserLabel struct {
  14. Id int `orm:"column(id);pk"`
  15. UserId int `description:"用户ID"`
  16. CompanyId int `description:"公司id"`
  17. RealName string `description:"用户实际名称"`
  18. Mobile string `description:"手机号"`
  19. Email string `description:"邮箱"`
  20. Label string `description:"标签内容"`
  21. Weight int `description:"权重"`
  22. SourceId int `description:"来源ID(产业ID,系列ID)"`
  23. Source int `description:"来源1:产业、2:系列"`
  24. IsFollow int `description:"是否关注,1是,0否"`
  25. CreateTime time.Time `description:"创建时间"`
  26. ModifyTime time.Time `description:"更新时间"`
  27. }
  28. // 获取数量
  29. func GetCygxUserLabelCount(condition string, pars []interface{}) (count int, err error) {
  30. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_user_label as art WHERE 1= 1 AND modify_time > DATE_SUB(CURDATE(), INTERVAL 3 MONTH) `
  31. if condition != "" {
  32. sqlCount += condition
  33. }
  34. o := orm.NewOrmUsingDB("hz_cygx")
  35. err = o.Raw(sqlCount, pars).QueryRow(&count)
  36. return
  37. }
  38. // 添加
  39. func AddCygxUserLabel(item *CygxUserLabel) (lastId int64, err error) {
  40. o := orm.NewOrmUsingDB("hz_cygx")
  41. lastId, err = o.Insert(item)
  42. return
  43. }
  44. // 修改是否关注
  45. func UpdateCygxUserLabelIsFollow(isFollow, sourceId, source, userId int, label string) (err error) {
  46. o := orm.NewOrmUsingDB("hz_cygx")
  47. sql := `UPDATE cygx_user_label SET is_follow=?,label = ? , modify_time=NOW() WHERE source_id=? AND source = ? AND user_id = ? `
  48. _, err = o.Raw(sql, isFollow, label, sourceId, source, userId).Exec()
  49. return
  50. }
  51. // 修改对应标签权重+1
  52. func UpdateCygxUserLabelWeight(sourceId, source, userId int, label string) (err error) {
  53. o := orm.NewOrmUsingDB("hz_cygx")
  54. sql := `UPDATE cygx_user_label SET weight = weight +1 ,label = ? , modify_time=NOW() WHERE source_id=? AND source = ? AND user_id = ? `
  55. _, err = o.Raw(sql, label, sourceId, source, userId).Exec()
  56. return
  57. }
  58. // 列表
  59. func GetCygxUserLabelList(condition string, pars []interface{}) (items []*CygxUserLabel, err error) {
  60. o := orm.NewOrmUsingDB("hz_cygx")
  61. sql := `SELECT * FROM cygx_user_label as art WHERE 1= 1 AND modify_time > DATE_SUB(CURDATE(), INTERVAL 3 MONTH) `
  62. if condition != "" {
  63. sql += condition
  64. }
  65. _, err = o.Raw(sql, pars).QueryRows(&items)
  66. return
  67. }