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
4776b5f4
authored
Nov 15, 2022
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
冲突解决
parent
e298fda7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
49 deletions
.env
app/Http/Middleware/Permission.php
app/helpers.php
config/perm.php
.env
View file @
4776b5f4
...
...
@@ -57,7 +57,9 @@ START_IFRAME_TAB=true
LOGIN_DOMAIN=user.semourdev.net
PERM_URL=http://perm.semourdev.net/api/check
PERM_ID=12
PERM_LIST=http://perm.semourdev.net/api/perms
PERM_ID=61
PERM_GOURL=http://perm.semourdev.net
ADMIN_GROUP=1000,20000
MENU_ID=2
...
...
app/Http/Middleware/Permission.php
View file @
4776b5f4
...
...
@@ -37,6 +37,10 @@ class Permission
return
$this
->
view
(
'Auth'
,
'没有访问权限'
,
$permData
[
'go_url'
]);
}
$request
->
menus
=
$menus
;
//获取权限放到头
$perms
=
$this
->
getPerms
();
$request
->
perms
=
$perms
;
}
if
(
!
in_array
(
$user
->
userId
,
$permData
[
'admin_group'
])
&&
$action
!=
'Dashboard'
)
{
//不是超级管理员
$perm
=
$this
->
perm
(
$request
->
user
->
userId
,
$action
);
...
...
@@ -47,6 +51,9 @@ class Permission
return
$this
->
view
(
'Auth'
,
'没有访问权限'
,
$permData
[
'go_url'
]);
}
}
return
$next
(
$request
,
$action
);
}
...
...
@@ -129,16 +136,16 @@ class Permission
}
//检查权限,仅支持验证单个权限
function
perm
(
$userId
,
$perm
1
=
''
)
function
perm
(
$userId
,
$perm
=
''
)
{
$permArr
=
config
(
'perm.perm'
);
$
N
otAuth
=
$permArr
[
'notAuth'
];
$
n
otAuth
=
$permArr
[
'notAuth'
];
$AdminID
=
$permArr
[
'adminGroup'
];
if
((
!
in_array
(
$perm
1
,
$N
otAuth
))
&&
!
in_array
(
$userId
,
$AdminID
))
{
//过滤不用鉴权的方法与用户
if
((
!
in_array
(
$perm
,
$n
otAuth
))
&&
!
in_array
(
$userId
,
$AdminID
))
{
//过滤不用鉴权的方法与用户
$permID
=
$permArr
[
'id'
];
$url
=
$permArr
[
'url'
]
.
'/'
.
$userId
.
'/'
.
$permID
.
'?perms='
.
$perm
1
;
$url
=
$permArr
[
'url'
]
.
'/'
.
$userId
.
'/'
.
$permID
.
'?perms='
.
$perm
;
$result
=
json_decode
(
curl
(
$url
,
''
,
0
),
true
);
if
(
!
isset
(
$result
[
'retcode'
])
||
$result
[
'retcode'
]
!==
0
||
$result
[
'data'
][
'perms'
][
$perm
1
]
==
false
)
{
if
(
!
isset
(
$result
[
'retcode'
])
||
$result
[
'retcode'
]
!==
0
||
$result
[
'data'
][
'perms'
][
$perm
]
==
false
)
{
return
false
;
}
else
{
return
true
;
...
...
@@ -147,4 +154,16 @@ class Permission
return
true
;
}
}
public
function
getPerms
()
{
$userId
=
request
()
->
user
->
userId
;
$permsUrl
=
config
(
'perm.perm.list'
)
.
'/'
.
$userId
.
'/'
.
config
(
'perm.perm.id'
)
.
'/'
;
$permsResult
=
json_decode
(
curl
(
$permsUrl
),
true
);
$perms
=
[];
if
(
isset
(
$permsResult
[
'retcode'
])
&&
$permsResult
[
'retcode'
]
===
0
)
{
$perms
=
$permsResult
[
'data'
][
'perms'
];
}
return
$perms
;
}
}
app/helpers.php
View file @
4776b5f4
...
...
@@ -2,18 +2,17 @@
use
Illuminate\Support\Arr
;
define
(
"DIGITS_TWO"
,
2
);
define
(
"DIGITS_FOUR"
,
4
);
define
(
"DIGITS_SIX"
,
6
);
define
(
"DIGITS_TWO"
,
2
);
define
(
"DIGITS_FOUR"
,
4
);
define
(
"DIGITS_SIX"
,
6
);
if
(
!
function_exists
(
'user_admin_config'
))
{
if
(
!
function_exists
(
'user_admin_config'
))
{
function
user_admin_config
(
$key
=
null
,
$value
=
null
)
{
$session
=
session
();
if
(
!
$config
=
$session
->
get
(
'admin.config'
))
{
if
(
!
$config
=
$session
->
get
(
'admin.config'
))
{
$config
=
config
(
'admin'
);
$config
[
'lang'
]
=
config
(
'app.locale'
);
}
...
...
@@ -22,9 +21,7 @@ if (! function_exists('user_admin_config')) {
foreach
(
$key
as
$k
=>
$v
)
{
Arr
::
set
(
$config
,
$k
,
$v
);
}
$session
->
put
(
'admin.config'
,
$config
);
return
;
}
...
...
@@ -90,23 +87,24 @@ function curl($url, $params = false, $ispost = 0, $https = 0, $cookie = '', $tim
* @$thousandsSymbol 千分位字符串隔开 1,200,3.4567
*
* define("DIGITS_TWO",2);
define("DIGITS_FOUR",4);
define("DIGITS_SIX",6);
*
define("DIGITS_FOUR",4);
*
define("DIGITS_SIX",6);
*/
if
(
!
function_exists
(
'decimal_number_format'
))
{
function
decimal_number_format
(
$amount
,
$digits
=
DIGITS_TWO
,
$currency
=
""
,
$thousandsSymbol
=
""
){
function
decimal_number_format
(
$amount
,
$digits
=
DIGITS_TWO
,
$currency
=
""
,
$thousandsSymbol
=
""
)
{
$amount
=
floatval
(
strval
(
$amount
));
//格式化币别
if
(
$currency
)
{
if
(
$currency
)
{
$minus
=
$amount
<
0
?
'-'
:
''
;
$numerical
=
number_format
(
abs
(
$amount
),
$digits
,
"."
,
$thousandsSymbol
);
$sign
=
Arr
::
get
(
config
(
"field.currency_sign"
),
intval
(
$currency
),
""
);
$numerical
=
number_format
(
abs
(
$amount
),
$digits
,
"."
,
$thousandsSymbol
);
$sign
=
\Arr
::
get
(
config
(
"field.currency_sign"
),
intval
(
$currency
),
""
);
if
(
!
empty
(
$sign
))
{
$numerical
=
$sign
.
$numerical
;
}
return
$minus
?
$minus
.
$numerical
:
$numerical
;
}
else
{
$numerical
=
number_format
(
$amount
,
$digits
,
"."
,
""
);
return
$minus
?
$minus
.
$numerical
:
$numerical
;
}
else
{
$numerical
=
number_format
(
$amount
,
$digits
,
"."
,
""
);
return
$numerical
;
}
}
...
...
@@ -125,7 +123,8 @@ if (!function_exists('drawLetter')) {
* 格式化型号, echo DrawLetter("LMGAGA 质量 &&*****") 输出:LMGAGA
* @param $g string 关键词
*/
function
drawLetter
(
$g
){
function
drawLetter
(
$g
)
{
$g
=
preg_replace
(
'/[\x{4e00}-\x{9fff}]+/u'
,
''
,
$g
);
$g
=
preg_replace
(
'/[^A-Za-z0-9]+/'
,
''
,
$g
);
return
strtoupper
(
$g
);
...
...
@@ -149,17 +148,19 @@ if (!function_exists('buildQuery')) {
}
else
{
$query
->
where
(
$subWhere
[
0
],
$subWhere
[
1
]);
}
}
else
if
(
count
(
$subWhere
)
==
3
)
{
$fiels
=
$subWhere
[
0
]
??
""
;
$exp
=
$subWhere
[
1
]
??
null
;
$value
=
$subWhere
[
2
]
??
null
;
if
(
empty
(
$fiels
)
||
$exp
===
null
||
$value
===
null
)
{
continue
;
}
if
(
$exp
==
"in"
&&
is_array
(
$value
)
&&
!
empty
(
$value
))
{
$query
->
whereIn
(
$fiels
,
$value
);
}
else
{
$query
->
where
(
$fiels
,
$exp
,
$value
);
}
else
{
if
(
count
(
$subWhere
)
==
3
)
{
$fiels
=
$subWhere
[
0
]
??
""
;
$exp
=
$subWhere
[
1
]
??
null
;
$value
=
$subWhere
[
2
]
??
null
;
if
(
empty
(
$fiels
)
||
$exp
===
null
||
$value
===
null
)
{
continue
;
}
if
(
$exp
==
"in"
&&
is_array
(
$value
)
&&
!
empty
(
$value
))
{
$query
->
whereIn
(
$fiels
,
$value
);
}
else
{
$query
->
where
(
$fiels
,
$exp
,
$value
);
}
}
}
}
...
...
@@ -168,8 +169,9 @@ if (!function_exists('buildQuery')) {
}
if
(
!
function_exists
(
'echoToSql'
))
{
function
echoToSql
(
$query
){
$tmp
=
str_replace
(
'?'
,
'"'
.
'%s'
.
'"'
,
$query
->
toSql
());
function
echoToSql
(
$query
)
{
$tmp
=
str_replace
(
'?'
,
'"'
.
'%s'
.
'"'
,
$query
->
toSql
());
$tmp
=
vsprintf
(
$tmp
,
$query
->
getBindings
());
dd
(
$tmp
);
}
...
...
@@ -184,9 +186,10 @@ if (!function_exists('echoToSql')) {
* @param $val
* @return array
*/
function
flipArrayPluck
(
$arr
,
$newKey
,
$seachKey
){
function
flipArrayPluck
(
$arr
,
$newKey
,
$seachKey
)
{
$newArr
=
[];
foreach
(
$arr
as
$v
)
{
foreach
(
$arr
as
$v
)
{
$newArr
[
$v
[
$newKey
]][]
=
$v
[
$seachKey
];
}
return
$newArr
;
...
...
@@ -194,16 +197,17 @@ function flipArrayPluck($arr,$newKey,$seachKey){
if
(
!
function_exists
(
'checkArrayValuesNotEmpty'
))
{
function
checkArrayValuesNotEmpty
(
$arr
=
[]){
function
checkArrayValuesNotEmpty
(
$arr
=
[])
{
$result
=
true
;
if
(
is_array
(
$arr
))
{
foreach
(
$arr
as
$val
)
{
if
(
empty
(
$val
))
{
if
(
is_array
(
$arr
))
{
foreach
(
$arr
as
$val
)
{
if
(
empty
(
$val
))
{
$result
=
false
;
break
;
}
}
}
else
{
}
else
{
$result
=
false
;
}
return
$result
;
...
...
@@ -379,12 +383,12 @@ function price_format($price, $sign = 0, $num = 2, $sep = '')
$minus
=
$price
<
0
?
'-'
:
''
;
$price
=
floatval
(
strval
(
$price
));
$price
=
number_format
(
abs
(
$price
),
$num
,
'.'
,
$sep
);
$sign
=
\Arr
::
get
(
config
(
"field.currency_sign"
),
intval
(
$sign
),
""
);
$sign
=
\Arr
::
get
(
config
(
"field.currency_sign"
),
intval
(
$sign
),
""
);
if
(
!
empty
(
$sign
))
{
$price
=
$sign
.
$price
;
}
if
(
$minus
)
{
return
$minus
.
$price
;
if
(
$minus
)
{
return
$minus
.
$price
;
}
return
$price
;
}
...
...
@@ -417,4 +421,4 @@ function buildQueryTimeRange($time = "")
$buildTimeQueryData
[
"begin_time"
]
=
isset
(
$time
[
0
])
?
$time
[
0
]
:
""
;
$buildTimeQueryData
[
"end_time"
]
=
isset
(
$time
[
1
])
?
$time
[
1
]
:
""
;
return
$buildTimeQueryData
;
}
\ No newline at end of file
}
config/perm.php
View file @
4776b5f4
...
...
@@ -3,6 +3,7 @@ return [
'perm'
=>
[
'id'
=>
env
(
'PERM_ID'
),
'url'
=>
env
(
'PERM_URL'
),
'list'
=>
env
(
'PERM_LIST'
),
'go_url'
=>
env
(
'PERM_GOURL'
),
'admin_group'
=>
explode
(
','
,
env
(
'ADMIN_GROUP'
)),
//管理员权限组,有所有权限
'menu_id'
=>
env
(
'MENU_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