wx_user_code.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type WxUserCode struct {
  7. Id int `orm:"column(id);pk"`
  8. WxCode string
  9. UserId int
  10. Code int
  11. FirstLogin int
  12. Authorization string
  13. UserPermission int
  14. CreateTime time.Time
  15. }
  16. // 添加联系人日志信息
  17. func AddWxUserCode(item *WxUserCode) (lastId int64, err error) {
  18. o := orm.NewOrmUsingDB("weekly_report")
  19. lastId, err = o.Insert(item)
  20. return
  21. }
  22. func GetWxUserCode(wxCode string) (item *WxUserCode, err error) {
  23. o := orm.NewOrmUsingDB("weekly_report")
  24. sql := `SELECT * FROM wx_user_code WHERE wx_code=? `
  25. err = o.Raw(sql, wxCode).QueryRow(&item)
  26. return
  27. }
  28. // 获取所有有权限的用户的手机号
  29. func GetCygxUserRecordPower(condition string, pars []interface{}) (items []*OpenIdList, err error) {
  30. o := orm.NewOrmUsingDB("weekly_report")
  31. sql := `SELECT
  32. u.user_id,
  33. u.company_id,
  34. u.real_name,
  35. u.mobile
  36. FROM
  37. company_report_permission AS p
  38. INNER JOIN wx_user AS u ON u.company_id = p.company_id
  39. INNER JOIN user_record AS r ON r.user_id = u.user_id
  40. WHERE
  41. r.create_platform = 4 ` + condition + `
  42. AND p.STATUS IN ( '正式', '试用', '永续' )
  43. GROUP BY u.mobile `
  44. _, err = o.Raw(sql, pars).QueryRows(&items)
  45. return
  46. }
  47. // 获取关注这个文章对应产业的用户的 openid
  48. func GetCygxUserFllowOpenid(articleId int) (items []*OpenIdList, err error) {
  49. o := orm.NewOrm()
  50. sql := `SELECT
  51. f.mobile,
  52. f.user_id
  53. FROM
  54. cygx_xzs_choose_send AS s
  55. INNER JOIN cygx_industry_fllow AS f ON f.user_id = s.user_id
  56. INNER JOIN cygx_industrial_article_group_management AS mg ON mg.industrial_management_id = f.industrial_management_id
  57. WHERE
  58. 1 = 1
  59. AND mg.article_id = ?
  60. AND f.follow_type = 1
  61. GROUP BY f.user_id `
  62. _, err = o.Raw(sql, articleId).QueryRows(&items)
  63. return
  64. }
  65. // 获取拒绝接收推送的的用户的 openid
  66. func GetCygxUserRefusetOpenid() (items []*OpenIdList, err error) {
  67. o := orm.NewOrm()
  68. sql := `SELECT
  69. cr.open_id,
  70. cr.cygx_user_id AS user_id
  71. FROM
  72. cygx_xzs_choose_send AS s
  73. INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
  74. WHERE
  75. 1 = 1
  76. AND s.is_refuse = 1`
  77. _, err = o.Raw(sql).QueryRows(&items)
  78. return
  79. }
  80. // 获取选择策略推送的用户的openid openid
  81. func GetCygxUserFllowCeLueOpenid(categoryId int) (items []*OpenIdList, err error) {
  82. o := orm.NewOrm()
  83. sql := `SELECT
  84. cr.open_id,
  85. cr.cygx_user_id AS user_id
  86. FROM
  87. cygx_xzs_choose_send AS s
  88. INNER JOIN cygx_xzs_choose_category AS f ON f.user_id = s.user_id
  89. INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
  90. WHERE
  91. 1 = 1
  92. AND s.is_refuse = 0
  93. AND ( s.is_subjective = 1 OR s.is_objective = 1 )
  94. AND f.category_id = ?
  95. GROUP BY
  96. s.user_id `
  97. _, err = o.Raw(sql, categoryId).QueryRows(&items)
  98. return
  99. }
  100. // 获取提交过推送规则用户的userId
  101. //func GetCygxXzsChooseSendOpenIdByUserIds(idStr string) (items []*OpenIdList, err error) {
  102. // o := orm.NewOrm()
  103. // sql := `SELECT ur.user_id, cr.open_id FROM user_record AS ur
  104. //INNER JOIN cygx_user_record AS cr
  105. //WHERE ur.user_id IN (` + idStr + `) AND create_platform=4 AND ur.union_id=cr.union_id `
  106. // _, err = o.Raw(sql).QueryRows(&items)
  107. // return
  108. //}