123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type WxUser struct {
- UserId int `orm:"column(user_id);pk"`
- OpenId string `description:"open_id"`
- UnionId string `description:"union_id"`
- Subscribe string `description:"是否关注"`
- CompanyId int `description:"客户id"`
- NickName string `description:"用户昵称"`
- RealName string `description:"用户实际名称"`
- UserCode string `description:"用户编码"`
- Mobile string `description:"手机号码"`
- BindAccount string `description:"绑定时的账号"`
- WxCode string `description:"微信号"`
- Profession string `description:"职业"`
- Email string `description:"邮箱"`
- Telephone string `description:"座机"`
- Sex int `description:"普通用户性别,1为男性,2为女性"`
- Province string `description:"普通用户个人资料填写的省份"`
- City string `description:"普通用户个人资料填写的城市"`
- Country string `description:"国家,如中国为CN"`
- SubscribeTime int `description:"关注时间"`
- Remark string `description:"备注"`
- Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
- Privilege string `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"`
- Unionid string `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"`
- FirstLogin int `description:"是否第一次登陆"`
- Enabled int `description:"是否可用"`
- CreatedTime time.Time `description:"创建时间"`
- LastUpdatedTime time.Time `description:"最新一次修改时间"`
- Seller string `description:"销售员"`
- Note string `description:"客户备份信息"`
- IsNote int `description:"是否备注过信息"`
- FromType string `description:"report' COMMENT 'report:研报,teleconference:电话会"`
- ApplyMethod int `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
- RegisterTime time.Time `description:"注册时间"`
- RegisterPlatform int `description:"注册平台,1:微信端,2:PC网页端"`
- IsFreeLogin bool `description:"是否免登陆,true:免登陆,false:非免登陆"`
- LoginTime time.Time `description:"最近一次登录时间"`
- SessionKey string `description:"微信小程序会话密钥"`
- IsRegister int `description:"是否注册:1:已注册,0:未注册"`
- Source int `description:"绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询"`
- CountryCode string `description:"区号"`
- OutboundMobile string `description:"外呼手机号"`
- OutboundCountryCode string `description:"外呼手机号区号"`
- TripartiteCode string `description:"第三方给过来的用户编码,判断用户是否存在"`
- }
- //添加用户信息
- func AddWxUser(item *WxUser) (lastId int64, err error) {
- o := orm.NewOrm()
- lastId, err = o.Insert(item)
- 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:"是否弹窗过绑定外呼手机号区号"`
- Source int
- }
- func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
- sql := `SELECT * FROM wx_user WHERE union_id=? `
- err = orm.NewOrm().Raw(sql, unionid).QueryRow(&item)
- return
- }
- func GetWxUserItemByUserId(userId int) (item *WxUserItem, err error) {
- 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 = orm.NewOrm().Raw(sql, userId).QueryRow(&item)
- return
- }
- func GetWxUserItemByOpenId(openId string) (item *WxUserItem, err error) {
- sql := `SELECT * FROM wx_user WHERE open_id=? `
- err = orm.NewOrm().Raw(sql, openId).QueryRow(&item)
- return
- }
- type WxLoginResp struct {
- Authorization string
- UserId int
- FirstLogin int
- Headimgurl string `description:"用户头像"`
- Mobile string `description:"手机号"`
- Email string `description:"邮箱"`
- CompanyName string `description:"客户名称"`
- Status string `description:"状态"`
- EndDate string `description:"到期日期"`
- ProductName string `description:"客户类型名称"`
- }
- type WxGetUserInfoReq struct {
- RawData string `description:"rawData"`
- Signature string `description:"signature"`
- EncryptedData string `description:"encryptedData"`
- Iv string `description:"iv"`
- }
- //修改用户会话key
- func ModifyWxUserSessionKey(sessionKey string, userId int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE wx_user SET session_key=? WHERE user_id=? `
- _, err = o.Raw(sql, sessionKey, userId).Exec()
- return
- }
- //添加用户信息
- func ModifyWxUserInfo(unionId, nickName, province, city, country, avatar string, gender, userId int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE wx_user SET union_id=?,unionid=?,nick_name=?,sex=?,province=?,city=?,country=?,headimgurl=? WHERE user_id=? `
- _, err = o.Raw(sql, unionId, unionId, nickName, gender, province, city, country, avatar, userId).Exec()
- return
- }
- //修改用户会话key
- func DeleteWxUserByUserId(userId int) (err error) {
- o := orm.NewOrm()
- sql := `DELETE FROM wx_user WHERE user_id=? `
- _, err = o.Raw(sql, userId).Exec()
- return
- }
- type WxGetUserInfoResp struct {
- //UsersId int `orm:"column(id);pk"`
- //Mobile string `description:"手机号"`
- //NickName string `description:"昵称"`
- //Gender int `description:"用户性别 1:男性,2:女性,0:未知(默认)"`
- //CreateTime time.Time `description:"注册时间"`
- //ModifyTime time.Time `description:"修改时间"`
- //AvatarUrl string `description:"头像地址"`
- //City string `description:"城市"`
- //Province string `description:"省"`
- //Country string `description:"国家"`
- //Language string `description:"语言"`
- //Appid string `description:"Appid"`
- //Timestamp int64 `description:"时间戳"`
- Authorization string `description:"登陆凭证,后续接口调用时,带在请求头里面Key:Authorization"`
- }
- type WxGetPhoneNumberReq struct {
- EncryptedData string `description:"encryptedData"`
- Iv string `description:"iv"`
- }
- func ModifyUsersMobile(usersId int, phoneNumber string) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE wx_user SET mobile=? WHERE user_id=? `
- _, err = o.Raw(sql, phoneNumber, usersId).Exec()
- return
- }
- type WxGetPhoneNumberResp struct {
- PhoneNumber string `description:"用户绑定的手机号(国外手机号会有区号)"`
- PurePhoneNumber string `description:"没有区号的手机号"`
- CountryCode string `description:"区号"`
- }
- func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
- 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.mobile=? `
- err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
- return
- }
- func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
- sql := `SELECT * FROM wx_user WHERE email=? `
- err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
- return
- }
- func ModifyReportLastViewTime(uid int) (err error) {
- sql := ` UPDATE wx_user SET report_last_view_time=NOW()
- WHERE user_id=? `
- _, err = orm.NewOrm().Raw(sql, uid).Exec()
- return
- }
- //变更联系人是否已注册状态
- func ModifyWxUserRegisterStatus(userId int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE wx_user SET is_register=?,source=3,register_time=NOW() WHERE user_id = ? `
- _, err = o.Raw(sql, 1, userId).Exec()
- return
- }
- //修改用户是否绑定外呼手机号弹窗
- func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
- _, err = o.Raw(sql, userId).Exec()
- return
- }
- //列表
- func GetUserListAll() (items []*WxUserItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM wx_user WHERE mobile <>'' AND outbound_mobile = ''`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- //修改手机号区号 8位号码+852,9位号码+886,10位号码+1,11位及以上号码+86
- func UPdateUserCountryCode(item *WxUserItem) (err error) {
- o := orm.NewOrm()
- if item.CountryCode == "" && len(item.Mobile) >= 11 {
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=86 , country_code=86 WHERE user_id = ?`
- _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
- } else if item.CountryCode == "" && len(item.Mobile) == 8 {
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=852 , country_code=852 WHERE user_id = ?`
- _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
- } else if item.CountryCode == "" && len(item.Mobile) == 9 {
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=886 , country_code=886 WHERE user_id = ?`
- _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
- } else if item.CountryCode == "" && len(item.Mobile) == 10 {
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=1 , country_code=1 WHERE user_id = ?`
- _, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
- } else {
- sql := ` UPDATE wx_user SET outbound_mobile= ? , outbound_country_code=? WHERE user_id = ?`
- _, err = o.Raw(sql, item.Mobile, item.CountryCode, item.UserId).Exec()
- }
- return
- }
- //判断公司下用户名称是否存在
- func GetUserCountByName(companyId int, name string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? AND real_name = ?`
- err = orm.NewOrm().Raw(sql, companyId, name).QueryRow(&count)
- return
- }
- //判断公司下用户名称是否存在
- func GetUserCountByThirdName(companyId int, name string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM wx_user WHERE company_id = ? AND tripartite_code = ?`
- err = orm.NewOrm().Raw(sql, companyId, name).QueryRow(&count)
- return
- }
- func UpdateUserMobile(uid int, mobile string) (err error) {
- sql := ` UPDATE wx_user SET mobile=?
- WHERE user_id=? `
- _, err = orm.NewOrm().Raw(sql, mobile, uid).Exec()
- return
- }
- //获取公司下用户详情详情详情
- func GetUserByName(companyId int, name string) (item *WxUser, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM wx_user WHERE company_id = ? AND real_name = ? `
- err = o.Raw(sql, companyId, name).QueryRow(&item)
- return
- }
- //获取公司下用户详情详情详情
- func GetUserByThirdName(companyId int, name string) (item *WxUser, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM wx_user WHERE company_id = ? AND tripartite_code = ? `
- err = o.Raw(sql, companyId, name).QueryRow(&item)
- return
- }
|