wx_template_msg.go 2.9 KB

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