123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_crm_api/utils"
- "time"
- )
- type WxUser struct {
- UserId int64 `orm:"column(user_id);pk"`
- Mobile string
- Email string
- CompanyId int
- RealName string `description:"姓名"`
- NickName string `description:"昵称"`
- CreatedTime time.Time
- MobileTwo string `description:"备用手机号"`
- BusinessCardUrl string `description:"名片"`
- IsMaker int `description:"是否决策人,1:是,0:否"`
- Position string `description:"职位"`
- Sex int `description:"普通用户性别,1为男性,2为女性"`
- DepartmentName string `description:"联系人部门"`
- RegisterTime time.Time
- RegisterPlatform int
- Remark string `description:"备注"`
- CountryCode string `description:"区号,86、852、886等"`
- OutboundMobile string `description:"外呼手机号"`
- OutboundCountryCode string `description:"外呼手机号区号,86、852、886等"`
- LastUpdatedTime time.Time `description:"最近一次更新时间"`
- IsDeal int `description:"是否标记处理 0-未处理 1-已处理"`
- OpenId string `orm:"column(open_id)" description:"微信openid"`
- Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
- UserLabel string `description:"查研观向用户标签"`
- MarkGroup string `description:"标记分组"`
- FiccViewTotal int `description:"ficc报告的阅读次数"`
- FiccLastViewTime string `description:"ficc报告最近一次阅读时间"`
- RaiViewTotal int `description:"权益报告的阅读次数"`
- RaiLastViewTime string `description:"权益报告的最近一次阅读时间"`
- }
- func AddWxUser(item *WxUser) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- return
- }
- func GetWxUserByMobile(mobile string) (item *WxUser, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM wx_user WHERE mobile = ? LIMIT 1`
- err = o.Raw(sql, mobile).QueryRow(&item)
- return
- }
- // GetWxUserByMobileCountryCode 根据手机号和区号获取用户信息
- func GetWxUserByMobileCountryCode(mobile, countryCode string) (item *WxUser, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM wx_user WHERE mobile = ? `
- sql += ` and country_code in ("","` + countryCode + `") `
- sql += ` LIMIT 1 `
- err = o.Raw(sql, mobile).QueryRow(&item)
- return
- }
- func GetWxUserByUserId(userId int) (item *WxUser, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM wx_user WHERE user_id=? `
- err = o.Raw(sql, userId).QueryRow(&item)
- return
- }
- // 更新wxUser信息
- func (wxUser *WxUser) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(wxUser, cols...)
- return
- }
- type PotentialUserItem struct {
- UserId int `description:"用户id"`
- RealName string `description:"姓名"`
- CountryCode string `description:"区号,86、852、886等"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- CreatedTime string `description:"注册时间"`
- ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
- CompanyName string `description:"客户名称"`
- ViewTotal int `description:"累计阅读次数"`
- LastViewTime time.Time `json:"-" description:"最后一次阅读时间"`
- LastViewTimeStr string `description:"最后一次阅读时间"`
- FromType string `description:"report:研报,teleconference:电话会"`
- BusinessCardUrl string `description:"名片"`
- Source int `description:"来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询,5:电话会"`
- IsDeal int `description:"是否标记处理,0是未处理,1是已处理"`
- }
- type PotentialUserListResp struct {
- List []*PotentialUserItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- // 联系人导入预览数据返回
- type ImportListResp struct {
- ValidUser []*WxUser `description:"有效客户数据"`
- RepeatUser []*WxUser `description:"重复客户数据"`
- }
- func GetPotentialUserListCount(condition string, pars []interface{}) (count int, err error) {
- o := orm.NewOrm()
- sql := `SELECT COUNT(1) AS count
- FROM wx_user AS a
- LEFT JOIN company AS b ON a.company_id = b.company_id
- LEFT JOIN user_record AS c ON a.user_id=c.user_id
- WHERE b.enabled = 1 AND b.company_id = 1
- AND (a.mobile IS NOT NULL || a.email IS NOT NULL)
- AND (a.mobile<>'' OR a.email<>'')
- AND (c.create_platform<>4 or c.create_platform is null)`
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- func GetPotentialUserList(condition string, pars []interface{}, startSize, pageSize int) (items []*PotentialUserItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT a.*,a.note AS company_name,
- IF(b.type IN (1,2),1,0) AS is_fee_customer,
- (SELECT count(1) FROM user_view_history AS uvh WHERE uvh.user_id=a.user_id GROUP BY a.user_id) AS view_total,
- a.report_last_view_time AS last_view_time_str,
- c.create_platform
- FROM wx_user AS a
- LEFT JOIN company AS b ON a.company_id = b.company_id
- LEFT JOIN user_record AS c ON a.user_id=c.user_id
- WHERE b.enabled = 1 AND b.company_id = 1
- AND (a.mobile IS NOT NULL || a.email IS NOT NULL)
- AND (a.mobile<>'' OR a.email<>'')
- AND (c.create_platform<>4 or c.create_platform is null) `
- if condition != "" {
- sql += condition
- }
- sql += ` GROUP BY a.user_id `
- sql += `ORDER BY a.created_time DESC LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- type PotentialUserDeleteReq struct {
- UserId int `description:"用户id"`
- }
- // 标记潜在用户请求
- type PotentialUserDealReq struct {
- UserId int `description:"用户id"`
- }
- func DeletePotentialUser(userId int) (err error) {
- sql := ` DELETE FROM wx_user WHERE user_id=? `
- _, err = orm.NewOrm().Raw(sql, userId).Exec()
- return
- }
- // DeleteWxUserByUserIds 根据用户id字符串批量删除用户信息
- func DeleteWxUserByUserIds(userIds string) (err error) {
- sql := ` DELETE FROM wx_user WHERE user_id in (` + userIds + `) `
- _, err = orm.NewOrm().Raw(sql).Exec()
- return
- }
- // 移动潜在客户名下的联系人 请求数据
- type PotentialUserMoveReq struct {
- UserId int `description:"用户id"`
- CompanyId int `description:"移动到的客户id"`
- SellerId int `description:"需要移动到的销售id"`
- RealName string `description:"姓名"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- Remark string `description:"备注信息"`
- //crm4.0新增校验字段
- Sex int `description:"用户性别,1为男性,2为女性"`
- RegionType string `description:"区域,枚举值:国内、海外"`
- Position string `description:"职位"`
- IsMaker int `description:"是否决策人,1:是,0:否"`
- BusinessCardUrl string `description:"名片地址"`
- DepartmentName string `description:"联系人部门"`
- CountryCode string `description:"区号,86、852、886等"`
- }
- // 移动联系人请求数据
- type UserMoveReq struct {
- UserId int `description:"用户id"`
- CompanyId int `description:"移动到的客户id"`
- SellerId int `description:"需要移动到的销售id"`
- }
- // FICC申请单-移动潜在客户名下的联系人 请求数据
- type ApplyRecordPotentialUserMoveReq struct {
- UserId int `description:"用户id"`
- CompanyId int `description:"移动到的客户id"`
- SellerId int `description:"需要移动到的销售id"`
- RealName string `description:"姓名"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- Remark string `description:"备注信息"`
- ApplyRecordId int `description:"申请单ID"`
- Sex int `description:"用户性别,1为男性,2为女性"`
- RegionType string `description:"区域,枚举值:国内、海外"`
- Position string `description:"职位"`
- IsMaker int `description:"是否决策人,1:是,0:否"`
- BusinessCardUrl string `description:"名片地址"`
- DepartmentName string `description:"联系人部门"`
- CountryCode string `description:"区号,86、852、886等"`
- }
- func CheckUserMobileIsRegister(userId int, mobile string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM wx_user AS a
- INNER JOIN company AS b ON a.company_id = b.company_id
- WHERE a.mobile = ? AND a.user_id<> ? `
- o := orm.NewOrm()
- err = o.Raw(sql, mobile, userId).QueryRow(&count)
- return
- }
- func CheckUserEmailIsRegister(userId int, email string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM wx_user AS a
- INNER JOIN company AS b ON a.company_id = b.company_id
- WHERE a.email = ? AND a.user_id<> ? `
- o := orm.NewOrm()
- err = o.Raw(sql, email, userId).QueryRow(&count)
- return
- }
- // 移动潜在客户名下的联系人
- func MovePotentialUser(userId, companyId int, realName, mobile, email, remark string) (err error) {
- if realName != "" {
- sql := ` UPDATE wx_user
- SET
- company_id = ?,
- real_name = ?,
- mobile = ?,
- email = ?,
- remark = ?,
- last_updated_time = NOW(),
- is_note = 1
- WHERE user_id = ? `
- _, err = orm.NewOrm().Raw(sql, companyId, realName, mobile, email, remark, userId).Exec()
- } else {
- sql := ` UPDATE wx_user
- SET
- company_id = ?,
- mobile = ?,
- email = ?,
- remark = ?,
- last_updated_time = NOW(),
- is_note = 1
- WHERE user_id = ? `
- _, err = orm.NewOrm().Raw(sql, companyId, mobile, email, remark, userId).Exec()
- }
- return
- }
- // 移动联系人
- func MoveUser(userId, companyId int) (err error) {
- sql := ` UPDATE wx_user
- SET
- company_id = ?,
- last_updated_time = NOW(),
- is_note = 1
- WHERE user_id = ? `
- _, err = orm.NewOrm().Raw(sql, companyId, userId).Exec()
- return
- }
- type ReportViewRecordTotal struct {
- ViewTotal int
- LastViewTime time.Time
- }
- func GetReportViewMaxTime(uid int) (item *ReportViewRecordTotal, err error) {
- o := orm.NewOrmUsingDB("rddp")
- rddpSql := "SELECT MAX(create_time) AS last_view_time,COUNT(1) AS view_total FROM report_view_record WHERE user_id=? "
- err = o.Raw(rddpSql, uid).QueryRow(&item)
- return
- }
- // 根据用户id字符串获取用户的浏览数
- func GetReportViewMaxTimeByUserIds(userIds string) (items []*ReportViewRecord, err error) {
- o := orm.NewOrmUsingDB("rddp")
- rddpSql := `SELECT user_id,MAX(create_time) AS last_view_time,COUNT(1) AS view_total FROM report_view_record WHERE user_id in (` + userIds + `) group by user_id`
- _, err = o.Raw(rddpSql).QueryRows(&items)
- return
- }
- // 根据用户手机号字符串获取用户的浏览数
- type ReportViewMobileRecord struct {
- Mobile string
- ViewTotal int
- LastViewTime time.Time
- }
- func GetReportViewMaxTimeByMobiles(mobiles string) (items []*ReportViewMobileRecord, err error) {
- o := orm.NewOrmUsingDB("rddp")
- rddpSql := `SELECT mobile,MAX(create_time) AS last_view_time,COUNT(1) AS view_total FROM report_view_record WHERE mobile in (` + mobiles + `) group by mobile`
- _, err = o.Raw(rddpSql).QueryRows(&items)
- return
- }
- // 根据用户邮箱字符串获取用户的浏览数
- type ReportViewEmailRecord struct {
- Email string
- ViewTotal int
- LastViewTime time.Time
- }
- func GetReportViewMaxTimeByEmails(emails string) (items []*ReportViewEmailRecord, err error) {
- o := orm.NewOrmUsingDB("rddp")
- rddpSql := `SELECT email,MAX(create_time) AS last_view_time,COUNT(1) AS view_total FROM report_view_record WHERE email in (` + emails + `) group by email`
- _, err = o.Raw(rddpSql).QueryRows(&items)
- return
- }
- func GetPotentialUserListExport(condition string, pars []interface{}) (items []*PotentialUserItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT DISTINCT a.*,b.company_name,
- IF(b.type IN (1,2),1,0) AS is_fee_customer,
- (SELECT count(1) FROM user_view_history AS uvh WHERE uvh.user_id=a.user_id GROUP BY a.user_id) AS view_total,
- (SELECT max(uvh.created_time) FROM user_view_history AS uvh WHERE uvh.user_id=a.user_id GROUP BY a.user_id) AS last_view_time
- FROM wx_user AS a
- LEFT JOIN company AS b ON a.company_id = b.company_id
- INNER JOIN user_record AS c ON a.user_id=c.user_id
- WHERE b.enabled = 1 AND b.company_id = 1
- AND (a.mobile IS NOT NULL || a.email IS NOT NULL)
- AND (a.mobile<>'' OR a.email<>'')
- AND c.create_platform<>4 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY a.last_updated_time DESC `
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- type WxUserDetail struct {
- UserId int64 `orm:"column(user_id);pk"`
- CountryCode string `description:"区号,86、852、886等"`
- Mobile string
- Email string
- CompanyId int
- RealName string `description:"姓名"`
- CreatedTime time.Time
- MobileTwo string `description:"备用手机号"`
- BusinessCardUrl string `description:"名片"`
- IsMaker int `description:"是否决策人,1:是,0:否"`
- Position string `description:"职位"`
- Sex int `description:"普通用户性别,1为男性,2为女性"`
- CompanyName string `description:"公司名称"`
- DepartmentName string `description:"联系人部门"`
- SellerRealName string `description:"销售"`
- }
- // GetWxUserListByUserIds 根据用户ID集合获取用户
- func GetWxUserListByUserIds(userIds string) (list []*WxUser, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM wx_user WHERE user_id IN (` + userIds + `) `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // GetWxUserByCompanyIdAndMobile 根据客户ID及手机号获取用户
- func GetWxUserByCompanyIdAndMobile(companyId int, mobile string) (item *WxUser, err error) {
- o := orm.NewOrm()
- sql := ` SELECT * FROM wx_user WHERE company_id = ? AND mobile = ? LIMIT 1 `
- err = o.Raw(sql, companyId, mobile).QueryRow(&item)
- return
- }
- // DeleteWxUserAndRecordByUserId 删除用户及第三方信息
- func DeleteWxUserAndRecordByUserId(userId int) (err error) {
- o := orm.NewOrm()
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- // 删除wx_user
- userSql := ` DELETE FROM wx_user WHERE user_id = ? LIMIT 1 `
- _, err = to.Raw(userSql, userId).Exec()
- // 删除user_record
- if err == nil {
- recordSql := ` DELETE FROM user_record WHERE user_id = ? `
- _, err = to.Raw(recordSql, userId).Exec()
- }
- return
- }
- // 获取这个公司下面所有用户的手机号
- func GetCompanyUserMobilesByCompanyId(companyId int) (mobiles string, err error) {
- o := orm.NewOrm()
- sql := ` SELECT GROUP_CONCAT( DISTINCT a.mobile SEPARATOR ',' ) AS mobiles FROM
- wx_user AS a WHERE company_id = ? AND mobile != '' `
- err = o.Raw(sql, companyId).QueryRow(&mobiles)
- return
- }
- // 获取这个公司下面所有用户的邮箱号
- func GetCompanyUserEmailsByCompanyId(companyId int) (emails string, err error) {
- o := orm.NewOrm()
- sql := ` SELECT GROUP_CONCAT( DISTINCT a.email SEPARATOR ',' ) AS emails FROM
- wx_user AS a WHERE company_id = ? AND email != '' `
- err = o.Raw(sql, companyId).QueryRow(&emails)
- return
- }
- // 获取这个公司下面所有用户的手机号
- func SetUserSubscribe(openId string) (err error) {
- o := orm.NewOrm()
- sql := ` UPDATE user_record SET subscribe=1,subscribe_time=NOW() WHERE open_id=? `
- _, err = o.Raw(sql, openId).Exec()
- return
- }
- type WxUserItem struct {
- UserId int `description:"用户id"`
- OpenId string `description:"open_id"`
- UnionId string `description:"union_id"`
- CompanyId int `description:"客户id"`
- NickName string `description:"用户昵称"`
- RealName string `description:"用户实际名称"`
- Mobile string `description:"手机号码"`
- BindAccount string `description:"绑定时的账号"`
- Email string `description:"邮箱"`
- Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
- ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
- FirstLogin int `description:"是否第一次登陆"`
- IsFreeLogin int `description:"是否免登陆,true:免登陆,false:非免登陆"`
- LoginTime time.Time `description:"登录时间"`
- CreatedTime time.Time `description:"创建时间"`
- LastUpdatedTime time.Time `description:"最近一次修改时间"`
- SessionKey string `description:"微信小程序会话密钥"`
- CompanyName string `description:"公司名称"`
- IsRegister int `description:"是否注册:1:已注册,0:未注册"`
- CountryCode string `description:"手机国家区号"`
- OutboundMobile string `description:"外呼手机号"`
- OutboundCountryCode string `description:"外呼手机号区号"`
- IsMsgOutboundMobile int `description:"是否弹窗过绑定外呼手机号区号"`
- IsMaker int `description:"是否是决策人"`
- Source int
- Position string `description:"职位"`
- }
- // GetWxUserListByUserIds 根据用户ID集合获取用户有公司名称
- func GetWxUserListByUserIdsHaveCompany(userIds string) (list []*WxUserItem, err error) {
- o := orm.NewOrm()
- sql := ` SELECT u.*, c.company_name FROM wx_user AS u
- INNER JOIN company AS c ON c.company_id = u.company_id
- WHERE user_id IN (` + userIds + `) `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // GetWxUserByAdminId 通过后台用户ID及微信平台获取对应的微信用户
- func GetWxUserByAdminId(platform, adminId int) (item *WxUser, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- wu.user_id
- FROM
- wx_user AS wu
- JOIN user_record AS ur ON wu.user_id = ur.user_id AND ur.create_platform = ?
- JOIN admin AS ad ON wu.mobile = ad.mobile
- WHERE
- ad.admin_id = ?`
- err = o.Raw(sql, platform, adminId).QueryRow(&item)
- return
- }
- // GetWxUserByOutboundMobiles 根据用户手机号获取用户详情
- func GetWxUserByOutboundMobiles(mobiles []string) (items []*WxUser, err error) {
- lenmobiles := len(mobiles)
- if lenmobiles == 0 {
- return
- }
- sql := `SELECT* FROM wx_user WHERE outbound_mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
- o := orm.NewOrm()
- _, err = o.Raw(sql, mobiles).QueryRows(&items)
- return
- }
- // GetWxUserByUserIds 根据用户ID获取用户详情
- func GetWxUserByUserIds(userIds []int) (items []*WxUser, err error) {
- lenuserIds := len(userIds)
- if lenuserIds == 0 {
- return
- }
- sql := `SELECT* FROM wx_user WHERE user_id in (` + utils.GetOrmInReplace(lenuserIds) + `) `
- o := orm.NewOrm()
- _, err = o.Raw(sql, userIds).QueryRows(&items)
- return
- }
- // GetWxUserListByUserMobileHaveCompany 根据用户手机号集合获取用户有公司名称
- func GetWxUserListByUserMobileHaveCompany(mobiles []string) (list []*WxUserItem, err error) {
- lenmobiles := len(mobiles)
- if lenmobiles == 0 {
- return
- }
- o := orm.NewOrm()
- sql := ` SELECT u.*, c.company_name FROM wx_user AS u
- INNER JOIN company AS c ON c.company_id = u.company_id
- WHERE mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) `
- _, err = o.Raw(sql, mobiles).QueryRows(&list)
- return
- }
- // GetWxUserListCompanyId 根据公司ID获取所有用户信息
- func GetWxUserListCompanyId(companyId int) (list []*WxUserItem, err error) {
- o := orm.NewOrm()
- sql := ` SELECT* FROM wx_user WHERE company_id = ? `
- _, err = o.Raw(sql, companyId).QueryRows(&list)
- return
- }
- type WxUserSller struct {
- UserId int `description:"用户id"`
- RealName string `description:"姓名"`
- Mobile string `description:"手机号"`
- CompanyId int `description:"公司id"`
- CompanyName string `description:"公司名称"`
- SellerName string `description:"所属销售"`
- Status string `description:"所属销售"`
- ChartPermissionName string `description:"所属销售"`
- ShareSeller string `description:"所属销售"`
- }
- // GetWxUserRaiSllerListByUserIds 根据用户id获取权益相关用户信息
- func GetWxUserRaiSllerListByUserIds(userIds []int) (list []*WxUserSller, err error) {
- lenarr := len(userIds)
- if lenarr == 0 {
- return
- }
- o := orm.NewOrm()
- sql := ` SELECT
- w.user_id,
- w.real_name,
- w.mobile,
- c.company_name,
- p.seller_name
- FROM
- wx_user AS w
- INNER JOIN company_product AS p ON p.company_id = w.company_id
- INNER JOIN company AS c ON c.company_id = w.company_id
- WHERE
- 1 = 1
- AND p.product_id = 2
- AND w.user_id IN (` + utils.GetOrmInReplace(lenarr) + `) `
- _, err = o.Raw(sql, userIds).QueryRows(&list)
- return
- }
- // GetWxUserRaiSllerListByUserMobile 根据用户手机号获取权益相关用户信息
- func GetWxUserRaiSllerListByUserMobile(mobiles []string) (list []*WxUserSller, err error) {
- lenarr := len(mobiles)
- if lenarr == 0 {
- return
- }
- o := orm.NewOrm()
- sql := ` SELECT
- w.user_id,
- w.real_name,
- w.mobile,
- c.company_name,
- c.company_id,
- p.status,
- p.seller_name,
- p.share_seller
- FROM
- wx_user AS w
- INNER JOIN company_product AS p ON p.company_id = w.company_id
- INNER JOIN company AS c ON c.company_id = w.company_id
- WHERE
- 1 = 1
- AND p.product_id = 2
- AND w.mobile IN (` + utils.GetOrmInReplace(lenarr) + `) `
- _, err = o.Raw(sql, mobiles).QueryRows(&list)
- return
- }
- // GetWxUserRaiSllerListByUserMobile 根据用户手机号获取权益相关用户信息
- func GetWxUserRaiSllerListByUserMobileFiic(mobiles []string) (list []*WxUserSller, err error) {
- lenarr := len(mobiles)
- if lenarr == 0 {
- return
- }
- o := orm.NewOrm()
- sql := ` SELECT
- w.user_id,
- w.real_name,
- w.mobile,
- c.company_name
- FROM
- wx_user AS w
- INNER JOIN company_product AS p ON p.company_id = w.company_id
- INNER JOIN company AS c ON c.company_id = w.company_id
- WHERE
- 1 = 1
- AND p.product_id = 1
- AND w.mobile IN (` + utils.GetOrmInReplace(lenarr) + `) `
- _, err = o.Raw(sql, mobiles).QueryRows(&list)
- return
- }
- // GetWxUserRaiSllerListByUserMobile 根据用户手机号获取权益相关用户信息
- func GetWxUserRaiSllerListByUserComapnyId(company_ids []int) (list []*WxUserSller, err error) {
- lenarr := len(company_ids)
- if lenarr == 0 {
- return
- }
- o := orm.NewOrm()
- sql := ` SELECT
- c.company_name,
- c.company_id,
- p.status,
- p.seller_name,
- p.share_seller
- FROM
-
- company_product AS p
- INNER JOIN company AS c ON c.company_id = p.company_id
- WHERE
- 1 = 1
- AND p.product_id = 2
- AND c.company_id IN (` + utils.GetOrmInReplace(lenarr) + `) `
- _, err = o.Raw(sql, company_ids).QueryRows(&list)
- return
- }
- func GetWxUserRaiSllerListByUserComapnyIdFicc(company_ids []int) (list []*WxUserSller, err error) {
- lenarr := len(company_ids)
- if lenarr == 0 {
- return
- }
- o := orm.NewOrm()
- sql := ` SELECT
- c.company_name,
- c.company_id,
- p.status,
- p.seller_name
- FROM
-
- company_product AS p
- INNER JOIN company AS c ON c.company_id = p.company_id
- WHERE
- 1 = 1
- AND p.product_id = 1
- AND c.company_id IN (` + utils.GetOrmInReplace(lenarr) + `) `
- _, err = o.Raw(sql, company_ids).QueryRows(&list)
- return
- }
- // GetWxUserByCompanyIds 根据客户ID集合获取用户列表
- func GetWxUserByCompanyIds(companyIds []int) (items []*WxUser, err error) {
- num := len(companyIds)
- if num == 0 {
- return
- }
- sql := `SELECT * FROM wx_user WHERE company_id in (` + utils.GetOrmInReplace(num) + `) `
- o := orm.NewOrm()
- _, err = o.Raw(sql, companyIds).QueryRows(&items)
- return
- }
- // GetWxUserList 用户列表查询
- func GetWxUserList(condition string, pars []interface{}) (items []*WxUser, err error) {
- o := orm.NewOrm()
- sql := `SELECT *
- FROM wx_user WHERE 1 = 1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func SetUserFollow(userId, follow int) (err error) {
- o := orm.NewOrm()
- sql := ` UPDATE wx_user SET is_follow=? WHERE user_id=? `
- _, err = o.Raw(sql, follow, userId).Exec()
- return
- }
- func GetCompanyFollowCount(companyId int) (count int, err error) {
- o := orm.NewOrm()
- sql := ` SELECT COUNT(1) FROM wx_user WHERE company_id=? AND is_follow = 1 `
- err = o.Raw(sql, companyId).QueryRow(&count)
- return
- }
- // 根据用户ID获取相关信息
- func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT a.*,b.company_name FROM wx_user AS a
- LEFT JOIN company AS b on a.company_id=b.company_id
- WHERE a.user_id=? `
- err = o.Raw(sql, userId).QueryRow(&item)
- return
- }
|