corpconfig

This commit is contained in:
jiangyong 2025-06-16 16:33:33 +08:00
parent 19059f0874
commit 722647dc03
3 changed files with 52 additions and 6 deletions

View File

@ -1,5 +1,11 @@
package model package model
import (
"encoding/json"
"github.com/spf13/cast"
"strings"
)
type CorpUser struct { type CorpUser struct {
Id int64 Id int64
CorpId int64 CorpId int64
@ -10,3 +16,43 @@ type CorpUser struct {
CreateTime int64 CreateTime int64
UpdateTime 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
}

View File

@ -73,15 +73,15 @@ func (c *Base) Before(ctx *gin.Context) {
if time.Now().Unix() > tk.ExpireTime { if time.Now().Unix() > tk.ExpireTime {
panic(config.ErrTokenExpire.New()) panic(config.ErrTokenExpire.New())
} }
staffUser, err := dao.NewStaffUserDao().Get(tk.UserId) corpUser, err := dao.NewCorpUserDao().Get(tk.UserId)
if err != nil { if err != nil {
panic(config.ErrDb.New().Append(err)) panic(config.ErrDb.New().Append(err))
} }
if staffUser == nil { if corpUser == nil {
panic(config.ErrTokenInvaild.New()) 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) { func (c *Base) Token(ctx *gin.Context) {

View File

@ -23,10 +23,10 @@ type AdminHeader struct {
type AdminSession struct { type AdminSession struct {
adminHeader *AdminHeader 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{ return &AdminSession{
adminHeader: header, adminHeader: header,
adminUser: user, adminUser: user,
@ -37,7 +37,7 @@ func (s *AdminSession) GetHeader() *AdminHeader {
return s.adminHeader return s.adminHeader
} }
func (s *AdminSession) GetAdmin() *model.StaffUser { func (s *AdminSession) GetAdmin() *model.CorpUser {
return s.adminUser return s.adminUser
} }