wechat_send_msg.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. package models
  2. import (
  3. "eta/eta_pub/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. )
  7. type OpenIdList struct {
  8. OpenId string
  9. UserId int
  10. }
  11. func GetOpenIdList() (items []*OpenIdList, err error) {
  12. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  13. INNER JOIN company AS c ON c.company_id = wu.company_id
  14. INNER JOIN company_product AS d ON c.company_id=d.company_id
  15. INNER join user_record as ur on wu.user_id=ur.user_id
  16. WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND d.status IN('正式','试用','永续') `
  17. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  18. return
  19. }
  20. func GetOpenIdListByMobile(mobile string) (items []*OpenIdList, err error) {
  21. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  22. INNER JOIN company AS c ON c.company_id = wu.company_id
  23. INNER join user_record as ur on wu.user_id=ur.user_id
  24. WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND wu.mobile=? `
  25. _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
  26. return
  27. }
  28. // 获取预约活动的用户的openID
  29. func GetActivityOpenIdList(activityId int) (items []*OpenIdList, err error) {
  30. sql := `SELECT DISTINCT cr.open_id,u.user_id
  31. FROM
  32. cygx_my_schedule AS m
  33. INNER JOIN user_record AS u ON u.bind_account = m.mobile
  34. INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
  35. WHERE m.activity_id = ? AND u.create_platform = 4 `
  36. _, err = orm.NewOrm().Raw(sql, activityId).QueryRows(&items)
  37. return
  38. }
  39. // 获取预约活动的用户的openID测试环境
  40. func GetActivityOpenIdListByDeBug(activityId int) (items []*OpenIdList, err error) {
  41. sql := `SELECT
  42. u.open_id,
  43. u.user_id
  44. FROM
  45. cygx_my_schedule AS s
  46. INNER JOIN wx_user AS wx ON wx.user_id = s.user_id
  47. INNER JOIN user_record AS u ON u.bind_account = wx.mobile
  48. INNER JOIN company_product AS p ON p.company_id = wx.company_id
  49. WHERE
  50. s.activity_id = ?
  51. AND u.create_platform = 1
  52. AND p.STATUS IN ( '正式', '试用', '永续' )
  53. GROUP BY
  54. u.open_id`
  55. _, err = orm.NewOrm().Raw(sql, activityId).QueryRows(&items)
  56. return
  57. }
  58. // 获取预约活动的用户的openID
  59. func GetActivitySpecialOpenIdList() (items []*OpenIdList, err error) {
  60. sql := `SELECT DISTINCT cr.open_id,u.user_id
  61. FROM
  62. cygx_user_follow_special AS m
  63. INNER JOIN user_record AS u ON u.bind_account = m.mobile
  64. INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
  65. WHERE u.create_platform = 4 `
  66. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  67. return
  68. }
  69. // 获取预约活动的用户的openID测试环境
  70. func GetActivitySpecialOpenIdListByDeBug() (items []*OpenIdList, err error) {
  71. sql := `SELECT
  72. u.open_id,
  73. u.user_id
  74. FROM
  75. cygx_user_follow_special AS s
  76. INNER JOIN wx_user AS wx ON wx.user_id = s.user_id
  77. INNER JOIN user_record AS u ON u.bind_account = wx.mobile
  78. INNER JOIN company_product AS p ON p.company_id = wx.company_id
  79. WHERE
  80. u.create_platform = 1
  81. AND p.STATUS IN ( '正式', '试用', '永续' )
  82. GROUP BY
  83. u.open_id`
  84. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  85. return
  86. }
  87. // 获取关注作者的用户的openID
  88. func GetFollowDepartmentOpenIdList(departmentId int) (items []*OpenIdList, err error) {
  89. sql := `SELECT cr.open_id,u.user_id
  90. FROM
  91. cygx_article_department_follow AS f
  92. INNER JOIN user_record AS u ON u.bind_account = f.mobile
  93. INNER JOIN wx_user AS wx ON wx.user_id = f.user_id
  94. INNER JOIN company_product AS p ON p.company_id = wx.company_id
  95. INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
  96. WHERE
  97. f.department_id = ?
  98. AND u.create_platform = 4
  99. AND f.type = 1
  100. AND p.status IN ('正式','试用','永续')
  101. GROUP BY
  102. cr.open_id `
  103. _, err = orm.NewOrm().Raw(sql, departmentId).QueryRows(&items)
  104. return
  105. }
  106. // 获取关注作者的用户的openID测试环境
  107. func GetFollowDepartmentOpenIdListByDeBug(departmentId int) (items []*OpenIdList, err error) {
  108. sql := `SELECT
  109. u.open_id,
  110. u.user_id
  111. FROM
  112. cygx_article_department_follow AS f
  113. INNER JOIN wx_user AS wx ON wx.user_id = f.user_id
  114. INNER JOIN user_record AS u ON u.bind_account = wx.mobile
  115. INNER JOIN company_product AS p ON p.company_id = wx.company_id
  116. WHERE
  117. f.department_id = ?
  118. AND u.create_platform = 1
  119. AND f.type = 1
  120. AND p.STATUS IN ( '正式', '试用', '永续' )
  121. GROUP BY
  122. u.open_id`
  123. _, err = orm.NewOrm().Raw(sql, departmentId).QueryRows(&items)
  124. return
  125. }
  126. // 获取关注产业的用户的openID
  127. func GetFollowindustrialOpenIdList(industrialManagementId int) (items []*OpenIdList, err error) {
  128. sql := `SELECT cr.open_id,u.user_id
  129. FROM
  130. cygx_industry_fllow AS f
  131. INNER JOIN wx_user AS wx ON wx.user_id = f.user_id
  132. INNER JOIN user_record AS u ON u.bind_account = wx.mobile
  133. INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
  134. WHERE
  135. f.industrial_management_id = ?
  136. AND u.create_platform = 4
  137. AND f.type = 1 GROUP BY cr.open_id `
  138. _, err = orm.NewOrm().Raw(sql, industrialManagementId).QueryRows(&items)
  139. return
  140. }
  141. // 获取关注产业的用户的openID 测试环境
  142. func GetFollowindustrialOpenIdListByDeBug(industrialManagementId int) (items []*OpenIdList, err error) {
  143. sql := `SELECT
  144. u.open_id,
  145. u.user_id
  146. FROM
  147. cygx_industry_fllow AS f
  148. INNER JOIN wx_user AS wx ON wx.user_id = f.user_id
  149. INNER JOIN user_record AS u ON u.bind_account = wx.mobile
  150. WHERE
  151. f.industrial_management_id = ?
  152. AND u.create_platform = 1
  153. AND u.bind_account != ""
  154. AND f.type = 1
  155. GROUP BY
  156. u.open_id`
  157. _, err = orm.NewOrm().Raw(sql, industrialManagementId).QueryRows(&items)
  158. return
  159. }
  160. // GetUserOpenidListByUserIds 根据用户id字符串集合来获取他的openid列表集合
  161. func GetUserOpenidListByUserIds(userIdStr []string) (list []*OpenIdList, err error) {
  162. if len(userIdStr) <= 0 {
  163. return
  164. }
  165. sql := `SELECT open_id,u.user_id FROM user_record WHERE user_id in (` + strings.Join(userIdStr, ",") + `) and create_platform = 1`
  166. _, err = orm.NewOrm().Raw(sql).QueryRows(&list)
  167. return
  168. }
  169. func GetAdminOpenIdByMobile(mobile string) (items []*OpenIdList, err error) {
  170. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  171. INNER JOIN company AS c ON c.company_id = wu.company_id
  172. INNER join user_record as ur on wu.user_id=ur.user_id
  173. WHERE ur.open_id != "" and ur.create_platform=1 AND wu.mobile=? `
  174. _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
  175. return
  176. }
  177. // 根据手机号获取用户的openid查研观向小助手专用
  178. func GetUserRecordListByMobile(platform int, bindAccount string) (items []*OpenIdList, err error) {
  179. var sql string
  180. if utils.RunMode == "release" {
  181. sql = `SELECT cr.open_id FROM user_record as u
  182. INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
  183. WHERE create_platform=? AND bind_account IN (` + bindAccount + `)`
  184. } else {
  185. platform = 1
  186. sql = `SELECT open_id FROM user_record WHERE create_platform =? AND bind_account IN (` + bindAccount + `)`
  187. }
  188. _, err = orm.NewOrm().Raw(sql, platform).QueryRows(&items)
  189. return
  190. }
  191. type SendWxTemplate struct {
  192. WxAppId string `description:"公众号appId"`
  193. First string `description:"模板消息first字段"`
  194. Keyword1 string `description:"模板消息keyword1字段"`
  195. Keyword2 string `description:"模板消息keyword2字段"`
  196. Keyword3 string `description:"模板消息keyword3字段"`
  197. Keyword4 string `description:"模板消息keyword4字段"`
  198. Keyword5 string `description:"模板消息keyword5字段"`
  199. Productname string `description:"模板消息productname字段"`
  200. Date string `description:"模板消息date字段"`
  201. Remark string `description:"模板消息remark字段"`
  202. TemplateId string `description:"模板id"`
  203. RedirectUrl string `description:"跳转地址"`
  204. RedirectTarget int `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序,3:查研观向"`
  205. Resource string `description:"资源唯一标识"`
  206. SendType int `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
  207. OpenIdArr []string `description:"消息接收者openid"`
  208. }
  209. type WxTokenReq struct {
  210. WxAppId string `description:"公众号appId"`
  211. WxAppSecret string `description:"公众号appSecret"`
  212. }
  213. type WxTokenResp struct {
  214. AccessToken string `description:"微信token"`
  215. }
  216. // 跳小程序所需数据
  217. type MiniprogramReq struct {
  218. Appid string `json:"appid" ;description:"所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系,暂不支持小游戏`
  219. Pagepath string `json:"pagepath" ;description:"所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar),要求该小程序已发布,暂不支持小游戏`
  220. }
  221. type SendWxCategoryTemplate struct {
  222. WxAppId string `description:"公众号appId"`
  223. Keywords []string `description:"模板消息keyword字段"`
  224. TemplateId string `description:"模板id"`
  225. Miniprogram *MiniprogramReq `description:"跳小程序所需数据,不需跳小程序可不用传该数据"`
  226. RedirectUrl string `description:"跳转地址"`
  227. RedirectTarget int `description:"小程序跳转目标:1:弘则研报小程序,2:随手办公小程序,3:查研观向"`
  228. Resource string `description:"资源唯一标识"`
  229. SendType int `description:"发送的消息类型:1:报告,2:指标更新提醒,3:审批通知,4:销售领取客户通知,5:活动取消通知,6活动更改时间通知,7:关注的作者发布报告通知,8:发送日报(周报、双周报、月报)模板消息,9:活动预约/报名时间通知"`
  230. OpenIdArr []string `description:"消息接收者openid"`
  231. }