wx_template_msg.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_cygx/utils"
  5. )
  6. type SendTemplateResponse struct {
  7. Errcode int `json:"errcode"`
  8. Errmsg string `json:"errmsg"`
  9. MsgID int `json:"msgid"`
  10. }
  11. type OpenIdList struct {
  12. OpenId string
  13. UserId int
  14. Mobile string `description:"手机号"`
  15. }
  16. func GetOpenIdList() (items []*OpenIdList, err error) {
  17. o := orm.NewOrmUsingDB("weekly_report")
  18. openIdstr := WxUsersGet()
  19. sql := `SELECT open_id FROM wx_user AS wu
  20. INNER JOIN company AS c ON c.company_id = wu.company_id
  21. WHERE wu.open_id IS NOT NULL AND c.type IN (1,2) `
  22. if openIdstr != "" {
  23. sql += ` AND open_id in (` + openIdstr + `) `
  24. }
  25. _, err = o.Raw(sql).QueryRows(&items)
  26. return
  27. }
  28. func GetWxOpenIdByMobileList(mobile string) (items []*OpenIdList, err error) {
  29. sql := ` SELECT
  30. union_id,open_id,
  31. cygx_user_id AS user_id
  32. FROM cygx_user_record WHERE 1 = 1 AND cygx_bind_account IN (` + mobile + `)`
  33. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  34. return
  35. }
  36. type AdminOpenIdList struct {
  37. OpenId string `description:"OpenId"`
  38. UserId int `description:"UserId"`
  39. Mobile string `description:"手机号"`
  40. CompanyId int `description:"手机号"`
  41. }
  42. // GetAdminOpendidByCompany 通过用户公司ID获取对应销售的openid
  43. func GetAdminOpendidByCompany(condition string, pars []interface{}) (list []*AdminOpenIdList, err error) {
  44. o := orm.NewOrmUsingDB("weekly_report")
  45. sql := `SELECT
  46. a.mobile,
  47. p.company_id
  48. FROM
  49. company_product AS p
  50. INNER JOIN admin AS a ON a.admin_id = p.seller_id
  51. WHERE
  52. 1 = 1
  53. AND p.product_id = 2 ` + condition
  54. _, err = o.Raw(sql, pars).QueryRows(&list)
  55. return
  56. }
  57. //func GetWxOpenIdByMobileSliceList(mobiles []string) (items []*OpenIdList, err error) {
  58. // itemsLen := len(mobiles)
  59. // if itemsLen == 0 {
  60. // return
  61. // }
  62. // o := orm.NewOrm()
  63. // sql := `SELECT cr.*,user_id FROM user_record as c
  64. // INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  65. // WHERE bind_account IN (` + utils.GetOrmInReplace(itemsLen) + `) AND create_platform = 4`
  66. // _, err = o.Raw(sql, mobiles).QueryRows(&items)
  67. // return
  68. //}
  69. // 根据手机号获取用户的openid
  70. func GetWxOpenIdByMobileSliceList(mobiles []string) (items []*OpenIdList, err error) {
  71. o := orm.NewOrm()
  72. lenarr := len(mobiles)
  73. if lenarr == 0 {
  74. return
  75. }
  76. var condition string
  77. var pars []interface{}
  78. condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
  79. pars = append(pars, mobiles)
  80. sql := `SELECT
  81. u.open_id,
  82. u.cygx_user_id AS user_id
  83. FROM
  84. cygx_user_record AS u
  85. WHERE
  86. 1 = 1 ` + condition
  87. _, err = o.Raw(sql, pars).QueryRows(&items)
  88. return
  89. }
  90. // 根据手机号获取用户的openid
  91. func GetMfyxWxOpenIdByMobileSliceList(mobiles []string) (items []*OpenIdList, err error) {
  92. o := orm.NewOrm()
  93. lenarr := len(mobiles)
  94. if lenarr == 0 {
  95. return
  96. }
  97. var condition string
  98. var pars []interface{}
  99. condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
  100. pars = append(pars, mobiles)
  101. sql := `SELECT
  102. u.open_id,
  103. u.cygx_user_id AS user_id
  104. FROM
  105. cygx_mfyx_gzh_user_record AS u
  106. WHERE
  107. 1 = 1 ` + condition
  108. _, err = o.Raw(sql, pars).QueryRows(&items)
  109. return
  110. }