12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package models
- import (
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- func GetSessionByToken(token string) (item *CygxMfyxWebSession, err error) {
- sql := `SELECT * FROM cygx_mfyx_web_session WHERE access_token=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
- o := orm.NewOrm()
- err = o.Raw(sql, token).QueryRow(&item)
- return
- }
- type CygxClptSession1 struct {
- SessionId int `orm:"column(session_id);pk"`
- Mobile string
- UserId int
- AccessToken string
- ExpireTime time.Time
- CreatedTime time.Time
- LastUpdatedTime time.Time
- OpenId string `description:"用户openid,最大长度:32"`
- UnionId string `description:"用户unionid,最大长度:64"`
- }
- type CygxMfyxWebSession struct {
- SessionId int `orm:"column(session_id);pk"`
- Mobile string
- UserId int
- AccessToken string
- ExpireTime time.Time
- CreatedTime time.Time
- LastUpdatedTime time.Time
- OpenId string `description:"用户openid,最大长度:32"`
- UnionId string `description:"用户unionid,最大长度:64"`
- SessionStatus int `description:"token状态,0正常,1被顶号"`
- }
- // 添加用户session信息
- func AddCygxMfyxWebSession(item *CygxMfyxWebSession) (err error) {
- o := orm.NewOrm()
- _, err = o.Insert(item)
- return
- }
- func GetXzsSessionCountByToken(token string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM cygx_mfyx_web_session WHERE access_token=? LIMIT 1 `
- o := orm.NewOrm()
- err = o.Raw(sql, token).QueryRow(&count)
- return
- }
- // 获取用户token详情
- func GetUnionidByToken(token string) (item *CygxMfyxWebSession, err error) {
- sql := `SELECT * FROM cygx_xzs_session WHERE access_token=? LIMIT 1 `
- o := orm.NewOrm()
- err = o.Raw(sql, token).QueryRow(&item)
- return
- }
- // 根据用户openid获取token
- func GetTokenByOpenId(mobile string) (item *CygxMfyxWebSession, err error) {
- sql := `SELECT * FROM cygx_mfyx_web_session WHERE mobile=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
- o := orm.NewOrm()
- err = o.Raw(sql, mobile).QueryRow(&item)
- return
- }
- // 用户绑定手机号时同时绑定外呼手机号
- func BindSessionMobile(mobile, token string) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE cygx_mfyx_web_session SET mobile=? WHERE access_token=? `
- _, err = o.Raw(sql, mobile, token).Exec()
- return
- }
- // 根据用户id和平台id获取用户关系
- func GetUserSessionByUserId(userId int) (item *CygxMfyxWebSession, err error) {
- sql := `SELECT * FROM cygx_mfyx_web_session WHERE user_id=? `
- err = orm.NewOrm().Raw(sql, userId).QueryRow(&item)
- return
- }
- // 把其他有效token改为被顶号状态
- func UpdateSessionStatusByMobile(mobile, token string) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE cygx_mfyx_web_session SET session_status= 1 WHERE mobile=? AND expire_time> NOW() AND access_token != ? `
- _, err = o.Raw(sql, mobile, token).Exec()
- return
- }
|