industry_fllow.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxIndustryFllow struct {
  7. Id int `orm:"column(id);pk"`
  8. IndustrialManagementId int `description:"产业D"`
  9. UserId int `description:"用户ID"`
  10. Mobile string `description:"手机号"`
  11. Email string `description:"邮箱"`
  12. CompanyId int `description:"公司id"`
  13. CompanyName string `description:"公司名称"`
  14. Type int `description:"操作方式,1报名,2取消报名"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"更新时间"`
  17. RealName string `description:"用户实际名称"`
  18. Source int `description:"来源1查研观向,2查研观向小助手"`
  19. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  20. }
  21. type CygxIndustryFllowRep struct {
  22. IndustrialManagementId int `description:"产业D"`
  23. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  24. }
  25. type CygxCategoryFllowRep struct {
  26. CategoryId int `description:"分类ID"`
  27. FollowType int `description:"1,重点关注,3不感兴趣,0默认接受推送"`
  28. }
  29. // 根据手机号获取用户关注的产业
  30. func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err error) {
  31. o := orm.NewOrm()
  32. sql := `SELECT * FROM cygx_industry_fllow WHERE mobile = ?`
  33. _, err = o.Raw(sql, mobile).QueryRows(&items)
  34. return
  35. }
  36. type CygxIndustryFllowResp struct {
  37. Status int `description:"1:关注,2:取消关注"`
  38. }
  39. // 获取数量
  40. func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) {
  41. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? `
  42. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  43. return
  44. }
  45. // 添加
  46. func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
  47. o, err := orm.NewOrm().Begin()
  48. if err != nil {
  49. return
  50. }
  51. defer func() {
  52. if err == nil {
  53. o.Commit()
  54. } else {
  55. o.Rollback()
  56. }
  57. }()
  58. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? `
  59. _, err = o.Raw(sql, item.UserId, item.IndustrialManagementId).Exec()
  60. if err != nil {
  61. return
  62. }
  63. lastId, err = o.Insert(item)
  64. return
  65. }
  66. // 删除
  67. func RemoveCygxIndustryFllow(userId, industrialManagementId int) (err error) {
  68. o := orm.NewOrm()
  69. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? `
  70. _, err = o.Raw(sql, userId, industrialManagementId).Exec()
  71. return
  72. }
  73. // 获取某个用户关注某个行业下的产业数量
  74. func GetCountCygxIndustryFllowByUidAndChartPermissionId(userId, ChartPermissionId int) (count int, err error) {
  75. sql := `SELECT
  76. COUNT( 1 ) AS count
  77. FROM
  78. cygx_industry_fllow AS f
  79. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  80. WHERE
  81. user_id = ?
  82. AND m.chart_permission_id = ? `
  83. err = orm.NewOrm().Raw(sql, userId, ChartPermissionId).QueryRow(&count)
  84. return
  85. }
  86. // 获取用户关注的产业列表
  87. func GetUserFllowIndustrialList(userId int) (items []*CygxIndustryFllow, err error) {
  88. o := orm.NewOrm()
  89. sql := `SELECT
  90. f.user_id,
  91. f.follow_type,
  92. m.industry_name,
  93. m.industrial_management_id
  94. FROM
  95. cygx_industry_fllow AS f
  96. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  97. WHERE
  98. 1 = 1
  99. AND f.user_id = ? `
  100. _, err = o.Raw(sql, userId).QueryRows(&items)
  101. return
  102. }