123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- package cygx
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hz_crm_api/utils"
- "time"
- )
- type CygxUserRecord struct {
- UserRecordId int `orm:"column(user_record_id);pk"`
- OpenId string `description:"用户openid,最大长度:32"`
- UnionId string `description:"用户unionid,最大长度:64"`
- NickName string `descritpion:"用户昵称,最大长度:32"`
- Sex int `descritpion:"普通用户性别,1为男性,2为女性"`
- Province string `description:"普通用户个人资料填写的省份,最大长度:30"`
- City string `description:"普通用户个人资料填写的城市,最大长度:30"`
- Country string `description:"国家,如中国为CN,最大长度:30"`
- Headimgurl string `description:"用户第三方(微信)头像,最大长度:512"`
- CreateTime time.Time `description:"创建时间,关系添加时间、用户授权时间"`
- }
- type OpenIdList struct {
- OpenId string
- UserId int
- CompanyId int `description:"公司ID"`
- Mobile string `description:"手机号"`
- }
- type OpenIdMobileList struct {
- OpenId string
- UserId int
- Mobile string `description:"手机号"`
- }
- func GetCygxUserRecord() (items []*CygxUserRecord, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT union_id,open_id FROM cygx_user_record `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取所有有权限的用户的opid
- func GetCygxUserRecordPower(chartPermissionIds string) (items []*OpenIdList, err error) {
- //o := orm.NewOrm()
- //sql := `SELECT
- // cr.open_id,
- // u.user_id,
- // u.company_id,
- // u.real_name,
- // u.mobile
- // 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
- // p.chart_permission_id IN (` + chartPermissionIds + `)
- // AND r.create_platform = 4
- // AND p.STATUS IN ('正式','试用','永续') GROUP BY cr.open_id `
- //_, err = o.Raw(sql).QueryRows(&items)
- listMobile, err := GetCygxUserRecordPowerMobileList(chartPermissionIds)
- if err != nil {
- return
- }
- var mobileArr []string
- for _, v := range listMobile {
- if v.Mobile != "" {
- mobileArr = append(mobileArr, v.Mobile)
- }
- }
- mobileLen := len(mobileArr)
- if mobileLen == 0 {
- return
- }
- openIdList, err := GetUserRecordListByMobileArr(mobileArr)
- if err != nil {
- return
- }
- items = openIdList
- return
- }
- // 获取所有有权限的用户的opid
- func GetCygxUserRecordPowerMobileList(chartPermissionIds string) (items []*OpenIdMobileList, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- u.user_id,
- u.company_id,
- u.real_name,
- u.mobile
- 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
- WHERE
- p.chart_permission_id IN (` + chartPermissionIds + `)
- AND r.create_platform = 4
- AND p.STATUS IN ('正式','试用','永续') GROUP BY u.user_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取关注这个文章对应产业的用户的 openid
- func GetCygxUserFllowOpenid(articleId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- cr.open_id,
- cr.cygx_user_id as user_id
- FROM
- cygx_xzs_choose_send AS s
- INNER JOIN cygx_industry_fllow AS f ON f.user_id = s.user_id
- INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
- INNER JOIN cygx_industrial_article_group_management as mg ON mg.industrial_management_id = f.industrial_management_id
- WHERE 1=1
- AND mg.article_id = ?`
- _, err = o.Raw(sql, articleId).QueryRows(&items)
- return
- }
- // 获取关注这个产业的用户的 openid
- func GetCygxUserindustryFllowOpenid(industrialId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- cr.open_id,
- cr.cygx_user_id as user_id
- FROM
- cygx_xzs_choose_send AS s
- INNER JOIN cygx_industry_fllow AS f ON f.user_id = s.user_id
- INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
- WHERE
- 1=1
- AND f.industrial_management_id = ?`
- _, err = o.Raw(sql, industrialId).QueryRows(&items)
- return
- }
- // 获取关注这个文章对应作者的用户的 openid
- func GetCygxUserFllowDepartmentOpenid(articleId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- cr.open_id,
- cr.cygx_user_id as user_id
- FROM
- cygx_article_department_follow AS f
- INNER JOIN cygx_user_record AS cr ON cr.cygx_bind_account = f.mobile
- INNER JOIN cygx_article AS a ON a.department_id = f.department_id
- WHERE
- 1=1
- AND a.article_id = ?`
- _, err = o.Raw(sql, articleId).QueryRows(&items)
- return
- }
- // 获取拒绝接收推送的的用户的 openid
- func GetCygxUserRefusetOpenid() (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- cr.open_id,
- cr.cygx_user_id as user_id
- FROM
- cygx_xzs_choose_send AS s
- INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
- WHERE
- 1=1
- AND s.is_refuse = 1`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取选择策略推送的用户的openid openid
- func GetCygxUserFllowCeLueOpenid(categoryId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- cr.open_id,
- cr.cygx_user_id AS user_id
- FROM
- cygx_xzs_choose_send AS s
- INNER JOIN cygx_xzs_choose_category AS f ON f.user_id = s.user_id
- INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
- WHERE
- 1 = 1
- AND s.is_refuse = 0
- AND s.is_subjective = 1
- AND s.is_objective = 1
- AND f.category_id = ?`
- _, err = o.Raw(sql, categoryId).QueryRows(&items)
- return
- }
- // 获取关注这个活动对应产业的用户的 openid
- func GetCygxActiviyUserFllowOpenid(activityId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- cr.open_id,
- cr.cygx_user_id AS user_id
- FROM
- cygx_xzs_choose_send AS s
- INNER JOIN cygx_industry_fllow AS f ON f.user_id = s.user_id
- INNER JOIN cygx_user_record AS cr ON cr.cygx_user_id = s.user_id
- INNER JOIN cygx_industrial_activity_group_management AS mg ON mg.industrial_management_id = f.industrial_management_id
- WHERE
- 1=1
- AND mg.activity_id = ? AND mg.source = 1 `
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- //// 根据销售规模,获取所有有权限的用户的opid
- //func GetCygxUserRecordPowerByScale(chartPermissionIds, scale string) (items []*OpenIdList, err error) {
- // o := orm.NewOrm()
- // sql := `SELECT
- // cr.open_id,
- // u.user_id,
- // u.company_id,
- // u.real_name,
- // u.mobile
- // 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
- // INNER JOIN company_product AS cp ON cp.company_id = p.company_id
- // WHERE
- // p.chart_permission_id IN (` + chartPermissionIds + `)
- // AND cp.scale IN (` + scale + `)
- // AND r.create_platform = 4
- // AND p.STATUS IN ('正式','试用','永续') GROUP BY u.company_id `
- // _, err = o.Raw(sql).QueryRows(&items)
- // return
- //}
- // GetCygxUserRecordPowerByActivitySet 根据活动设置,获取所有有权限的用户的opid
- func GetCygxUserRecordPowerByActivitySet(chartPermissionIds, condition string) (items []*OpenIdList, itemsYx []*OpenIdList, err error) {
- //o := orm.NewOrm()
- //sql := `SELECT
- // cr.open_id,
- // u.user_id,
- // u.company_id,
- // u.real_name,
- // u.mobile
- // 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
- // p.chart_permission_id IN (` + chartPermissionIds + `) ` + condition + ` AND r.create_platform = 4
- // AND p.STATUS IN ('正式','试用','永续') GROUP BY cr.open_id `
- //_, err = o.Raw(sql).QueryRows(&items)
- listMobile, err := GetCygxUserRecordPowerByActivitySetListMobile(chartPermissionIds, condition)
- if err != nil {
- return
- }
- var mobileArr []string
- for _, v := range listMobile {
- if v.Mobile != "" {
- mobileArr = append(mobileArr, v.Mobile)
- }
- }
- mobileLen := len(mobileArr)
- if mobileLen == 0 {
- return
- }
- openIdList, err := GetUserRecordListByMobileArr(mobileArr)
- if err != nil {
- return
- }
- items = openIdList
- openIdListYx, err := GetMfyxUserRecordListByMobileArr(mobileArr)
- if err != nil {
- return
- }
- itemsYx = openIdListYx
- return
- }
- // GetCygxUserRecordPowerByActivitySetListMobile 根据活动设置,获取所有有权限的用户的手机号
- func GetCygxUserRecordPowerByActivitySetListMobile(chartPermissionIds, condition string) (items []*OpenIdMobileList, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- u.user_id,
- u.company_id,
- u.real_name,
- u.mobile
- 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
- WHERE
- p.chart_permission_id IN (` + chartPermissionIds + `) ` + condition + `
- AND p.STATUS IN ('正式','试用','永续') GROUP BY u.user_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取关注了查研观向小助手公众号的所有公司ID
- func GetCygxUserRecordCompany() (items []*OpenIdList, err error) {
- listUser, err := GetCygxUserRecordCompanyUserId()
- if err != nil {
- return
- }
- var userIds []int
- for _, v := range listUser {
- userIds = append(userIds, v.UserId)
- }
- lenarr := len(userIds)
- if lenarr == 0 {
- return
- }
- var condition string
- var pars []interface{}
- condition = ` AND w.user_id IN (` + utils.GetOrmInReplace(lenarr) + `)`
- pars = append(pars, userIds)
- o := orm.NewOrm()
- sql := `SELECT
- w.company_id
- FROM
- wx_user AS w
- WHERE
- 1 = 1` + condition + `GROUP BY w.company_id `
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // 获取关注了查研观向小助手公众号的所有用户ID
- func GetCygxUserRecordCompanyUserId() (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT
- u.open_id,
- u.cygx_user_id AS user_id
- FROM
- cygx_user_record AS u
- WHERE
- 1 = 1
- AND subscribe = 1
- GROUP BY
- u.cygx_user_id `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type CompanyReportPermissionItem struct {
- CompanyId int
- ChartPermissionId int
- IsUpgrade int `description:"是否升级,1是,0否"`
- Remark string `description:"备注,权限名称带有主观客观这种"`
- PermissionName string `description:"权限名称"`
- }
- // GetCompanyReportPermissionItem 获取客户对应的权限
- func GetCompanyReportPermissionItem(condition string, pars []interface{}) (items []*CompanyReportPermissionItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- r.company_id,
- r.chart_permission_id,
- r.is_upgrade,
- c.remark,
- c.permission_name
- FROM
- company_report_permission AS r
- INNER JOIN chart_permission AS c ON r.chart_permission_id = c.chart_permission_id
- WHERE
- 1 = 1
- AND r.product_id = 2
- AND r.STATUS = '正式' ` + condition
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // 根据手机号获取用户的openid
- func GetUserRecordListByMobileArr(bindAccount []string) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- lenarr := len(bindAccount)
- if lenarr == 0 {
- return
- }
- var condition string
- var pars []interface{}
- condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
- pars = append(pars, bindAccount)
- sql := `SELECT
- u.open_id,
- u.cygx_user_id AS user_id
- FROM
- cygx_user_record AS u
- WHERE
- 1 = 1 ` + condition
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // 获取单个用户openid
- func GetUserRecordOpenidByMobile(bindAccount string) (item *OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- var sql string
- sql = `SELECT cr.open_id,cr.cygx_user_id as user_id
- FROM cygx_user_record AS cr
- WHERE cr.cygx_bind_account = ?`
- err = o.Raw(sql, bindAccount).QueryRow(&item)
- return
- }
- // 获取预约活动的用户的openID
- func GetActivityOpenIdList(activityId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT DISTINCT cr.open_id,cr.cygx_user_id as user_id
- FROM
- cygx_my_schedule AS m
- INNER JOIN cygx_user_record AS cr ON cr.cygx_bind_account = m.mobile
- WHERE m.activity_id = ? `
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取预约活动的用户的openID
- func GetActivitySpecialOpenIdList() (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT DISTINCT cr.open_id,cr.cygx_user_id as user_id
- FROM
- cygx_user_follow_special AS m
- INNER JOIN cygx_user_record AS cr ON cr.cygx_bind_account = m.mobile `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 获取关注作者的用户的openID
- func GetFollowDepartmentOpenIdList(departmentId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT DISTINCT cr.open_id,cr.cygx_user_id as user_id
- FROM
- cygx_article_department_follow AS f
- INNER JOIN cygx_user_record AS cr ON cr.cygx_bind_account = f.mobile
- WHERE
- f.department_id = ? `
- _, err = o.Raw(sql, departmentId).QueryRows(&items)
- return
- }
- // 获取关注产业的用户的openID
- func GetFollowindustrialOpenIdList(industrialManagementId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT DISTINCT cr.open_id,cr.cygx_user_id as user_id
- FROM
- cygx_industry_fllow AS f
- INNER JOIN cygx_user_record AS cr ON cr.cygx_bind_account = f.mobile
- WHERE
- f.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,
- cr.cygx_bind_account as mobile,
- cr.cygx_user_id AS 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 cygx_user_record AS cr ON cr.cygx_user_id = f.user_id
- WHERE
- agm.activity_id = ? `
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 获取预约活动的用户的openID
- func GetMfyxActivityOpenIdList(activityId int) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT DISTINCT cr.open_id,cr.cygx_user_id as user_id
- FROM
- cygx_my_schedule AS m
- INNER JOIN cygx_mfyx_gzh_user_record AS cr ON cr.cygx_bind_account = m.mobile
- WHERE m.activity_id = ? `
- _, err = o.Raw(sql, activityId).QueryRows(&items)
- return
- }
- // 根据手机号获取用户的openid
- func GetMfyxUserRecordListByMobileArr(bindAccount []string) (items []*OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- lenarr := len(bindAccount)
- if lenarr == 0 {
- return
- }
- var condition string
- var pars []interface{}
- condition = ` AND u.cygx_bind_account IN (` + utils.GetOrmInReplace(lenarr) + `)`
- pars = append(pars, bindAccount)
- sql := `SELECT
- u.open_id,
- u.cygx_user_id AS user_id
- FROM
- cygx_mfyx_gzh_user_record AS u
- WHERE
- 1 = 1 ` + condition
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // 获取单个用户openid
- func GetMfyxUserRecordOpenidByMobile(bindAccount string) (item *OpenIdList, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- var sql string
- sql = `SELECT cr.open_id,cr.cygx_user_id as user_id
- FROM cygx_mfyx_gzh_user_record AS cr
- WHERE cr.cygx_bind_account = ?`
- err = o.Raw(sql, bindAccount).QueryRow(&item)
- return
- }
|