industry_fllow.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. //"time"
  6. )
  7. type CygxIndustryFllow struct {
  8. Id int `orm:"column(id);pk"`
  9. IndustrialManagementId int `description:"产业D"`
  10. UserId int `description:"用户ID"`
  11. Mobile string `description:"手机号"`
  12. Email string `description:"邮箱"`
  13. CompanyId int `description:"公司id"`
  14. CompanyName string `description:"公司名称"`
  15. Type int `description:"操作方式,1报名,2取消报名"`
  16. CreateTime time.Time `description:"创建时间"`
  17. ModifyTime time.Time `description:"更新时间"`
  18. RealName string `description:"用户实际名称"`
  19. Source int `description:"来源1查研观向,2查研观向小助手,3勾选全部赛道的用户进行自动关注"`
  20. }
  21. // 列表
  22. func GetCygxIndustryFllowList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxIndustryFllow, err error) {
  23. o := orm.NewOrmUsingDB("hz_cygx")
  24. sql := `SELECT * FROM cygx_industry_fllow WHERE 1= 1 `
  25. if condition != "" {
  26. sql += condition
  27. }
  28. if startSize+pageSize > 0 {
  29. sql += ` LIMIT ?,? `
  30. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  31. } else {
  32. _, err = o.Raw(sql, pars).QueryRows(&items)
  33. }
  34. return
  35. }
  36. // 关注产业列表
  37. func GetCygxIndustryFllowByUser(uid, startSize, pageSize int, condition string) (items []*UserInteraction, err error) {
  38. o := orm.NewOrmUsingDB("hz_cygx")
  39. sql := `SELECT
  40. a.industrial_management_id,
  41. a.industry_name,
  42. f.modify_time as create_time
  43. FROM
  44. cygx_industry_fllow AS f
  45. INNER JOIN cygx_industrial_management AS a ON a.industrial_management_id = f.industrial_management_id
  46. WHERE
  47. f.user_id = ?
  48. AND f.follow_type = 1 ` + condition +
  49. `ORDER BY
  50. f.create_time DESC LIMIT ?,? `
  51. _, err = o.Raw(sql, uid, startSize, pageSize).QueryRows(&items)
  52. return
  53. }
  54. // 关注产业数量
  55. func GetCygxIndustryFllowCount(uid int, condition string) (count int, err error) {
  56. o := orm.NewOrmUsingDB("hz_cygx")
  57. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow as f
  58. INNER JOIN cygx_industrial_management as a ON a.industrial_management_id = f.industrial_management_id
  59. WHERE f.user_id = ? AND f.follow_type = 1 ` + condition
  60. err = o.Raw(sqlCount, uid).QueryRow(&count)
  61. return
  62. }
  63. // 判断用户是否关注这些产业ID
  64. func GetCygxIndustryFllowCountByUser(uid int, industrialManagementd string) (count int, err error) {
  65. o := orm.NewOrmUsingDB("hz_cygx")
  66. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_industry_fllow WHERE user_id = ? AND type = 1 AND industrial_management_id IN (` + industrialManagementd + `)`
  67. err = o.Raw(sqlCount, uid).QueryRow(&count)
  68. return
  69. }
  70. // GetUserFllowIndustrialListByUserIdAndIndustrial 通过用户ID 跟产业ID获取用户关注的产业列表
  71. func GetUserFllowIndustrialListByUserIdAndIndustrial(userIds, industrials string) (items []*CygxIndustryFllow, err error) {
  72. o := orm.NewOrmUsingDB("hz_cygx")
  73. sql := `SELECT * FROM cygx_industry_fllow
  74. WHERE 1 = 1
  75. AND user_id IN ( ` + userIds + ` )
  76. AND industrial_management_id IN ( ` + industrials + `) `
  77. _, err = o.Raw(sql).QueryRows(&items)
  78. return
  79. }
  80. // 批量添加
  81. func AddCygxIndustryFllowMulti(items []*CygxIndustryFllow) (err error) {
  82. o := orm.NewOrmUsingDB("hz_cygx")
  83. if len(items) > 0 {
  84. //批量添加新的关注记录
  85. _, err = o.InsertMulti(len(items), items)
  86. }
  87. return
  88. }
  89. // 获取所有关注了该产业永续客户的openid
  90. func GetCygxForeverUserIndustryFllowOpneidByActivityIds(activityId int) (items []*OpenIdList, err error) {
  91. o := orm.NewOrmUsingDB("hz_cygx")
  92. sql := `SELECT
  93. f.*
  94. FROM
  95. cygx_industrial_activity_group_management AS agm
  96. INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
  97. WHERE
  98. agm.activity_id = ?`
  99. _, err = o.Raw(sql, activityId).QueryRows(&items)
  100. return
  101. }
  102. // 获取所有关注了该产业用户的companyIds
  103. func GetCygxIndustryFollowCompanyIdsByActivityId(activityId int) (item *string, err error) {
  104. o := orm.NewOrmUsingDB("hz_cygx")
  105. sql := ` SELECT
  106. GROUP_CONCAT( DISTINCT f.company_id SEPARATOR ',' ) AS company_ids
  107. FROM
  108. cygx_industrial_activity_group_management AS agm
  109. INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
  110. WHERE
  111. agm.activity_id = ? `
  112. err = o.Raw(sql, activityId).QueryRow(&item)
  113. return
  114. }