wx_template_msg.go 3.5 KB

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