wx_template_msg.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_mfyx/utils"
  5. "strings"
  6. )
  7. type SendTemplateResponse struct {
  8. Errcode int `json:"errcode"`
  9. Errmsg string `json:"errmsg"`
  10. MsgID int `json:"msgid"`
  11. }
  12. type OpenIdList struct {
  13. OpenId string
  14. UserId int
  15. Mobile string `description:"手机号"`
  16. }
  17. func GetOpenIdList() (items []*OpenIdList, err error) {
  18. o := orm.NewOrmUsingDB("weekly_report")
  19. openIdstr := WxUsersGet()
  20. sql := `SELECT open_id FROM wx_user AS wu
  21. INNER JOIN company AS c ON c.company_id = wu.company_id
  22. WHERE wu.open_id IS NOT NULL AND c.type IN (1,2) `
  23. if openIdstr != "" {
  24. sql += ` AND open_id in (` + openIdstr + `) `
  25. }
  26. _, err = o.Raw(sql).QueryRows(&items)
  27. return
  28. }
  29. // 查研观向小助手Openid
  30. func GetWxOpenIdByMobileList(mobile string) (items []*OpenIdList, err error) {
  31. sliceMobile := strings.Split(mobile, ",")
  32. var mobiles []string
  33. for _, v := range sliceMobile {
  34. mobiles = append(mobiles, v)
  35. }
  36. o := orm.NewOrm()
  37. lenarr := len(mobiles)
  38. if lenarr == 0 {
  39. return
  40. }
  41. var condition string
  42. var pars []interface{}
  43. condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
  44. pars = append(pars, mobiles)
  45. sql := `SELECT
  46. u.open_id,
  47. u.cygx_user_id AS user_id
  48. FROM
  49. cygx_user_record AS u
  50. WHERE
  51. 1 = 1 ` + condition
  52. _, err = o.Raw(sql, pars).QueryRows(&items)
  53. return
  54. }
  55. type AdminOpenIdList struct {
  56. OpenId string `description:"OpenId"`
  57. UserId int `description:"UserId"`
  58. Mobile string `description:"手机号"`
  59. CompanyId int `description:"手机号"`
  60. }
  61. // 根据手机号获取用户的openid
  62. func GetWxOpenIdByMobileSliceList(mobiles []string) (items []*OpenIdList, err error) {
  63. o := orm.NewOrm()
  64. lenarr := len(mobiles)
  65. if lenarr == 0 {
  66. return
  67. }
  68. var condition string
  69. var pars []interface{}
  70. condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
  71. pars = append(pars, mobiles)
  72. sql := `SELECT
  73. u.open_id,
  74. u.cygx_user_id AS user_id
  75. FROM
  76. cygx_user_record AS u
  77. WHERE
  78. 1 = 1 ` + condition
  79. _, err = o.Raw(sql, pars).QueryRows(&items)
  80. return
  81. }