xzs_choose_category.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. IdCygx int `description:"cygx_report_mapping_cygx 表主键ID"`
  18. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  19. }
  20. // 根据手机号获取用户关注的产业
  21. func GetCygxXzsChooseCategoryList(mobile string) (items []*CygxXzsChooseCategory, err error) {
  22. o := orm.NewOrm()
  23. sql := `SELECT * FROM cygx_xzs_choose_category WHERE mobile = ?`
  24. _, err = o.Raw(sql, mobile).QueryRows(&items)
  25. return
  26. }
  27. // 添加
  28. func AddCygxCategoryFllow(item *CygxXzsChooseCategory) (lastId int64, err error) {
  29. o, err := orm.NewOrm().Begin()
  30. if err != nil {
  31. return
  32. }
  33. defer func() {
  34. if err == nil {
  35. o.Commit()
  36. } else {
  37. o.Rollback()
  38. }
  39. }()
  40. sql := `DELETE FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? `
  41. _, err = o.Raw(sql, item.Mobile, item.CategoryId).Exec()
  42. if err != nil {
  43. return
  44. }
  45. lastId, err = o.Insert(item)
  46. return
  47. }
  48. // 删除
  49. func RemoveCygxCategoryFllow(mobile string, CategoryId int) (err error) {
  50. o := orm.NewOrm()
  51. sql := `DELETE FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? `
  52. _, err = o.Raw(sql, mobile, CategoryId).Exec()
  53. return
  54. }
  55. // 获取产业数量
  56. func GetCategoryCount(categoryId int) (count int, err error) {
  57. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_report_mapping WHERE category_id=? `
  58. o := orm.NewOrm()
  59. err = o.Raw(sqlCount, categoryId).QueryRow(&count)
  60. return
  61. }
  62. // 获取关注数量
  63. func GetCountCategoryFllow(categoryId int, mobile, condition string) (count int, err error) {
  64. sql := `SELECT COUNT(1) AS count FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? ` + condition
  65. err = orm.NewOrm().Raw(sql, mobile, categoryId).QueryRow(&count)
  66. return
  67. }
  68. type XzsChooseMapResp struct {
  69. Id int `description:"id"`
  70. CategoryId int `description:"权益文章对应分类,cygx_article"`
  71. CharPpermissionName string `description:"权限名称"`
  72. MatchTypeName string `description:"分类名称"`
  73. }
  74. // 根据手机号获取用户关注的产业
  75. func GetCygxXzsChooseCategoryMapList() (items []*XzsChooseMapResp, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT
  78. r.id,
  79. r.chart_permission_name,
  80. r.match_type_name,
  81. c.category_id
  82. FROM
  83. cygx_report_mapping_cygx AS r
  84. INNER JOIN cygx_report_mapping_group AS p ON p.id_cygx = r.id
  85. INNER JOIN cygx_report_mapping_celue AS c ON c.category_id = p.category_id_celue
  86. WHERE
  87. r.chart_permission_id IN (23,53,100000)`
  88. _, err = o.Raw(sql).QueryRows(&items)
  89. return
  90. }