corpconfig
This commit is contained in:
parent
19059f0874
commit
722647dc03
|
@ -1,5 +1,11 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/spf13/cast"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CorpUser struct {
|
||||
Id int64
|
||||
CorpId int64
|
||||
|
@ -10,3 +16,43 @@ type CorpUser struct {
|
|||
CreateTime int64
|
||||
UpdateTime int64
|
||||
}
|
||||
|
||||
type CorpUserConfig struct {
|
||||
UserRole string `json:"user_role"` //员工角色
|
||||
}
|
||||
|
||||
func (u *CorpUser) GetConfig() *CorpUserConfig {
|
||||
var salary CorpUserConfig
|
||||
json.Unmarshal([]byte(u.Config), &salary)
|
||||
return &salary
|
||||
}
|
||||
|
||||
func (u *CorpUserConfig) IsAdmin() bool {
|
||||
arrs := strings.Split(u.UserRole, ",")
|
||||
for _, a := range arrs {
|
||||
if cast.ToInt(a) == StaffUserRoleAdmin {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *CorpUserConfig) IsFinance() bool {
|
||||
arrs := strings.Split(u.UserRole, ",")
|
||||
for _, a := range arrs {
|
||||
if cast.ToInt(a) == StaffUserRoleFinance || cast.ToInt(a) == StaffUserRoleAdmin {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (u *CorpUserConfig) IsHr() bool {
|
||||
arrs := strings.Split(u.UserRole, ",")
|
||||
for _, a := range arrs {
|
||||
if cast.ToInt(a) == StaffUserRoleHr || cast.ToInt(a) == StaffUserRoleAdmin {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -73,15 +73,15 @@ func (c *Base) Before(ctx *gin.Context) {
|
|||
if time.Now().Unix() > tk.ExpireTime {
|
||||
panic(config.ErrTokenExpire.New())
|
||||
}
|
||||
staffUser, err := dao.NewStaffUserDao().Get(tk.UserId)
|
||||
corpUser, err := dao.NewCorpUserDao().Get(tk.UserId)
|
||||
if err != nil {
|
||||
panic(config.ErrDb.New().Append(err))
|
||||
}
|
||||
if staffUser == nil {
|
||||
if corpUser == nil {
|
||||
panic(config.ErrTokenInvaild.New())
|
||||
}
|
||||
|
||||
ctx.Keys[session.ContextSession] = session.NewAdminSession(&header, staffUser)
|
||||
ctx.Keys[session.ContextSession] = session.NewAdminSession(&header, corpUser)
|
||||
}
|
||||
|
||||
func (c *Base) Token(ctx *gin.Context) {
|
||||
|
|
|
@ -23,10 +23,10 @@ type AdminHeader struct {
|
|||
|
||||
type AdminSession struct {
|
||||
adminHeader *AdminHeader
|
||||
adminUser *model.StaffUser
|
||||
adminUser *model.CorpUser
|
||||
}
|
||||
|
||||
func NewAdminSession(header *AdminHeader, user *model.StaffUser) *AdminSession {
|
||||
func NewAdminSession(header *AdminHeader, user *model.CorpUser) *AdminSession {
|
||||
return &AdminSession{
|
||||
adminHeader: header,
|
||||
adminUser: user,
|
||||
|
@ -37,7 +37,7 @@ func (s *AdminSession) GetHeader() *AdminHeader {
|
|||
return s.adminHeader
|
||||
}
|
||||
|
||||
func (s *AdminSession) GetAdmin() *model.StaffUser {
|
||||
func (s *AdminSession) GetAdmin() *model.CorpUser {
|
||||
return s.adminUser
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue