wx_user_code.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. GROUP BY f.user_id `
  61. _, err = o.Raw(sql, articleId).QueryRows(&items)
  62. return
  63. }
  64. // 获取拒绝接收推送的的用户的 openid
  65. func GetCygxUserRefusetOpenid() (items []*OpenIdList, err error) {
  66. o := orm.NewOrm()
  67. sql := `SELECT
  68. cr.open_id,
  69. cr.cygx_user_id AS user_id
  70. FROM
  71. cygx_xzs_choose_send AS s
  72. INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
  73. WHERE
  74. 1 = 1
  75. AND s.is_refuse = 1`
  76. _, err = o.Raw(sql).QueryRows(&items)
  77. return
  78. }
  79. // 获取选择策略推送的用户的openid openid
  80. func GetCygxUserFllowCeLueOpenid(categoryId int) (items []*OpenIdList, err error) {
  81. o := orm.NewOrm()
  82. sql := `SELECT
  83. cr.open_id,
  84. cr.cygx_user_id AS user_id
  85. FROM
  86. cygx_xzs_choose_send AS s
  87. INNER JOIN cygx_xzs_choose_category AS f ON f.user_id = s.user_id
  88. INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
  89. WHERE
  90. 1 = 1
  91. AND s.is_refuse = 0
  92. AND ( s.is_subjective = 1 OR s.is_objective = 1 )
  93. AND f.category_id = ?
  94. GROUP BY
  95. s.user_id `
  96. _, err = o.Raw(sql, categoryId).QueryRows(&items)
  97. return
  98. }
  99. // 获取提交过推送规则用户的userId
  100. //func GetCygxXzsChooseSendOpenIdByUserIds(idStr string) (items []*OpenIdList, err error) {
  101. // o := orm.NewOrm()
  102. // sql := `SELECT ur.user_id, cr.open_id FROM user_record AS ur
  103. //INNER JOIN cygx_user_record AS cr
  104. //WHERE ur.user_id IN (` + idStr + `) AND create_platform=4 AND ur.union_id=cr.union_id `
  105. // _, err = o.Raw(sql).QueryRows(&items)
  106. // return
  107. //}