xzs_choose_category.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. }
  19. // 根据手机号获取用户关注的产业
  20. func GetCygxXzsChooseCategoryList(mobile string) (items []*CygxXzsChooseCategory, err error) {
  21. o := orm.NewOrm()
  22. sql := `SELECT * FROM cygx_xzs_choose_category WHERE mobile = ?`
  23. _, err = o.Raw(sql, mobile).QueryRows(&items)
  24. return
  25. }
  26. // 添加
  27. func AddCygxCategoryFllow(item *CygxXzsChooseCategory) (lastId int64, err error) {
  28. o := orm.NewOrm()
  29. lastId, err = o.Insert(item)
  30. return
  31. }
  32. // 删除
  33. func RemoveCygxCategoryFllow(mobile string, CategoryId int) (err error) {
  34. o := orm.NewOrm()
  35. sql := `DELETE FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? `
  36. _, err = o.Raw(sql, mobile, CategoryId).Exec()
  37. return
  38. }
  39. // 获取产业数量
  40. func GetCategoryCount(categoryId int) (count int, err error) {
  41. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_report_mapping WHERE category_id=? `
  42. o := orm.NewOrm()
  43. err = o.Raw(sqlCount, categoryId).QueryRow(&count)
  44. return
  45. }
  46. // 获取关注数量
  47. func GetCountCategoryFllow(categoryId int, mobile, condition string) (count int, err error) {
  48. sql := `SELECT COUNT(1) AS count FROM cygx_xzs_choose_category WHERE mobile=? AND category_id=? ` + condition
  49. err = orm.NewOrm().Raw(sql, mobile, categoryId).QueryRow(&count)
  50. return
  51. }
  52. type XzsChooseMapResp struct {
  53. Id int `description:"id"`
  54. CategoryId int `description:"权益文章对应分类,cygx_article"`
  55. CharPpermissionName string `description:"权限名称"`
  56. MatchTypeName string `description:"分类名称"`
  57. }
  58. // 根据手机号获取用户关注的产业
  59. func GetCygxXzsChooseCategoryMapList() (items []*XzsChooseMapResp, err error) {
  60. o := orm.NewOrm()
  61. sql := `SELECT
  62. r.id,
  63. r.chart_permission_name,
  64. r.match_type_name,
  65. c.category_id
  66. FROM
  67. cygx_report_mapping_cygx AS r
  68. INNER JOIN cygx_report_mapping_group AS p ON p.id_cygx = r.id
  69. INNER JOIN cygx_report_mapping_celue AS c ON c.category_id = p.category_id_celue
  70. WHERE
  71. r.chart_permission_id IN (23,53,100000)`
  72. _, err = o.Raw(sql).QueryRows(&items)
  73. return
  74. }