wx_template_msg.go 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 DeleteTemplateRecordByDate(date string) (err error) {
  12. sql := `DELETE FROM user_template_record WHERE create_time<? `
  13. o := orm.NewOrm()
  14. _, err = o.Raw(sql, date).Exec()
  15. return
  16. }
  17. // GetOpenIdListV2 2022-08-18从hongze_admin复制过来的最新的代码
  18. func GetOpenIdListV2() (items []*OpenIdList, err error) {
  19. sql := `SELECT DISTINCT
  20. ur.open_id,
  21. wu.user_id
  22. FROM
  23. wx_user AS wu
  24. INNER JOIN company AS c ON c.company_id = wu.company_id
  25. INNER JOIN company_product AS d ON c.company_id = d.company_id
  26. INNER JOIN user_record AS ur ON wu.user_id = ur.user_id
  27. WHERE
  28. ur.open_id != "" AND ur.subscribe = 1 AND ur.create_platform = 1 AND d. STATUS IN ('正式', '试用', '永续') `
  29. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  30. return
  31. }
  32. func GetOpenIdArr() (items []string, err error) {
  33. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  34. INNER JOIN company AS c ON c.company_id = wu.company_id
  35. INNER JOIN company_product AS d ON c.company_id=d.company_id
  36. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  37. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
  38. ORDER BY FIELD(c.company_id, 16) desc, ur.user_record_id asc`
  39. o := orm.NewOrm()
  40. _, err = o.Raw(sql).QueryRows(&items)
  41. return
  42. }
  43. func GetOpenIdArrByClassifyNameSecond(classifyNameSecond string) (items []string, err error) {
  44. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  45. INNER JOIN company AS c ON c.company_id = wu.company_id
  46. INNER JOIN company_product AS d ON c.company_id=d.company_id
  47. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  48. INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
  49. INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
  50. INNER JOIN chart_permission_search_key_word_mapping AS g ON f.chart_permission_id=g.chart_permission_id
  51. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续') AND e.status IN('正式','试用','永续')
  52. AND g.from='rddp'
  53. AND g.key_word=?
  54. ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
  55. o := orm.NewOrm()
  56. _, err = o.Raw(sql, classifyNameSecond).QueryRows(&items)
  57. return
  58. }
  59. // GetOpenIdArrByClassifyId
  60. // @Description: 根据分类id获取关联的用户微信openid
  61. // @author: Roc
  62. // @datetime 2024-06-28 14:57:27
  63. // @param classifyId int
  64. // @return items []string
  65. // @return err error
  66. func GetOpenIdArrByClassifyId(classifyId int) (items []string, err error) {
  67. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  68. INNER JOIN company AS c ON c.company_id = wu.company_id
  69. INNER JOIN company_product AS d ON c.company_id=d.company_id
  70. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  71. INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
  72. INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
  73. INNER JOIN chart_permission_search_key_word_mapping AS g ON f.chart_permission_id=g.chart_permission_id
  74. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续') AND e.status IN('正式','试用','永续')
  75. AND g.from='rddp'
  76. AND g.classify_id=?
  77. ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
  78. o := orm.NewOrmUsingDB("weekly")
  79. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  80. return
  81. }