Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
47dd5d0e
Commit
47dd5d0e
authored
Apr 09, 2019
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
权限缓存
parent
9f9d6df6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
19 deletions
+133
-19
RedisCacheService.php
application/api_broker/service/RedisCacheService.php
+57
-6
VipService.php
application/api_broker/service/VipService.php
+47
-9
Auth.php
application/index/controller/Auth.php
+29
-4
No files found.
application/api_broker/service/RedisCacheService.php
View file @
47dd5d0e
...
@@ -30,10 +30,12 @@ class RedisCacheService
...
@@ -30,10 +30,12 @@ class RedisCacheService
public
function
__construct
()
public
function
__construct
()
{
{
$this
->
redis_ext
=
RedisExt
::
getRedis
();
$this
->
redis_ext
=
RedisExt
::
getRedis
();
$this
->
time
=
604800
;
//7
天
$this
->
time
=
172800
;
//2
天
}
}
/**
/**
* 设置缓存
*
* @param $key
* @param $key
* @param $value
* @param $value
* @param int $time
* @param int $time
...
@@ -42,7 +44,6 @@ class RedisCacheService
...
@@ -42,7 +44,6 @@ class RedisCacheService
public
function
setRedisCache
(
$key
,
$value
,
$time
=
0
)
public
function
setRedisCache
(
$key
,
$value
,
$time
=
0
)
{
{
$value
=
json_encode
(
$value
);
$value
=
json_encode
(
$value
);
$key
=
$this
->
key_string
.
$key
;
if
(
!
$time
)
{
if
(
!
$time
)
{
$time
=
$this
->
time
;
$time
=
$this
->
time
;
}
}
...
@@ -50,6 +51,8 @@ class RedisCacheService
...
@@ -50,6 +51,8 @@ class RedisCacheService
}
}
/**
/**
* 获取缓存
*
* @param $key
* @param $key
* @return mixed
* @return mixed
*/
*/
...
@@ -65,6 +68,8 @@ class RedisCacheService
...
@@ -65,6 +68,8 @@ class RedisCacheService
}
}
/**
/**
* 设置缓存
*
* @param $key
* @param $key
* @param $value
* @param $value
* @return bool
* @return bool
...
@@ -78,6 +83,7 @@ class RedisCacheService
...
@@ -78,6 +83,7 @@ class RedisCacheService
}
}
/**
/**
* 设置hash缓存
* @param $key
* @param $key
* @param $value
* @param $value
* @param int $time
* @param int $time
...
@@ -92,6 +98,33 @@ class RedisCacheService
...
@@ -92,6 +98,33 @@ class RedisCacheService
return
$this
->
redis_ext
->
set
(
$key
,
$value
,
$time
);
return
$this
->
redis_ext
->
set
(
$key
,
$value
,
$time
);
}
}
/**
* 删除缓存
*
* @param $type
* @param $id
* @return bool
*/
public
function
delRedisCache
(
$type
,
$id
)
{
$result
=
0
;
switch
(
$type
)
{
case
1
:
$result
=
$this
->
redis_ext
->
del
(
$this
->
user_key
.
$id
);
break
;
case
2
:
$result
=
$this
->
redis_ext
->
del
(
$this
->
agent_key
.
$id
);
break
;
case
3
:
$result
=
$this
->
redis_ext
->
del
(
$this
->
group_key
.
$id
);
break
;
case
4
:
$result
=
$this
->
redis_ext
->
del
(
$this
->
rule_key
.
$id
);
}
return
$result
;
}
/**
/**
* 缓存用户信息
* 缓存用户信息
*
*
...
@@ -149,6 +182,15 @@ class RedisCacheService
...
@@ -149,6 +182,15 @@ class RedisCacheService
return
$data
;
return
$data
;
}
}
/**
* 缓存角色
*
* @param $group_id
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
groupCache
(
$group_id
)
public
function
groupCache
(
$group_id
)
{
{
$m_auth_group
=
new
AuthGroup
();
$m_auth_group
=
new
AuthGroup
();
...
@@ -160,19 +202,28 @@ class RedisCacheService
...
@@ -160,19 +202,28 @@ class RedisCacheService
return
$data
;
return
$data
;
}
}
public
function
authCache
(
$rule_id
)
/**
* 根据规则名缓存角色权限规则
*
* @param $name
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
authCache
(
$name
)
{
{
$m_auth_rule
=
new
AuthRule
();
$m_auth_rule
=
new
AuthRule
();
$field
=
'id,name,title,pid,is_menu'
;
$field
=
'id,name,title,pid,is_menu'
;
$data
=
$m_auth_rule
->
getRule
(
$field
,
[
'
id'
=>
$rule_id
,
'status'
=>
0
]);
$data
=
$m_auth_rule
->
getRule
(
$field
,
[
'
name'
=>
$name
,
'status'
=>
0
]);
if
(
!
empty
(
$data
))
{
if
(
!
empty
(
$data
))
{
$this
->
setRedisCache
(
$this
->
rule_key
.
$
rule_id
,
$data
[
0
]);
$this
->
setRedisCache
(
$this
->
rule_key
.
$
name
,
$data
[
0
]);
}
}
return
$data
;
return
$data
;
}
}
/**
/**
* @param $type 1:客户 2:经纪人 3:角色组 4:权限
* @param $type 1:客户 2:经纪人 3:角色组 4:权限
规则
* @param $id
* @param $id
* @return array|bool|false|mixed|\PDOStatement|string|\think\Model
* @return array|bool|false|mixed|\PDOStatement|string|\think\Model
*/
*/
...
...
application/api_broker/service/VipService.php
View file @
47dd5d0e
...
@@ -18,11 +18,13 @@ class VipService
...
@@ -18,11 +18,13 @@ class VipService
private
$agentModel
;
private
$agentModel
;
private
$groupModel
;
private
$groupModel
;
private
$rulesModel
;
private
$rulesModel
;
private
$redisCache
;
public
function
__construct
()
public
function
__construct
()
{
{
$this
->
agentModel
=
new
AAgents
();
$this
->
agentModel
=
new
AAgents
();
$this
->
groupModel
=
new
AuthGroup
();
$this
->
groupModel
=
new
AuthGroup
();
$this
->
rulesModel
=
new
AuthRule
();
$this
->
rulesModel
=
new
AuthRule
();
$this
->
redisCache
=
new
RedisCacheService
();
}
}
/**
/**
...
@@ -39,13 +41,31 @@ class VipService
...
@@ -39,13 +41,31 @@ class VipService
return
0
;
return
0
;
}
}
$fields
=
'auth_group_id'
;
$agent_data
=
$this
->
redisCache
->
getRedisCache
(
2
,
$id
);
$auth_group_id
=
$this
->
agentModel
->
getAgentsById
(
$id
,
$fields
);
$fields
=
'rules'
;
if
(
empty
(
$agent_data
[
'auth_group_id'
]))
{
$rules
=
$this
->
groupModel
->
getAuthGroupById
(
$auth_group_id
,
$fields
);
$fields
=
'auth_group_id'
;
$auth_group_id
=
$this
->
agentModel
->
getAgentsById
(
$id
,
$fields
);
}
else
{
$auth_group_id
=
$agent_data
[
'auth_group_id'
];
}
$group_data
=
$this
->
redisCache
->
getRedisCache
(
3
,
$auth_group_id
);
if
(
empty
(
$group_data
))
{
$fields
=
'rules'
;
$rules
=
$this
->
groupModel
->
getAuthGroupById
(
$auth_group_id
,
$fields
);
}
else
{
$rules
=
$group_data
[
'rules'
];
}
$rule_data
=
$this
->
redisCache
->
getRedisCache
(
4
,
$name
);
if
(
empty
(
$auth_group_id
))
{
$fields
=
'id'
;
$auth_rule_id
=
$this
->
rulesModel
->
getAuthRuleByName
(
$name
,
$fields
);
}
else
{
$auth_rule_id
=
$rule_data
[
'id'
];
}
$fields
=
'id'
;
$auth_rule_id
=
$this
->
rulesModel
->
getAuthRuleByName
(
$name
,
$fields
);
$rules_arr
=
explode
(
','
,
$rules
);
$rules_arr
=
explode
(
','
,
$rules
);
if
(
in_array
(
$auth_rule_id
,
$rules_arr
))
{
if
(
in_array
(
$auth_rule_id
,
$rules_arr
))
{
...
@@ -91,9 +111,27 @@ class VipService
...
@@ -91,9 +111,27 @@ class VipService
}
}
try
{
try
{
$auth_group_id
=
$this
->
agentModel
->
getAgentsById
(
$id
,
'auth_group_id'
);
$agent_data
=
$this
->
redisCache
->
getRedisCache
(
2
,
$id
);
$rules
=
$this
->
groupModel
->
getAuthGroupById
(
$auth_group_id
,
'rules'
);
if
(
empty
(
$agent_data
[
'auth_group_id'
]))
{
$auth_rule_id
=
$this
->
rulesModel
->
getAuthRuleByName
(
$name
,
'id'
);
$auth_group_id
=
$this
->
agentModel
->
getAgentsById
(
$id
,
'auth_group_id'
);
}
else
{
$auth_group_id
=
$agent_data
[
'auth_group_id'
];
}
$group_data
=
$this
->
redisCache
->
getRedisCache
(
3
,
$auth_group_id
);
if
(
empty
(
$group_data
))
{
$rules
=
$this
->
groupModel
->
getAuthGroupById
(
$auth_group_id
,
'rules'
);
}
else
{
$rules
=
$group_data
[
'rules'
];
}
$rule_data
=
$this
->
redisCache
->
getRedisCache
(
4
,
$name
);
if
(
empty
(
$auth_group_id
))
{
$auth_rule_id
=
$this
->
rulesModel
->
getAuthRuleByName
(
$name
,
'id'
);
}
else
{
$auth_rule_id
=
$rule_data
[
'id'
];
}
}
catch
(
Exception
$e
)
{
}
catch
(
Exception
$e
)
{
return
-
1
;
return
-
1
;
}
}
...
...
application/index/controller/Auth.php
View file @
47dd5d0e
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
app\index\controller
;
namespace
app\index\controller
;
use
app\api_broker\service\RedisCacheService
;
use
app\index\extend\Basic
;
use
app\index\extend\Basic
;
use
app\index\service\BrokerService
;
use
app\index\service\BrokerService
;
use
app\model\AuthGroup
;
use
app\model\AuthGroup
;
...
@@ -269,6 +270,8 @@ class Auth extends Basic
...
@@ -269,6 +270,8 @@ class Auth extends Basic
}
}
if
(
$auth
->
saveStatus
(
'rules'
,
$this
->
params
[
'rules'
],
$this
->
params
[
'id'
]))
{
if
(
$auth
->
saveStatus
(
'rules'
,
$this
->
params
[
'rules'
],
$this
->
params
[
'id'
]))
{
$redis_service
=
new
RedisCacheService
();
$redis_service
->
groupCache
(
$this
->
params
[
'id'
]);
return
$this
->
response
(
200
,
'成功'
);
return
$this
->
response
(
200
,
'成功'
);
}
else
{
}
else
{
return
$this
->
response
(
100
,
'失败'
);
return
$this
->
response
(
100
,
'失败'
);
...
@@ -279,12 +282,23 @@ class Auth extends Basic
...
@@ -279,12 +282,23 @@ class Auth extends Basic
* 设置权限状态
* 设置权限状态
*/
*/
public
function
updateRoleStatus
(){
public
function
updateRoleStatus
(){
$table
=
New
AuthRule
;
$table
=
new
AuthRule
;
$data
=
$this
->
request
->
param
();
$data
=
$this
->
request
->
param
();
$ids
=
trim
(
$data
[
'ids'
],
','
);
$rule_data
=
$table
->
getAuthRule
(
'id,name,status'
,
[
'id'
=>
$ids
]);
if
(
$rule_data
[
'status'
]
==
$data
[
'status'
])
{
return
$this
->
response
(
101
,
'无更新内容'
);
}
$ids
=
trim
(
$data
[
'ids'
],
','
);
if
(
$table
->
saveStatus
(
'status'
,
$data
[
'status'
],
$ids
)){
if
(
$table
->
saveStatus
(
'status'
,
$data
[
'status'
],
$ids
)){
$redis_service
=
new
RedisCacheService
();
if
(
$data
[
'status'
])
{
$redis_service
->
delRedisCache
(
4
,
$rule_data
[
'name'
]);
}
else
{
$redis_service
->
getRedisCache
(
4
,
$rule_data
[
'name'
]);
}
return
$this
->
response
(
200
,
'成功'
,
$data
);
return
$this
->
response
(
200
,
'成功'
,
$data
);
}
else
{
}
else
{
return
$this
->
response
(
100
,
'失败'
,
$data
);
return
$this
->
response
(
100
,
'失败'
,
$data
);
...
@@ -302,6 +316,14 @@ class Auth extends Basic
...
@@ -302,6 +316,14 @@ class Auth extends Basic
$ids
=
trim
(
$data
[
'ids'
],
','
);
$ids
=
trim
(
$data
[
'ids'
],
','
);
if
(
$table
->
saveStatus
(
'status'
,
$data
[
'status'
],
$ids
)){
if
(
$table
->
saveStatus
(
'status'
,
$data
[
'status'
],
$ids
)){
$redis_service
=
new
RedisCacheService
();
if
(
$data
[
'status'
])
{
$redis_service
->
delRedisCache
(
3
,
$ids
);
}
else
{
$redis_service
->
getRedisCache
(
3
,
$ids
);
}
return
$this
->
response
(
200
,
'成功'
,
$data
);
return
$this
->
response
(
200
,
'成功'
,
$data
);
}
else
{
}
else
{
return
$this
->
response
(
100
,
'失败'
,
$data
);
return
$this
->
response
(
100
,
'失败'
,
$data
);
...
@@ -395,6 +417,8 @@ class Auth extends Basic
...
@@ -395,6 +417,8 @@ class Auth extends Basic
$data
=
input
(
'post.'
);
$data
=
input
(
'post.'
);
$data
[
'name'
]
=
trim
(
$data
[
'name'
]);
$data
[
'title'
]
=
trim
(
$data
[
'title'
]);
if
(
$table
->
repetition
(
'name'
,
$data
[
'name'
])
&&
empty
(
$data
[
'id'
])){
if
(
$table
->
repetition
(
'name'
,
$data
[
'name'
])
&&
empty
(
$data
[
'id'
])){
return
$this
->
response
(
100
,
'url存在重复值'
);
return
$this
->
response
(
100
,
'url存在重复值'
);
}
}
...
@@ -413,8 +437,9 @@ class Auth extends Basic
...
@@ -413,8 +437,9 @@ class Auth extends Basic
//新增或者编辑数据
//新增或者编辑数据
//prt($data)
//prt($data)
if
(
$table
->
editData
(
$data
,
$id
))
{
if
(
$table
->
editData
(
$data
,
$id
))
{
$redis_service
=
new
RedisCacheService
();
$redis_service
->
getRedisCache
(
4
,
$data
[
'name'
]);
return
$this
->
response
(
200
,
'成功'
);
return
$this
->
response
(
200
,
'成功'
);
}
else
{
}
else
{
return
$this
->
response
(
100
,
'无修改'
);
return
$this
->
response
(
100
,
'无修改'
);
...
...
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