package model import ( "encoding/json" "github.com/spf13/cast" "strings" ) type CorpUser struct { Id int64 CorpId int64 Username string Password string Realname string Config string 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 }