wechat_send_msg.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_mobile_admin/utils"
  5. )
  6. type OpenIdList struct {
  7. OpenId string
  8. UserId int
  9. }
  10. func GetAdminOpenIdByMobile(mobile string) (items []*OpenIdList, err error) {
  11. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  12. INNER JOIN company AS c ON c.company_id = wu.company_id
  13. INNER join user_record as ur on wu.user_id=ur.user_id
  14. WHERE ur.open_id != "" and ur.create_platform=1 AND wu.mobile=? `
  15. _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
  16. return
  17. }
  18. // 根据手机号获取用户的openid查研观向小助手专用
  19. func GetUserRecordListByMobile(platform int, bindAccount string) (items []*OpenIdList, err error) {
  20. var sql string
  21. if utils.RunMode == "release" {
  22. sql = `SELECT cr.open_id FROM user_record as u
  23. INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
  24. WHERE create_platform=? AND bind_account IN (` + bindAccount + `)`
  25. } else {
  26. platform = 1
  27. sql = `SELECT open_id FROM user_record WHERE create_platform =? AND bind_account IN (` + bindAccount + `)`
  28. }
  29. _, err = orm.NewOrm().Raw(sql, platform).QueryRows(&items)
  30. return
  31. }
  32. // 根据手机号获取用户的openid
  33. func GetUserRecordListByMobileArr(bindAccount []string) (items []*OpenIdList, err error) {
  34. o := orm.NewOrmUsingDB("hz_cygx")
  35. lenarr := len(bindAccount)
  36. if lenarr == 0 {
  37. return
  38. }
  39. var condition string
  40. var pars []interface{}
  41. condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
  42. pars = append(pars, bindAccount)
  43. sql := `SELECT
  44. u.open_id,
  45. u.cygx_user_id AS user_id
  46. FROM
  47. cygx_user_record AS u
  48. WHERE
  49. 1 = 1 ` + condition
  50. _, err = o.Raw(sql, pars).QueryRows(&items)
  51. return
  52. }
  53. // 根据手机号获取用户的openid
  54. func GetMfyxUserRecordListByMobileArr(bindAccount []string) (items []*OpenIdList, err error) {
  55. o := orm.NewOrmUsingDB("hz_cygx")
  56. lenarr := len(bindAccount)
  57. if lenarr == 0 {
  58. return
  59. }
  60. var condition string
  61. var pars []interface{}
  62. condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
  63. pars = append(pars, bindAccount)
  64. sql := `SELECT
  65. u.open_id,
  66. u.cygx_user_id AS user_id
  67. FROM
  68. cygx_mfyx_gzh_user_record AS u
  69. WHERE
  70. 1 = 1 ` + condition
  71. _, err = o.Raw(sql, pars).QueryRows(&items)
  72. return
  73. }