industry_fllow.go 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. }
  20. type CygxIndustryFllowRep struct {
  21. IndustrialManagementId int `description:"产业D"`
  22. }
  23. type CygxCategoryFllowRep struct {
  24. CategoryId int `description:"分类ID"`
  25. }
  26. // 根据手机号获取用户关注的产业
  27. func GetCygxIndustryFllowList(mobile string) (items []*CygxIndustryFllow, err error) {
  28. o := orm.NewOrm()
  29. sql := `SELECT * FROM cygx_industry_fllow WHERE mobile = ?`
  30. _, err = o.Raw(sql, mobile).QueryRows(&items)
  31. return
  32. }
  33. type CygxIndustryFllowResp struct {
  34. Status int `description:"1:关注,2:取消关注"`
  35. }
  36. // 获取数量
  37. func GetCountCygxIndustryFllowByUid(userId int) (count int, err error) {
  38. sql := `SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id=? `
  39. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  40. return
  41. }
  42. // 添加
  43. func AddCygxIndustryFllow(item *CygxIndustryFllow) (lastId int64, err error) {
  44. o := orm.NewOrm()
  45. lastId, err = o.Insert(item)
  46. return
  47. }
  48. // 删除
  49. func RemoveCygxIndustryFllow(userId, industrialManagementId int) (err error) {
  50. o := orm.NewOrm()
  51. sql := `DELETE FROM cygx_industry_fllow WHERE user_id=? AND industrial_management_id=? `
  52. _, err = o.Raw(sql, userId, industrialManagementId).Exec()
  53. return
  54. }
  55. // 获取某个用户关注某个行业下的产业数量
  56. func GetCountCygxIndustryFllowByUidAndChartPermissionId(userId, ChartPermissionId int) (count int, err error) {
  57. sql := `SELECT
  58. COUNT( 1 ) AS count
  59. FROM
  60. cygx_industry_fllow AS f
  61. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  62. WHERE
  63. user_id = ?
  64. AND m.chart_permission_id = ? `
  65. err = orm.NewOrm().Raw(sql, userId, ChartPermissionId).QueryRow(&count)
  66. return
  67. }
  68. // 获取用户关注的产业列表
  69. func GetUserFllowIndustrialList(userId int) (items []*CygxIndustryFllow, err error) {
  70. o := orm.NewOrm()
  71. sql := `SELECT
  72. f.user_id,
  73. m.industry_name,
  74. m.industrial_management_id
  75. FROM
  76. cygx_industry_fllow AS f
  77. INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = f.industrial_management_id
  78. WHERE
  79. 1 = 1
  80. AND f.user_id = ? `
  81. _, err = o.Raw(sql, userId).QueryRows(&items)
  82. return
  83. }