wechat_send_msg.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "strings"
  5. )
  6. type OpenIdList struct {
  7. OpenId string
  8. UserId int
  9. }
  10. func GetOpenIdList() (items []*OpenIdList, err error) {
  11. //openIdstr := WxUsersGet()
  12. //sql:=` SELECT DISTINCT open_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. // WHERE wu.open_id IS NOT NULL AND d.status IN('正式','试用','永续') `
  16. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  17. INNER JOIN company AS c ON c.company_id = wu.company_id
  18. INNER JOIN company_product AS d ON c.company_id=d.company_id
  19. INNER join user_record as ur on wu.user_id=ur.user_id
  20. WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND d.status IN('正式','试用','永续') `
  21. //if openIdstr != "" {
  22. // sql += ` AND ur.open_id in (` + openIdstr + `) `
  23. //}
  24. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  25. return
  26. }
  27. func GetOpenIdListByMobile(mobile string) (items []*OpenIdList, err error) {
  28. //openIdstr := WxUsersGet()
  29. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  30. INNER JOIN company AS c ON c.company_id = wu.company_id
  31. INNER join user_record as ur on wu.user_id=ur.user_id
  32. WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND wu.mobile=? `
  33. //if openIdstr != "" {
  34. // sql += ` AND ur.open_id in (` + openIdstr + `) `
  35. //}
  36. _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
  37. return
  38. }
  39. // GetUserOpenidListByUserIds 根据用户id字符串集合来获取他的openid列表集合
  40. func GetUserOpenidListByUserIds(userIdStr []string) (list []*OpenIdList, err error) {
  41. if len(userIdStr) <= 0 {
  42. return
  43. }
  44. sql := `SELECT open_id,u.user_id FROM user_record WHERE user_id in (` + strings.Join(userIdStr, ",") + `) and create_platform = 1`
  45. _, err = orm.NewOrm().Raw(sql).QueryRows(&list)
  46. return
  47. }
  48. func GetAdminOpenIdByMobile(mobile string) (items []*OpenIdList, err error) {
  49. sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
  50. INNER JOIN company AS c ON c.company_id = wu.company_id
  51. INNER join user_record as ur on wu.user_id=ur.user_id
  52. WHERE ur.open_id != "" and ur.create_platform=1 AND wu.mobile=? `
  53. _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
  54. return
  55. }
  56. // 获取小助手所有的用户的openid
  57. func GetCygxUserAllOpneid() (items []*OpenIdList, err error) {
  58. o := orm.NewOrmUsingDB("hz_cygx")
  59. sql := `SELECT
  60. cr.open_id,
  61. cr.cygx_user_id as user_id
  62. FROM cygx_user_record AS cr `
  63. _, err = o.Raw(sql).QueryRows(&items)
  64. return
  65. }
  66. func GetOpenIdArr() (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. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
  72. ORDER BY FIELD(c.company_id, 16) desc, ur.user_record_id asc`
  73. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  74. return
  75. }
  76. type MobileUserIdList struct {
  77. Mobile string
  78. UserId int
  79. }
  80. // 获取预约活动的用户的openID测试环境
  81. func GetActivitySpecialOpenIdListMobile(condition string, pars []interface{}) (items []*MobileUserIdList, err error) {
  82. sql := `SELECT
  83. u.mobile,
  84. u.user_id
  85. FROM
  86. company_report_permission AS p
  87. INNER JOIN wx_user AS u ON u.company_id = p.company_id
  88. INNER JOIN user_record AS r ON r.user_id = u.user_id
  89. WHERE
  90. r.create_platform = 4 AND p.STATUS IN ('正式','试用','永续') ` + condition + ` GROUP BY u.mobile`
  91. _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items)
  92. return
  93. }
  94. // 获取所有关注了该产业用户的openid
  95. func GetCygxUserIndustryFllowOpneid(IndustrialManagementId int) (items []*OpenIdList, err error) {
  96. o := orm.NewOrmUsingDB("hz_cygx")
  97. sql := `SELECT
  98. cr.open_id,
  99. cr.cygx_user_id as user_id
  100. FROM
  101. cygx_industry_fllow AS cf
  102. INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = cf.user_id
  103. WHERE
  104. 1=1
  105. AND cf.industrial_management_id = ?`
  106. _, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items)
  107. return
  108. }
  109. // 获取所有关注了该产业试用客户的openid
  110. func GetCygxTryOutUserIndustryFllowOpneidByActivityIds(activityId int) (items []*OpenIdList, err error) {
  111. o := orm.NewOrm()
  112. sql := `
  113. SELECT
  114. cr.open_id,
  115. r.user_id
  116. FROM
  117. cygx_industrial_activity_group_management AS agm
  118. INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
  119. INNER JOIN user_record AS r
  120. INNER JOIN cygx_user_record AS cr
  121. INNER JOIN wx_user AS wx ON wx.user_id = r.user_id
  122. INNER JOIN company_product AS p ON p.company_id = wx.company_id
  123. WHERE
  124. agm.activity_id = ?
  125. AND cr.union_id = r.union_id
  126. AND r.create_platform = 4
  127. AND r.user_id = f.user_id
  128. AND p.status = "试用";`
  129. _, err = o.Raw(sql, activityId).QueryRows(&items)
  130. return
  131. }
  132. // 获取所有关注了该产业用户的openidBy公司id
  133. func GetCygxUserIndustryFllowOpneidByActivityIdAndCompanyIds(activityId int, companyIds string) (items []*OpenIdList, err error) {
  134. o := orm.NewOrm()
  135. sql := `
  136. SELECT
  137. cr.open_id,
  138. r.user_id
  139. FROM
  140. cygx_industrial_activity_group_management AS agm
  141. INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
  142. INNER JOIN user_record AS r
  143. INNER JOIN cygx_user_record AS cr
  144. WHERE
  145. agm.activity_id = ?
  146. AND cr.union_id = r.union_id
  147. AND r.create_platform = 4
  148. AND r.user_id = f.user_id
  149. AND f.company_id IN (` + companyIds + `);`
  150. _, err = o.Raw(sql, activityId).QueryRows(&items)
  151. return
  152. }
  153. // 获取所有互动过的用户id
  154. func GetCygxInteractiveUserByActivityId(activityId int) (items []*int, err error) {
  155. o := orm.NewOrmUsingDB("hz_cygx")
  156. sql := `
  157. SELECT user_id FROM cygx_activity_signup WHERE activity_id =? AND fail_type = 0
  158. UNION ALL
  159. SELECT user_id FROM cygx_activity_appointment WHERE activity_id = ?
  160. UNION ALL
  161. SELECT user_id FROM cygx_activity_meeting_reminder WHERE activity_id = ?
  162. UNION ALL
  163. SELECT user_id FROM cygx_activity_help_ask WHERE activity_id = ? `
  164. _, err = o.Raw(sql, activityId, activityId, activityId, activityId).QueryRows(&items)
  165. return
  166. }
  167. // 获取所有用户的openid
  168. func GetCygxUserOpneidByUserIds(userIds string) (items []*OpenIdList, err error) {
  169. o := orm.NewOrm()
  170. sql := `
  171. SELECT
  172. cr.open_id,
  173. r.user_id
  174. FROM
  175. user_record AS r
  176. INNER JOIN cygx_user_record AS cr
  177. WHERE
  178. cr.union_id = r.union_id
  179. AND r.create_platform = 4
  180. AND r.user_id IN (` + userIds + `);`
  181. _, err = o.Raw(sql).QueryRows(&items)
  182. return
  183. }
  184. func GetOpenIdArrByClassifyNameSecond(classifyNameSecond string) (items []string, err error) {
  185. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  186. INNER JOIN company AS c ON c.company_id = wu.company_id
  187. INNER JOIN company_product AS d ON c.company_id=d.company_id
  188. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  189. INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
  190. INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
  191. INNER JOIN chart_permission_search_key_word_mapping AS g ON f.chart_permission_id=g.chart_permission_id
  192. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续') AND e.status IN('正式','试用','永续')
  193. AND g.from='rddp'
  194. AND g.key_word=?
  195. ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
  196. _, err = orm.NewOrm().Raw(sql, classifyNameSecond).QueryRows(&items)
  197. return
  198. }
  199. func GetOpenIdArrByChartPermissionIds(chartPermissionIds string) (items []string, err error) {
  200. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  201. INNER JOIN company AS c ON c.company_id = wu.company_id
  202. INNER JOIN company_product AS d ON c.company_id=d.company_id
  203. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  204. INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
  205. INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
  206. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
  207. AND f.chart_permission_id IN(` + chartPermissionIds + `)
  208. ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
  209. _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
  210. return
  211. }
  212. func GetOpenIdArrByVarietyTag(varietyTagId int) (items []string, err error) {
  213. sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
  214. INNER JOIN company AS c ON c.company_id = wu.company_id
  215. INNER JOIN company_product AS d ON c.company_id=d.company_id
  216. INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
  217. INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
  218. INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
  219. INNER JOIN variety_tag AS g ON f.chart_permission_id=g.chart_permission_id
  220. WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
  221. AND g.variety_tag_id=?
  222. ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
  223. _, err = orm.NewOrm().Raw(sql, varietyTagId).QueryRows(&items)
  224. return
  225. }