wx_template_msg.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. }
  15. func GetOpenIdList() (items []*OpenIdList, err error) {
  16. openIdstr := WxUsersGet()
  17. sql := `SELECT open_id FROM wx_user AS wu
  18. INNER JOIN company AS c ON c.company_id = wu.company_id
  19. WHERE wu.open_id IS NOT NULL AND c.type IN (1,2) `
  20. if openIdstr != "" {
  21. sql += ` AND open_id in (` + openIdstr + `) `
  22. }
  23. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  24. return
  25. }
  26. func GetWxOpenIdByMobileList(mobile string) (items []*OpenIdList, err error) {
  27. //sql := `SELECT * FROM user_record WHERE bind_account IN (` + utils.WxMsgTemplateIdAskMsgMobile + `) AND create_platform = 1`
  28. sql := `SELECT cr.*,user_id FROM user_record as c
  29. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  30. WHERE bind_account IN (` + mobile + `) AND create_platform = 4`
  31. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  32. return
  33. }
  34. type AdminOpenIdList struct {
  35. OpenId string `description:"OpenId"`
  36. UserId int `description:"UserId"`
  37. Mobile string `description:"手机号"`
  38. CompanyId int `description:"手机号"`
  39. }
  40. // GetAdminOpendidByCompany 通过用户公司ID获取对应销售的openid
  41. func GetAdminOpendidByCompany(condition string, pars []interface{}) (list []*AdminOpenIdList, err error) {
  42. sql := `SELECT
  43. cr.open_id,a.mobile,p.company_id,cr.union_id
  44. FROM
  45. company_product AS p
  46. INNER JOIN admin AS a ON a.admin_id = p.seller_id
  47. INNER JOIN user_record as c ON c.bind_account = a.mobile
  48. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  49. WHERE
  50. 1 = 1
  51. AND p.product_id = 2
  52. AND create_platform = 4 ` + condition
  53. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&list)
  54. return
  55. }
  56. func GetWxOpenIdByMobileSliceList(mobiles []string) (items []*OpenIdList, err error) {
  57. itemsLen := len(mobiles)
  58. if itemsLen == 0 {
  59. return
  60. }
  61. o := orm.NewOrm()
  62. sql := `SELECT cr.*,user_id FROM user_record as c
  63. INNER JOIN cygx_user_record AS cr ON cr.union_id = c.union_id
  64. WHERE bind_account IN (` + utils.GetOrmInReplace(itemsLen) + `) AND create_platform = 4`
  65. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  66. return
  67. }