Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
539ef76d
authored
Dec 07, 2022
by
宁成龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复员工权限
parent
64f62566
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
26 deletions
app/Admin/Forms/User/AssignUserHandle.php
app/Admin/Forms/User/TransferUserHandle.php
app/Admin/Service/PermService.php
app/Models/Cms/CmsUser.php
app/Admin/Forms/User/AssignUserHandle.php
View file @
539ef76d
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
App\Admin\Forms\User
;
namespace
App\Admin\Forms\User
;
use
App\Admin\Service\PermService
;
use
App\Admin\Service\UserService
;
use
App\Admin\Service\UserService
;
use
App\Models\Cms\CmsUser
;
use
App\Models\Cms\CmsUser
;
use
App\Models\Inquiry
;
use
App\Models\Inquiry
;
...
@@ -32,10 +33,41 @@ class AssignUserHandle extends Form implements LazyRenderable
...
@@ -32,10 +33,41 @@ class AssignUserHandle extends Form implements LazyRenderable
->
refresh
();
->
refresh
();
}
catch
(
\Throwable
$throwable
)
{
}
catch
(
\Throwable
$throwable
)
{
// var_dump((string)$throwable);
// var_dump((string)$throwable);
return
$this
->
response
()
->
error
(
trans
(
'admin.update_failed'
)
.
":
{
$throwable
->
getMessage
()
}
"
);
return
$this
->
response
()
->
error
(
trans
(
'admin.update_failed'
)
.
":
{
$throwable
->
getMessage
()
}
"
);
}
}
}
}
public
function
getCmsUserList
()
{
$where
=
[];
$where
[]
=
[
function
(
$query
)
{
$adminUser
=
"userId"
;
$nowSaleId
=
getAdminUserId
();
$role
=
PermService
::
getUserRoles
(
$nowSaleId
);
if
(
$nowSaleId
==
1000
)
{
return
$query
;
}
if
(
$role
[
0
]
==
PermService
::
ROLE_SALE_DIRECTOR
)
{
//销售总监查看同部门
$userIds
=
PermService
::
getSubUserId
(
$nowSaleId
);
if
(
!
empty
(
$userIds
))
{
return
$query
->
whereIn
(
$adminUser
,
$userIds
);
}
}
elseif
(
$role
[
0
]
==
PermService
::
ROLE_SALE_LEADER
)
{
//销售经理查看同组
//查看同组
$user_info
=
CmsUser
::
getInfoByUserId
(
$nowSaleId
);
if
(
empty
(
$user_info
)
||
!
$user_info
[
'department_id'
])
{
return
$query
->
where
(
$adminUser
,
$nowSaleId
);
}
// 获取同组部门的人员
$sub_user_ids
=
CmsUser
::
getUserIdsByDepartmentIds
([
$user_info
[
'department_id'
]]);
return
$query
->
whereIn
(
$adminUser
,
$sub_user_ids
);
}
}
];
return
CmsUser
::
where
(
$where
)
->
pluck
(
'name'
,
'userId'
)
->
toArray
();
}
/**
/**
* Build a form here.
* Build a form here.
*/
*/
...
@@ -43,7 +75,7 @@ class AssignUserHandle extends Form implements LazyRenderable
...
@@ -43,7 +75,7 @@ class AssignUserHandle extends Form implements LazyRenderable
{
{
$this
->
disableResetButton
();
$this
->
disableResetButton
();
$this
->
hidden
(
'id'
)
->
attribute
(
'id'
,
'id'
);
$this
->
hidden
(
'id'
)
->
attribute
(
'id'
,
'id'
);
$this
->
select
(
'sale_id'
)
->
options
(
CmsUser
::
get
UserList
())
->
default
(
0
)
->
required
();
$this
->
select
(
'sale_id'
)
->
options
(
$this
->
getCms
UserList
())
->
default
(
0
)
->
required
();
}
}
/**
/**
...
...
app/Admin/Forms/User/TransferUserHandle.php
View file @
539ef76d
...
@@ -39,37 +39,31 @@ class TransferUserHandle extends Form implements LazyRenderable
...
@@ -39,37 +39,31 @@ class TransferUserHandle extends Form implements LazyRenderable
public
function
getCmsUserList
()
public
function
getCmsUserList
()
{
{
CmsUser
::
getUserList
();
$where
=
[];
$where
=
[];
$where
[]
=
[
$where
[]
=
[
function
(
$query
)
{
function
(
$query
)
{
$viewList
=
User
::
$ruleViewList
;
$adminUser
=
"userId"
;
$adminUser
=
"userId"
;
$nowSaleId
=
getAdminUserId
();
$nowSaleId
=
getAdminUserId
();
if
(
$nowSaleId
==
1000
)
{
$role
=
PermService
::
getUserRoles
(
$nowSaleId
);
if
(
$nowSaleId
==
1000
||
$role
[
0
]
==
PermService
::
ROLE_SALE_DIRECTOR
)
{
return
$query
;
return
$query
;
}
}
//查看所有
if
(
$role
[
0
]
==
PermService
::
ROLE_SALE_LEADER
)
{
//销售经理可以查看同部门
if
(
checkPerm
(
$viewList
[
0
]))
{
return
$query
;
}
//查看下级
if
(
checkPerm
(
$viewList
[
1
]))
{
//查看下级的权限//获取用户部门下的所有用户
$userIds
=
PermService
::
getSubUserId
(
$nowSaleId
);
$userIds
=
PermService
::
getSubUserId
(
$nowSaleId
);
if
(
!
empty
(
$userIds
))
{
if
(
!
empty
(
$userIds
))
{
return
$query
->
whereIn
(
$adminUser
,
$userIds
);
return
$query
->
whereIn
(
$adminUser
,
$userIds
);
}
}
}
}
elseif
(
$role
[
0
]
==
PermService
::
ROLE_SALE
)
{
//销售可以查看同组
//查看同组
//查看同组
$user_info
=
CmsUser
::
getInfoByUserId
(
$nowSaleId
);
$user_info
=
CmsUser
::
getInfoByUserId
(
$nowSaleId
);
if
(
empty
(
$user_info
)
||
!
$user_info
[
'department_id'
])
{
if
(
empty
(
$user_info
)
||
!
$user_info
[
'department_id'
])
{
return
$query
->
where
(
$adminUser
,
$nowSaleId
);
return
$query
->
where
(
$adminUser
,
$nowSaleId
);
}
}
// 获取下级
部门的人员
// 获取同组
部门的人员
$sub_user_ids
=
CmsUser
::
getUserIdsByDepartmentIds
([
$user_info
[
'department_id'
]]);
$sub_user_ids
=
CmsUser
::
getUserIdsByDepartmentIds
([
$user_info
[
'department_id'
]]);
return
$query
->
whereIn
(
$adminUser
,
$sub_user_ids
);
return
$query
->
whereIn
(
$adminUser
,
$sub_user_ids
);
}
}
}
];
];
return
CmsUser
::
where
(
$where
)
->
pluck
(
'name'
,
'userId'
)
->
toArray
();
return
CmsUser
::
where
(
$where
)
->
pluck
(
'name'
,
'userId'
)
->
toArray
();
}
}
...
...
app/Admin/Service/PermService.php
View file @
539ef76d
...
@@ -22,22 +22,14 @@ class PermService
...
@@ -22,22 +22,14 @@ class PermService
const
ROLE_ADMIN
=
1
;
// 管理员角色
const
ROLE_ADMIN
=
1
;
// 管理员角色
const
ROLE_
BUYER
=
2
;
// 采购员
const
ROLE_
SALE
=
200
;
// 普通销售
const
ROLE_
BUYER_LEADER
=
3
;
// 采购
经理
const
ROLE_
SALE_LEADER
=
201
;
// 销售
经理
const
ROLE_
BUYER_DIRECTOR
=
4
;
// 采购
总监
const
ROLE_
SALE_DIRECTOR
=
202
;
// 销售
总监
const
ROLE_NULL
=
0
;
// 未设置角色
const
ROLE_NULL
=
0
;
// 未设置角色
private
static
$role_name_map
=
[
"管理员"
=>
self
::
ROLE_ADMIN
,
"采购员"
=>
self
::
ROLE_BUYER
,
"采购经理"
=>
self
::
ROLE_BUYER_LEADER
,
"采购总监"
=>
self
::
ROLE_BUYER_DIRECTOR
];
// 获取当前用户角色
// 获取当前用户角色
public
static
function
getUserRoles
(
$uid
=
0
,
$email
=
""
)
public
static
function
getUserRoles
(
$uid
=
0
,
$email
=
""
)
{
{
...
...
app/Models/Cms/CmsUser.php
View file @
539ef76d
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
namespace
App\Models\Cms
;
namespace
App\Models\Cms
;
use
App\Admin\Service\PermService
;
use
App\Models\BaseModel
;
use
App\Models\BaseModel
;
use
App\Models\User
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
class
CmsUser
extends
BaseModel
class
CmsUser
extends
BaseModel
...
@@ -11,6 +13,14 @@ class CmsUser extends BaseModel
...
@@ -11,6 +13,14 @@ class CmsUser extends BaseModel
protected
$table
=
'user_info'
;
protected
$table
=
'user_info'
;
public
$timestamps
=
false
;
public
$timestamps
=
false
;
//查看权限
public
static
$ruleViewList
=
[
self
::
CMS_USER_VIEW_ALL
,
//查看所有
self
::
CMS_USER_VIEW_SUB
,
//查看下级
];
const
CMS_USER_VIEW_ALL
=
"cms_user_viewAllList"
;
//查看所有
const
CMS_USER_VIEW_SUB
=
"cms_user_viewSubList"
;
//查看下级
public
static
function
getInfoByUserId
(
$userId
)
public
static
function
getInfoByUserId
(
$userId
)
{
{
$res
=
self
::
where
(
'userId'
,
$userId
)
->
first
();
$res
=
self
::
where
(
'userId'
,
$userId
)
->
first
();
...
@@ -19,7 +29,7 @@ class CmsUser extends BaseModel
...
@@ -19,7 +29,7 @@ class CmsUser extends BaseModel
public
static
function
getUserList
()
public
static
function
getUserList
()
{
{
return
CmsUser
::
where
([])
->
rule
(
\App\Models\User
::
$ruleViewList
,
'userId'
)
->
pluck
(
'name'
,
'userId'
)
->
toArray
();
return
CmsUser
::
where
([])
->
rule
(
self
::
$ruleViewList
,
'userId'
)
->
pluck
(
'name'
,
'userId'
)
->
toArray
();
}
}
//根据部门id获取列表
//根据部门id获取列表
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment