package router import ( "encoding/json" "fmt" "net/url" "app.yhyue.com/moapp/jybase/redis" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/net/ghttp" "github.com/gogf/gf/v2/util/gconv" ) const ( JY_SESSIONNAME = "SESSIONID" ) // JySession 剑鱼程序SESSION获取 type JySession struct { UserId string // 上下文用户信息 NewUid int64 // 新用户id EntId int64 // 当前企业id EntName string // 当前企业名称 Phone string // 手机号 Data g.Map // 当前Session管理对象 EntUserId int64 //当前企业用户id UserName string //用户名称 NickName string //微信昵称 YyName string //剑鱼生成的昵称 UserPositionId int64 //个人职位id UserAccountId int64 //个人账户id EntUserPositionId int64 //企业职位id EntUserName string //企业员工姓名 PersonId int64 //自然人id AccountId int64 //账户id EntAccountId int64 //企业账户id PositionId int64 //职位id PositionType int64 //职位类型 MgoUserId string //mongodb用户id EntRole int64 //管理员角色 EntNicheDis int64 //商机分配角色 EntDeptId int64 //部门id EntUserRole string // } // InitJySessionContext 获取用户session func InitJySessionContext(r *ghttp.Request) (jSession *JySession, err error) { jSession = &JySession{} cookie, err := r.Request.Cookie(JY_SESSIONNAME) if err != nil { return } if cookie.Value == "" { err = fmt.Errorf("cookie 内容为空") return } findKey, _ := url.QueryUnescape(cookie.Value) bs, err := redis.GetBytes("session", findKey) if err != nil { return } var data map[string]interface{} err = json.Unmarshal(*bs, &data) jSession.Phone, _ = data["phone"].(string) jSession.UserId, _ = data["userId"].(string) jSession.EntName, _ = data["entName"].(string) jSession.EntId = gconv.Int64(data["entId"]) jSession.NewUid = gconv.Int64(data["base_user_id"]) jSession.EntUserId = gconv.Int64(data["entUserId"]) jSession.UserName, _ = data["userName"].(string) jSession.NickName, _ = data["s_nickname"].(string) jSession.YyName, _ = data["s_jyname"].(string) jSession.EntUserName, _ = data["entUserName"].(string) jSession.UserPositionId = gconv.Int64(data["userPositionId"]) jSession.UserAccountId = gconv.Int64(data["userAccountId"]) jSession.EntUserPositionId = gconv.Int64(data["entUserPositionId"]) jSession.PersonId = gconv.Int64(data["personId"]) jSession.AccountId = gconv.Int64(data["accountId"]) jSession.EntAccountId = gconv.Int64(data["entAccountId"]) jSession.PositionId = gconv.Int64(data["positionId"]) jSession.PositionType = gconv.Int64(data["positionType"]) jSession.MgoUserId = gconv.String(data["mgoUserId"]) jSession.EntRole = gconv.Int64(data["entRole"]) jSession.EntNicheDis = gconv.Int64(data["entNicheDis"]) jSession.EntDeptId = gconv.Int64(data["entDeptId"]) jSession.EntUserRole = gconv.String(data["entUserRole"]) jSession.Data = data return }