wx_template_msg.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. type SendTemplateResponse struct {
  6. Errcode int `json:"errcode"`
  7. Errmsg string `json:"errmsg"`
  8. MsgID int `json:"msgid"`
  9. }
  10. type OpenIdList struct {
  11. OpenId string
  12. UserId int
  13. }
  14. func GetOpenIdList() (items []*OpenIdList, err error) {
  15. openIdstr := WxUsersGet()
  16. sql := `SELECT open_id FROM wx_user AS wu
  17. INNER JOIN company AS c ON c.company_id = wu.company_id
  18. WHERE wu.open_id IS NOT NULL AND c.type IN (1,2) `
  19. if openIdstr != "" {
  20. sql += ` AND open_id in (` + openIdstr + `) `
  21. }
  22. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  23. return
  24. }
  25. func GetWxOpenIdList() (items []*OpenIdList, err error) {
  26. sql := `SELECT open_id FROM wx_user AS wu
  27. INNER JOIN company AS c ON c.company_id = wu.company_id
  28. WHERE open_id=? `
  29. openId := "oW3Gts7V3hj-sTAE1VDi0MhGlee8"
  30. _, err = orm.NewOrm().Raw(sql, openId).QueryRows(&items)
  31. return
  32. }
  33. func GetWxOpenIdByMobileList(mobile string) (items []*OpenIdList, err error) {
  34. //sql := `SELECT * FROM user_record WHERE bind_account IN (` + utils.WxMsgTemplateIdAskMsgMobile + `) AND create_platform = 1`
  35. sql := `SELECT cr.*,user_id FROM user_record as c
  36. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  37. WHERE bind_account IN (` + mobile + `) AND create_platform = 4`
  38. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  39. return
  40. }
  41. type AdminOpenIdList struct {
  42. OpenId string `description:"OpenId"`
  43. UserId int `description:"UserId"`
  44. Mobile string `description:"手机号"`
  45. CompanyId int `description:"手机号"`
  46. }
  47. // GetAdminOpendidByCompany 通过用户公司ID获取对应销售的openid
  48. func GetAdminOpendidByCompany(condition string, pars []interface{}) (list []*AdminOpenIdList, err error) {
  49. sql := `SELECT
  50. cr.open_id,a.mobile,p.company_id,cr.union_id
  51. FROM
  52. company_product AS p
  53. INNER JOIN admin AS a ON a.admin_id = p.seller_id
  54. INNER JOIN user_record as c ON c.bind_account = a.mobile
  55. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  56. WHERE
  57. 1 = 1
  58. AND p.product_id = 2
  59. AND create_platform = 4 ` + condition
  60. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  61. return
  62. }