Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zhupu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sugar
zhupu
Commits
2c057adc
Commit
2c057adc
authored
Nov 24, 2023
by
wuxiaoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
后台代理
parent
139037e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
1 deletion
+91
-1
application/admin/controller/auth/Admin.php
application/admin/controller/auth/Admin.php
+53
-0
application/admin/controller/user/Agent.php
application/admin/controller/user/Agent.php
+37
-0
application/api/controller/Users.php
application/api/controller/Users.php
+1
-1
No files found.
application/admin/controller/auth/Admin.php
View file @
2c057adc
...
...
@@ -294,4 +294,57 @@ class Admin extends Backend
$this
->
dataLimitField
=
'id'
;
return
parent
::
selectpage
();
}
public
function
addEditAdmin
(
$params
){
if
(
$params
)
{
Db
::
startTrans
();
try
{
if
(
$params
[
'action'
]
==
"add"
){
$params
[
'password'
]
=
"666666"
;
$params
[
'salt'
]
=
Random
::
alnum
();
$params
[
'password'
]
=
md5
(
md5
(
$params
[
'password'
])
.
$params
[
'salt'
]);
$params
[
'avatar'
]
=
'/assets/img/avatar.png'
;
//设置新管理员默认头像。
$group
[]
=
$params
[
"group"
];
unset
(
$params
[
'action'
]);
unset
(
$params
[
'group'
]);
$result
=
$this
->
model
->
validate
(
'Admin.add'
)
->
save
(
$params
);
if
(
$result
===
false
)
{
return
[
'code'
=>-
1
,
'msg'
=>
$this
->
model
->
getError
()];
}
//过滤不允许的组别,避免越权
$group
=
array_intersect
(
$this
->
childrenGroupIds
,
$group
);
if
(
!
$group
)
{
return
[
'code'
=>-
1
,
'msg'
=>
'The parent group exceeds permission limit'
];
}
$dataset
=
[];
foreach
(
$group
as
$value
)
{
$dataset
[]
=
[
'uid'
=>
$this
->
model
->
id
,
'group_id'
=>
$value
];
}
model
(
'AuthGroupAccess'
)
->
saveAll
(
$dataset
);
}
else
if
(
$params
[
'action'
]
==
"edit"
){
unset
(
$params
[
'action'
]);
$row
=
$this
->
model
->
where
([
'agent_user_id'
=>
$params
[
'agent_user_id'
]])
->
find
();
// 先移除所有权限
model
(
'AuthGroupAccess'
)
->
where
(
'uid'
,
$row
->
id
)
->
delete
();
$group
[]
=
$params
[
"group"
];
// 过滤不允许的组别,避免越权
$group
=
array_intersect
(
$this
->
childrenGroupIds
,
$group
);
if
(
!
$group
)
{
return
[
'code'
=>-
1
,
'msg'
=>
'The parent group exceeds permission limit'
];
}
$dataset
=
[];
foreach
(
$group
as
$value
)
{
$dataset
[]
=
[
'uid'
=>
$row
->
id
,
'group_id'
=>
$value
];
}
model
(
'AuthGroupAccess'
)
->
saveAll
(
$dataset
);
}
Db
::
commit
();
}
catch
(
\Exception
$e
)
{
Db
::
rollback
();
return
[
'code'
=>-
1
,
'msg'
=>
$e
->
getMessage
()];
}
return
[
'code'
=>
1
,
'msg'
=>
"添加成功"
];
}
}
}
application/admin/controller/user/Agent.php
View file @
2c057adc
...
...
@@ -2,6 +2,7 @@
namespace
app\admin\controller\user
;
use
app\admin\controller\auth\Admin
;
use
app\common\controller\Backend
;
use
think\Db
;
...
...
@@ -18,11 +19,13 @@ class Agent extends Backend
* @var \app\admin\model\user\Agent
*/
protected
$model
=
null
;
protected
$Adminmodel
=
null
;
public
function
_initialize
()
{
parent
::
_initialize
();
$this
->
model
=
new
\app\admin\model\user\Agent
;
$this
->
Adminmodel
=
new
\app\admin\model\Admin
;
$this
->
view
->
assign
(
"typeList"
,
$this
->
model
->
getTypeList
());
$this
->
view
->
assign
(
"statusList"
,
$this
->
model
->
getStatusList
());
}
...
...
@@ -116,6 +119,21 @@ class Agent extends Backend
unset
(
$params
[
'family_id'
]);
}
if
(
in_array
(
$params
[
'type'
],[
3
,
4
,
5
])){
$data
[
'username'
]
=
$params
[
'mobile'
];
$data
[
'nickname'
]
=
$params
[
'realname'
];
$data
[
'agent_user_id'
]
=
$params
[
'agent_user_id'
];
$data
[
'action'
]
=
"add"
;
$admininfo
=
$this
->
Adminmodel
->
where
([
'username'
=>
$data
[
'username'
]])
->
find
();
if
(
!
$admininfo
){
$admin
=
new
Admin
();
$res
=
$admin
->
addEditAdmin
(
$data
);
if
(
$res
[
'code'
]
==-
1
){
Db
::
rollback
();
$this
->
error
(
$res
[
'msg'
]);
}
}
}
$result
=
$this
->
model
->
allowField
(
true
)
->
save
(
$params
);
Db
::
commit
();
}
catch
(
ValidateException
$e
)
{
...
...
@@ -192,6 +210,25 @@ class Agent extends Backend
unset
(
$params
[
'family_id'
]);
}
if
(
in_array
(
$params
[
'type'
],[
3
,
4
,
5
])){
$data
[
'agent_user_id'
]
=
$params
[
'agent_user_id'
];
$admin
=
Db
::
name
(
"admin"
)
->
where
([
'agent_user_id'
=>
$params
[
'agent_user_id'
]])
->
find
();
if
(
$admin
){
$data
[
'action'
]
=
"edit"
;
$admin
=
new
Admin
();
$res
=
$admin
->
addEditAdmin
(
$data
);
}
else
{
$data
[
'username'
]
=
$params
[
'mobile'
];
$data
[
'nickname'
]
=
$params
[
'realname'
];
$data
[
'action'
]
=
"add"
;
$admin
=
new
Admin
();
$res
=
$admin
->
addEditAdmin
(
$data
);
}
if
(
$res
[
'code'
]
==-
1
){
Db
::
rollback
();
$this
->
error
(
$res
[
'msg'
]);
}
}
$result
=
$row
->
allowField
(
true
)
->
save
(
$params
);
Db
::
commit
();
}
catch
(
ValidateException
$e
)
{
...
...
application/api/controller/Users.php
View file @
2c057adc
...
...
@@ -241,7 +241,7 @@ class Users extends Api
private
function
checkAdminByPassword
(
$user_id
)
{
$admin
=
Admin
::
get
([
'user_id'
=>
$user_id
]);
$admin
=
Admin
::
get
([
'
agent_
user_id'
=>
$user_id
]);
if
(
!
$admin
)
{
return
false
;
}
...
...
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