xzs_choose_category.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 GetCygxXzsChooseCategoryListByCon(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxXzsChooseCategory, err error) {
  29. o := orm.NewOrm()
  30. sql := `SELECT * FROM cygx_xzs_choose_category as art WHERE 1= 1 `
  31. if condition != "" {
  32. sql += condition
  33. }
  34. //sql += ` LIMIT ?,? `
  35. _, err = o.Raw(sql, pars).QueryRows(&items)
  36. return
  37. }
  38. // 添加
  39. func AddCygxCategoryFllow(item *CygxXzsChooseCategory) (lastId int64, err error) {
  40. o := orm.NewOrm()
  41. lastId, err = o.Insert(item)
  42. return
  43. }
  44. // 删除
  45. func RemoveCygxCategoryFllow(mobile string, CategoryId int) (err error) {
  46. o := orm.NewOrm()
  47. sql := `DELETE FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? `
  48. _, err = o.Raw(sql, mobile, CategoryId).Exec()
  49. return
  50. }
  51. // 根据手机号获取用户关注的产业
  52. func GetCygxXzsChooseCategoryWhithIdCygxList() (items []*CygxXzsChooseCategory, err error) {
  53. o := orm.NewOrm()
  54. sql := `SELECT * FROM cygx_xzs_choose_category WHERE id_cygx = 0`
  55. _, err = o.Raw(sql).QueryRows(&items)
  56. return
  57. }
  58. type XzsChooseMapResp struct {
  59. Id int `description:"id"`
  60. CategoryId int `description:"权益文章对应分类,cygx_article"`
  61. CharPpermissionName string `description:"权限名称"`
  62. MatchTypeName string `description:"分类名称"`
  63. }
  64. // 根据手机号获取用户关注的产业
  65. func GetCygxXzsChooseCategoryMapList() (items []*XzsChooseMapResp, err error) {
  66. o := orm.NewOrm()
  67. sql := `SELECT
  68. r.id,
  69. r.chart_permission_name,
  70. r.match_type_name,
  71. c.category_id
  72. FROM
  73. cygx_report_mapping_cygx AS r
  74. INNER JOIN cygx_report_mapping_group AS p ON p.id_cygx = r.id
  75. INNER JOIN cygx_report_mapping_celue AS c ON c.category_id = p.category_id_celue
  76. WHERE
  77. r.chart_permission_id IN (23,100000)`
  78. _, err = o.Raw(sql).QueryRows(&items)
  79. return
  80. }
  81. // 修改数据
  82. func UpdateCygxXzsChooseCategory(idCygx, id int) (err error) {
  83. o := orm.NewOrm()
  84. sql := `UPDATE cygx_xzs_choose_category SET id_cygx=? WHERE id=? `
  85. _, err = o.Raw(sql, idCygx, id).Exec()
  86. return
  87. }
  88. // 列表
  89. func GetCygxXzsChooseCategoryListFollowType(categoryId, followType int) (items []*CygxXzsChooseCategory, err error) {
  90. o := orm.NewOrm()
  91. sql := `SELECT * FROM cygx_xzs_choose_category as art WHERE category_id = ? AND follow_type = ? `
  92. _, err = o.Raw(sql, categoryId, followType).QueryRows(&items)
  93. return
  94. }
  95. // 获取重点关注数量
  96. func GetCountCygxXzsChooseCategoryFllowByType(userId, categoryId int) (count int, err error) {
  97. sql := `SELECT COUNT(1) AS count FROM cygx_xzs_choose_category WHERE user_id=? AND category_id=? AND follow_type = 1 `
  98. err = orm.NewOrm().Raw(sql, userId, categoryId).QueryRow(&count)
  99. return
  100. }