wx_template_msg.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package models
  2. import "github.com/beego/beego/v2/client/orm"
  3. type SendTemplateResponse struct {
  4. Errcode int `json:"errcode"`
  5. Errmsg string `json:"errmsg"`
  6. MsgID int `json:"msgid"`
  7. }
  8. type OpenIdList struct {
  9. OpenId string
  10. }
  11. func GetOpenIdList() (items []*OpenIdList, err error) {
  12. openIdstr := WxUsersGet()
  13. sql := `SELECT open_id FROM wx_user AS wu
  14. INNER JOIN company AS c ON c.company_id = wu.company_id
  15. WHERE wu.open_id IS NOT NULL AND c.type IN (1,2) `
  16. if openIdstr != "" {
  17. sql += ` AND open_id in (` + openIdstr + `) `
  18. }
  19. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  20. return
  21. }
  22. func GetWxOpenIdList() (items []*OpenIdList, err error) {
  23. sql := `SELECT open_id FROM wx_user AS wu
  24. INNER JOIN company AS c ON c.company_id = wu.company_id
  25. WHERE open_id=? `
  26. openId := "oW3Gts7V3hj-sTAE1VDi0MhGlee8"
  27. _, err = orm.NewOrm().Raw(sql, openId).QueryRows(&items)
  28. return
  29. }
  30. func DeleteTemplateRecordByDate(date string) (err error) {
  31. sql := `DELETE FROM user_template_record WHERE create_time<? `
  32. o := orm.NewOrm()
  33. _, err = o.Raw(sql, date).Exec()
  34. return
  35. }
  36. // GetOpenIdListV2 2022-08-18从hongze_admin复制过来的最新的代码
  37. func GetOpenIdListV2() (items []*OpenIdList, err error) {
  38. sql := `SELECT DISTINCT
  39. ur.open_id,
  40. wu.user_id
  41. FROM
  42. wx_user AS wu
  43. INNER JOIN company AS c ON c.company_id = wu.company_id
  44. INNER JOIN company_product AS d ON c.company_id = d.company_id
  45. INNER JOIN user_record AS ur ON wu.user_id = ur.user_id
  46. WHERE
  47. ur.open_id != "" AND ur.subscribe = 1 AND ur.create_platform = 1 AND d. STATUS IN ('正式', '试用', '永续') `
  48. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  49. return
  50. }
  51. func GetOpenIdArr() (items []string, err error) {
  52. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  53. INNER JOIN company AS c ON c.company_id = wu.company_id
  54. INNER JOIN company_product AS d ON c.company_id=d.company_id
  55. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  56. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
  57. ORDER BY FIELD(c.company_id, 16) desc, ur.user_record_id asc`
  58. o := orm.NewOrm()
  59. _, err = o.Raw(sql).QueryRows(&items)
  60. return
  61. }
  62. func GetOpenIdArrByClassifyNameSecond(classifyNameSecond string) (items []string, err error) {
  63. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  64. INNER JOIN company AS c ON c.company_id = wu.company_id
  65. INNER JOIN company_product AS d ON c.company_id=d.company_id
  66. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  67. INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
  68. INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
  69. INNER JOIN chart_permission_search_key_word_mapping AS g ON f.chart_permission_id=g.chart_permission_id
  70. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续') AND e.status IN('正式','试用','永续')
  71. AND g.from='rddp'
  72. AND g.key_word=?
  73. ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
  74. o := orm.NewOrm()
  75. _, err = o.Raw(sql, classifyNameSecond).QueryRows(&items)
  76. return
  77. }