xzs_choose_category_zhouqi.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxXzsChooseCategoryZhouqi 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_zhouqi_article_map 表主键"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  18. }
  19. // 根据手机号获取用户关注的产业
  20. func GetCygxXzsChooseCategoryZhouqiList(mobile string) (items []*CygxXzsChooseCategoryZhouqi, err error) {
  21. o := orm.NewOrm()
  22. sql := `SELECT * FROM cygx_xzs_choose_category_zhouqi WHERE mobile = ?`
  23. _, err = o.Raw(sql, mobile).QueryRows(&items)
  24. return
  25. }
  26. // 添加
  27. func AddCygxCategoryFllowZhouqi(item *CygxXzsChooseCategoryZhouqi) (lastId int64, err error) {
  28. o, err := orm.NewOrm().Begin()
  29. if err != nil {
  30. return
  31. }
  32. defer func() {
  33. if err == nil {
  34. o.Commit()
  35. } else {
  36. o.Rollback()
  37. }
  38. }()
  39. sql := `DELETE FROM cygx_xzs_choose_category_zhouqi WHERE mobile=? AND category_id=? `
  40. _, err = o.Raw(sql, item.Mobile, item.CategoryId).Exec()
  41. if err != nil {
  42. return
  43. }
  44. lastId, err = o.Insert(item)
  45. return
  46. }
  47. // 删除
  48. func RemoveCygxCategoryFllowZhouqi(mobile string, CategoryId int) (err error) {
  49. o := orm.NewOrm()
  50. sql := `DELETE FROM cygx_xzs_choose_category_zhouqi WHERE mobile=? AND category_id=? `
  51. _, err = o.Raw(sql, mobile, CategoryId).Exec()
  52. return
  53. }
  54. // 获取关注数量
  55. func GetCountCategoryFllowZhouqi(categoryId int, mobile string) (count int, err error) {
  56. sql := `SELECT COUNT(1) AS count FROM cygx_xzs_choose_category_zhouqi WHERE mobile=? AND category_id=? `
  57. err = orm.NewOrm().Raw(sql, mobile, categoryId).QueryRow(&count)
  58. return
  59. }
  60. type XzsChooseMapZhouqiResp struct {
  61. Id int `description:"id"`
  62. CategoryId int `description:"权益文章对应分类,cygx_article"`
  63. CharPpermissionName string `description:"权限名称"`
  64. MatchTypeName string `description:"分类名称"`
  65. }