wx_template_msg.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. func GetWxOpenIdByMobileList(mobile string) (items []*OpenIdList, err error) {
  30. sliceMobile := strings.Split(mobile, ",")
  31. var mobiles []string
  32. for _, v := range sliceMobile {
  33. mobiles = append(mobiles, v)
  34. }
  35. o := orm.NewOrm()
  36. lenarr := len(mobiles)
  37. if lenarr == 0 {
  38. return
  39. }
  40. var condition string
  41. var pars []interface{}
  42. condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
  43. pars = append(pars, mobiles)
  44. sql := `SELECT
  45. u.open_id,
  46. u.cygx_user_id AS user_id
  47. FROM
  48. cygx_user_record AS u
  49. WHERE
  50. 1 = 1 ` + condition
  51. _, err = o.Raw(sql, pars).QueryRows(&items)
  52. return
  53. }
  54. type AdminOpenIdList struct {
  55. OpenId string `description:"OpenId"`
  56. UserId int `description:"UserId"`
  57. Mobile string `description:"手机号"`
  58. CompanyId int `description:"手机号"`
  59. }
  60. // GetAdminOpendidByCompany 通过用户公司ID获取对应销售的openid
  61. func GetAdminOpendidByCompany(condition string, pars []interface{}) (list []*AdminOpenIdList, err error) {
  62. o := orm.NewOrmUsingDB("weekly_report")
  63. sql := `SELECT
  64. a.mobile,
  65. p.company_id
  66. FROM
  67. company_product AS p
  68. INNER JOIN admin AS a ON a.admin_id = p.seller_id
  69. WHERE
  70. 1 = 1
  71. AND p.product_id = 2 ` + condition
  72. _, err = o.Raw(sql, pars).QueryRows(&list)
  73. return
  74. }
  75. //func GetWxOpenIdByMobileSliceList(mobiles []string) (items []*OpenIdList, err error) {
  76. // itemsLen := len(mobiles)
  77. // if itemsLen == 0 {
  78. // return
  79. // }
  80. // o := orm.NewOrm()
  81. // sql := `SELECT cr.*,user_id FROM user_record as c
  82. // INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  83. // WHERE bind_account IN (` + utils.GetOrmInReplace(itemsLen) + `) AND create_platform = 4`
  84. // _, err = o.Raw(sql, mobiles).QueryRows(&items)
  85. // return
  86. //}
  87. // 根据手机号获取用户的openid
  88. func GetWxOpenIdByMobileSliceList(mobiles []string) (items []*OpenIdList, err error) {
  89. o := orm.NewOrm()
  90. lenarr := len(mobiles)
  91. if lenarr == 0 {
  92. return
  93. }
  94. var condition string
  95. var pars []interface{}
  96. condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
  97. pars = append(pars, mobiles)
  98. sql := `SELECT
  99. u.open_id,
  100. u.cygx_user_id AS user_id
  101. FROM
  102. cygx_mfyx_gzh_user_record AS u
  103. WHERE
  104. 1 = 1 ` + condition
  105. _, err = o.Raw(sql, pars).QueryRows(&items)
  106. return
  107. }