xzs_choose_category.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxXzsChooseCategory struct {
  7. Id int `orm:"column(id);pk"`
  8. UserId int `description:"用户ID"`
  9. Mobile string `description:"手机号"`
  10. Email string `description:"邮箱"`
  11. CompanyId int `description:"公司id"`
  12. CompanyName string `description:"公司名称"`
  13. RealName string `description:"用户实际名称"`
  14. CategoryId int `description:"权益文章对应分类,cygx_article"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. }
  18. //根据手机号获取用户关注的产业
  19. func GetCygxXzsChooseCategoryList(mobile string) (items []*CygxXzsChooseCategory, err error) {
  20. o := orm.NewOrm()
  21. sql := `SELECT * FROM cygx_xzs_choose_category WHERE mobile = ?`
  22. _, err = o.Raw(sql, mobile).QueryRows(&items)
  23. return
  24. }
  25. //添加
  26. func AddCygxCategoryFllow(item *CygxXzsChooseCategory) (lastId int64, err error) {
  27. o := orm.NewOrm()
  28. lastId, err = o.Insert(item)
  29. return
  30. }
  31. //删除
  32. func RemoveCygxCategoryFllow(mobile string, CategoryId int) (err error) {
  33. o := orm.NewOrm()
  34. sql := `DELETE FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? `
  35. _, err = o.Raw(sql, mobile, CategoryId).Exec()
  36. return
  37. }
  38. //获取产业数量
  39. func GetCategoryCount(categoryId int) (count int, err error) {
  40. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_report_mapping WHERE category_id=? `
  41. o := orm.NewOrm()
  42. err = o.Raw(sqlCount, categoryId).QueryRow(&count)
  43. return
  44. }
  45. //获取关注数量
  46. func GetCountCategoryFllow(categoryId int, mobile, condition string) (count int, err error) {
  47. sql := `SELECT COUNT(1) AS count FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? ` + condition
  48. err = orm.NewOrm().Raw(sql, mobile, categoryId).QueryRow(&count)
  49. return
  50. }