123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_ETA_mobile_api/utils"
- "strings"
- )
- type OpenIdList struct {
- OpenId string
- UserId int
- }
- func GetOpenIdList() (items []*OpenIdList, err error) {
- //openIdstr := WxUsersGet()
- //sql:=` SELECT DISTINCT open_id FROM wx_user AS wu
- // INNER JOIN company AS c ON c.company_id = wu.company_id
- // INNER JOIN company_product AS d ON c.company_id=d.company_id
- // WHERE wu.open_id IS NOT NULL AND d.status IN('正式','试用','永续') `
- sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
- INNER JOIN company AS c ON c.company_id = wu.company_id
- INNER JOIN company_product AS d ON c.company_id=d.company_id
- INNER join user_record as ur on wu.user_id=ur.user_id
- WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND d.status IN('正式','试用','永续') `
- //if openIdstr != "" {
- // sql += ` AND ur.open_id in (` + openIdstr + `) `
- //}
- _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
- return
- }
- func GetOpenIdListByMobile(mobile string) (items []*OpenIdList, err error) {
- //openIdstr := WxUsersGet()
- sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
- INNER JOIN company AS c ON c.company_id = wu.company_id
- INNER join user_record as ur on wu.user_id=ur.user_id
- WHERE ur.open_id != "" AND ur.subscribe=1 and ur.create_platform=1 AND wu.mobile=? `
- //if openIdstr != "" {
- // sql += ` AND ur.open_id in (` + openIdstr + `) `
- //}
- _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
- return
- }
- // 获取预约活动的用户的openID
- func GetActivityOpenIdList(activityId int) (items []*OpenIdList, err error) {
- sql := `SELECT DISTINCT cr.open_id,u.user_id
- FROM
- cygx_my_schedule AS m
- INNER JOIN user_record AS u ON u.bind_account = m.mobile
- INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
- WHERE m.activity_id = ? AND u.create_platform = 4 `
- _, err = orm.NewOrm().Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取预约活动的用户的openID测试环境
- func GetActivityOpenIdListByDeBug(activityId int) (items []*OpenIdList, err error) {
- sql := `SELECT
- u.open_id,
- u.user_id
- FROM
- cygx_my_schedule AS s
- INNER JOIN wx_user AS wx ON wx.user_id = s.user_id
- INNER JOIN user_record AS u ON u.bind_account = wx.mobile
- INNER JOIN company_product AS p ON p.company_id = wx.company_id
- WHERE
- s.activity_id = ?
- AND u.create_platform = 1
- AND p.STATUS IN ( '正式', '试用', '永续' )
- GROUP BY
- u.open_id`
- _, err = orm.NewOrm().Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取预约活动的用户的openID
- func GetActivitySpecialOpenIdList() (items []*OpenIdList, err error) {
- sql := `SELECT DISTINCT cr.open_id,u.user_id
- FROM
- cygx_user_follow_special AS m
- INNER JOIN user_record AS u ON u.bind_account = m.mobile
- INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
- WHERE u.create_platform = 4 `
- _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
- return
- }
- // 获取预约活动的用户的openID测试环境
- func GetActivitySpecialOpenIdListByDeBug() (items []*OpenIdList, err error) {
- sql := `SELECT
- u.open_id,
- u.user_id
- FROM
- cygx_user_follow_special AS s
- INNER JOIN wx_user AS wx ON wx.user_id = s.user_id
- INNER JOIN user_record AS u ON u.bind_account = wx.mobile
- INNER JOIN company_product AS p ON p.company_id = wx.company_id
- WHERE
- u.create_platform = 1
- AND p.STATUS IN ( '正式', '试用', '永续' )
- GROUP BY
- u.open_id`
- _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
- return
- }
- // 获取关注作者的用户的openID
- func GetFollowDepartmentOpenIdList(departmentId int) (items []*OpenIdList, err error) {
- sql := `SELECT cr.open_id,u.user_id
- FROM
- cygx_article_department_follow AS f
- INNER JOIN user_record AS u ON u.bind_account = f.mobile
- INNER JOIN wx_user AS wx ON wx.user_id = f.user_id
- INNER JOIN company_product AS p ON p.company_id = wx.company_id
- INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
- WHERE
- f.department_id = ?
- AND u.create_platform = 4
- AND f.type = 1
- AND p.status IN ('正式','试用','永续')
- GROUP BY
- cr.open_id `
- _, err = orm.NewOrm().Raw(sql, departmentId).QueryRows(&items)
- return
- }
- // 获取关注作者的用户的openID测试环境
- func GetFollowDepartmentOpenIdListByDeBug(departmentId int) (items []*OpenIdList, err error) {
- sql := `SELECT
- u.open_id,
- u.user_id
- FROM
- cygx_article_department_follow AS f
- INNER JOIN wx_user AS wx ON wx.user_id = f.user_id
- INNER JOIN user_record AS u ON u.bind_account = wx.mobile
- INNER JOIN company_product AS p ON p.company_id = wx.company_id
- WHERE
- f.department_id = ?
- AND u.create_platform = 1
- AND f.type = 1
- AND p.STATUS IN ( '正式', '试用', '永续' )
- GROUP BY
- u.open_id`
- _, err = orm.NewOrm().Raw(sql, departmentId).QueryRows(&items)
- return
- }
- // 获取关注产业的用户的openID
- func GetFollowindustrialOpenIdList(industrialManagementId int) (items []*OpenIdList, err error) {
- sql := `SELECT cr.open_id,u.user_id
- FROM
- cygx_industry_fllow AS f
- INNER JOIN wx_user AS wx ON wx.user_id = f.user_id
- INNER JOIN user_record AS u ON u.bind_account = wx.mobile
- INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
- WHERE
- f.industrial_management_id = ?
- AND u.create_platform = 4
- AND f.type = 1 GROUP BY cr.open_id `
- _, err = orm.NewOrm().Raw(sql, industrialManagementId).QueryRows(&items)
- return
- }
- // 获取关注产业的用户的openID 测试环境
- func GetFollowindustrialOpenIdListByDeBug(industrialManagementId int) (items []*OpenIdList, err error) {
- sql := `SELECT
- u.open_id,
- u.user_id
- FROM
- cygx_industry_fllow AS f
- INNER JOIN wx_user AS wx ON wx.user_id = f.user_id
- INNER JOIN user_record AS u ON u.bind_account = wx.mobile
- WHERE
- f.industrial_management_id = ?
- AND u.create_platform = 1
- AND u.bind_account != ""
- AND f.type = 1
- GROUP BY
- u.open_id`
- _, err = orm.NewOrm().Raw(sql, industrialManagementId).QueryRows(&items)
- return
- }
- // GetUserOpenidListByUserIds 根据用户id字符串集合来获取他的openid列表集合
- func GetUserOpenidListByUserIds(userIdStr []string) (list []*OpenIdList, err error) {
- if len(userIdStr) <= 0 {
- return
- }
- sql := `SELECT open_id,u.user_id FROM user_record WHERE user_id in (` + strings.Join(userIdStr, ",") + `) and create_platform = 1`
- _, err = orm.NewOrm().Raw(sql).QueryRows(&list)
- return
- }
- func GetAdminOpenIdByMobile(mobile string) (items []*OpenIdList, err error) {
- sql := `SELECT DISTINCT ur.open_id,wu.user_id FROM wx_user AS wu
- INNER JOIN company AS c ON c.company_id = wu.company_id
- INNER join user_record as ur on wu.user_id=ur.user_id
- WHERE ur.open_id != "" and ur.create_platform=1 AND wu.mobile=? `
- _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
- return
- }
- // 根据手机号获取用户的openid查研观向小助手专用
- func GetUserRecordListByMobile(platform int, bindAccount string) (items []*OpenIdList, err error) {
- var sql string
- if utils.RunMode == "release" {
- sql = `SELECT cr.open_id FROM user_record as u
- INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
- WHERE create_platform=? AND bind_account IN (` + bindAccount + `)`
- } else {
- platform = 1
- sql = `SELECT open_id FROM user_record WHERE create_platform =? AND bind_account IN (` + bindAccount + `)`
- }
- _, err = orm.NewOrm().Raw(sql, platform).QueryRows(&items)
- return
- }
- // 获取单个用户openid
- func GetCompanyDetailByIdGroup(platform int, bindAccount string) (item *OpenIdList, err error) {
- o := orm.NewOrm()
- var sql string
- sql = `SELECT cr.open_id,wu.user_id FROM user_record as u
- INNER JOIN cygx_user_record AS cr ON cr.union_id = u.union_id
- INNER JOIN wx_user AS wu ON wu.mobile = u.bind_account
- WHERE create_platform=? AND u.bind_account = ?`
- err = o.Raw(sql, platform, bindAccount).QueryRow(&item)
- return
- }
- // 获取小助手所有的用户的openid
- func GetCygxUserAllOpneid() (items []*OpenIdList, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- cr.open_id,
- r.user_id
- FROM
- user_record AS r
- INNER JOIN cygx_user_record AS cr ON cr.union_id = r.union_id
- WHERE
- r.create_platform = 4`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetOpenIdArr() (items []string, err error) {
- sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
- INNER JOIN company AS c ON c.company_id = wu.company_id
- INNER JOIN company_product AS d ON c.company_id=d.company_id
- INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
- WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
- ORDER BY FIELD(c.company_id, 16) desc, ur.user_record_id asc`
- _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
- return
- }
- // 获取预约活动的用户的openID测试环境
- func GetActivitySpecialOpenIdListMobile(condition string, pars []interface{}) (items []*OpenIdList, err error) {
- sql := `SELECT
- cr.open_id,
- u.user_id
- FROM
- company_report_permission AS p
- INNER JOIN wx_user AS u ON u.company_id = p.company_id
- INNER JOIN user_record AS r ON r.user_id = u.user_id
- INNER JOIN cygx_user_record AS cr ON cr.union_id = r.union_id
- WHERE
- r.create_platform = 4 AND p.STATUS IN ('正式','试用','永续') ` + condition + ` GROUP BY cr.open_id`
- _, err = orm.NewOrm().Raw(sql, pars).QueryRows(&items)
- return
- }
- // 获取所有关注了该产业用户的openid
- func GetCygxUserIndustryFllowOpneid(IndustrialManagementId int) (items []*OpenIdList, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- cr.open_id,
- r.user_id
- FROM
- user_record AS r
- INNER JOIN cygx_user_record AS cr ON cr.union_id = r.union_id
- INNER join cygx_industry_fllow as cf on cf.user_id = r.user_id
- WHERE
- r.create_platform = 4
- AND cf.industrial_management_id = ?`
- _, err = o.Raw(sql, IndustrialManagementId).QueryRows(&items)
- return
- }
- // 获取所有关注了该产业用户的openid
- func GetCygxUserIndustryFllowOpneidByActivityIds(activityId int) (items []*OpenIdList, err error) {
- o := orm.NewOrm()
- sql := `
- SELECT
- cr.open_id,
- r.user_id
- FROM
- cygx_industrial_activity_group_management AS agm
- INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
- INNER JOIN user_record AS r
- INNER JOIN cygx_user_record AS cr
- WHERE
- agm.activity_id = ?
- AND cr.union_id = r.union_id
- AND r.create_platform = 4
- AND r.user_id = f.user_id;`
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取所有关注了该产业永续客户的openid
- func GetCygxForeverUserIndustryFllowOpneidByActivityIds(activityId int) (items []*OpenIdList, err error) {
- o := orm.NewOrm()
- sql := `
- SELECT
- cr.open_id,
- r.user_id
- FROM
- cygx_industrial_activity_group_management AS agm
- INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
- INNER JOIN user_record AS r
- INNER JOIN cygx_user_record AS cr
- INNER JOIN wx_user AS wx ON wx.user_id = r.user_id
- INNER JOIN company_product AS p ON p.company_id = wx.company_id
- WHERE
- agm.activity_id = ?
- AND cr.union_id = r.union_id
- AND r.create_platform = 4
- AND r.user_id = f.user_id
- AND p.status = "永续";`
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取所有关注了该产业试用客户的openid
- func GetCygxTryOutUserIndustryFllowOpneidByActivityIds(activityId int) (items []*OpenIdList, err error) {
- o := orm.NewOrm()
- sql := `
- SELECT
- cr.open_id,
- r.user_id
- FROM
- cygx_industrial_activity_group_management AS agm
- INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
- INNER JOIN user_record AS r
- INNER JOIN cygx_user_record AS cr
- INNER JOIN wx_user AS wx ON wx.user_id = r.user_id
- INNER JOIN company_product AS p ON p.company_id = wx.company_id
- WHERE
- agm.activity_id = ?
- AND cr.union_id = r.union_id
- AND r.create_platform = 4
- AND r.user_id = f.user_id
- AND p.status = "试用";`
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取所有关注了该产业用户的companyIds
- func GetCygxIndustryFollowCompanyIdsByActivityId(activityId int) (item *string, err error) {
- o := orm.NewOrm()
- sql := `
- SELECT
- GROUP_CONCAT( DISTINCT f.company_id SEPARATOR ',' ) AS company_ids
- FROM
- cygx_industrial_activity_group_management AS agm
- INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
- INNER JOIN user_record AS r
- INNER JOIN cygx_user_record AS cr
- WHERE
- agm.activity_id = ?
- AND r.create_platform = 4
- AND r.user_id = f.user_id;`
- err = o.Raw(sql, activityId).QueryRow(&item)
- return
- }
- // 获取所有关注了该产业用户的openidBy公司id
- func GetCygxUserIndustryFllowOpneidByActivityIdAndCompanyIds(activityId int, companyIds string) (items []*OpenIdList, err error) {
- o := orm.NewOrm()
- sql := `
- SELECT
- cr.open_id,
- r.user_id
- FROM
- cygx_industrial_activity_group_management AS agm
- INNER JOIN cygx_industry_fllow AS f ON f.industrial_management_id = agm.industrial_management_id
- INNER JOIN user_record AS r
- INNER JOIN cygx_user_record AS cr
- WHERE
- agm.activity_id = ?
- AND cr.union_id = r.union_id
- AND r.create_platform = 4
- AND r.user_id = f.user_id
- AND f.company_id IN (` + companyIds + `);`
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取所有互动过的用户id
- func GetCygxInteractiveUserByActivityId(activityId int) (items []*int, err error) {
- o := orm.NewOrm()
- sql := `
- SELECT user_id FROM cygx_activity_signup WHERE activity_id =? AND fail_type = 0
- UNION ALL
- SELECT user_id FROM cygx_activity_appointment WHERE activity_id = ?
- UNION ALL
- SELECT user_id FROM cygx_activity_meeting_reminder WHERE activity_id = ?
- UNION ALL
- SELECT user_id FROM cygx_activity_help_ask WHERE activity_id = ? `
- _, err = o.Raw(sql, activityId, activityId, activityId, activityId).QueryRows(&items)
- return
- }
- // 获取所有用户的openid
- func GetCygxUserOpneidByUserIds(userIds string) (items []*OpenIdList, err error) {
- o := orm.NewOrm()
- sql := `
- SELECT
- cr.open_id,
- r.user_id
- FROM
- user_record AS r
- INNER JOIN cygx_user_record AS cr
- WHERE
- cr.union_id = r.union_id
- AND r.create_platform = 4
- AND r.user_id IN (` + userIds + `);`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetOpenIdArrByClassifyNameSecond(classifyNameSecond string) (items []string, err error) {
- sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
- INNER JOIN company AS c ON c.company_id = wu.company_id
- INNER JOIN company_product AS d ON c.company_id=d.company_id
- INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
- INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
- INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
- INNER JOIN chart_permission_search_key_word_mapping AS g ON f.chart_permission_id=g.chart_permission_id
- WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
- AND g.from='rddp'
- AND g.key_word=?
- ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
- _, err = orm.NewOrm().Raw(sql, classifyNameSecond).QueryRows(&items)
- return
- }
- func GetOpenIdArrByChartPermissionIds(chartPermissionIds string) (items []string, err error) {
- sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
- INNER JOIN company AS c ON c.company_id = wu.company_id
- INNER JOIN company_product AS d ON c.company_id=d.company_id
- INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
- INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
- INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
- WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
- AND f.chart_permission_id IN(` + chartPermissionIds + `)
- ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
- _, err = orm.NewOrm().Raw(sql).QueryRows(&items)
- return
- }
- func GetOpenIdArrByVarietyTag(varietyTagId int) (items []string, err error) {
- sql := ` SELECT DISTINCT ur.open_id FROM wx_user AS wu
- INNER JOIN company AS c ON c.company_id = wu.company_id
- INNER JOIN company_product AS d ON c.company_id=d.company_id
- INNER JOIN user_record AS ur ON wu.user_id=ur.user_id
- INNER JOIN company_report_permission AS e ON d.company_id=e.company_id
- INNER JOIN chart_permission AS f ON e.chart_permission_id=f.chart_permission_id
- INNER JOIN variety_tag AS g ON f.chart_permission_id=g.chart_permission_id
- WHERE ur.open_id != "" AND ur.subscribe=1 AND ur.create_platform=1 AND d.status IN('正式','试用','永续')
- AND g.variety_tag_id=?
- ORDER BY FIELD(c.company_id, 16) DESC, ur.user_record_id ASC `
- _, err = orm.NewOrm().Raw(sql, varietyTagId).QueryRows(&items)
- return
- }
|