Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
wallet
token
Commits
60e43541
Commit
60e43541
authored
Jun 23, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log operation
parent
b87f07cd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
0 deletions
+79
-0
OperationLogInterceptor.php
common/behaviors/OperationLogInterceptor.php
+79
-0
No files found.
common/behaviors/OperationLogInterceptor.php
0 → 100644
View file @
60e43541
<?php
namespace
common\behaviors
;
use
Yii
;
use
linslin\yii2\curl\Curl
;
use
yii\base\ActionFilter
;
use
wallet\base\ResponseMsg
;
class
OperationLogInterceptor
extends
ActionFilter
{
public
function
beforeAction
(
$action
)
{
if
(
!
parent
::
beforeAction
(
$action
))
{
return
false
;
}
$method
=
strtolower
(
Yii
::
$app
->
request
->
method
);
$handerClass
=
strtolower
(
Yii
::
$app
->
controller
->
id
);
$handlerAction
=
strtolower
(
Yii
::
$app
->
controller
->
action
->
id
);
// if (!isset(Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction][$method])) {
// return false;
// }
switch
(
$method
)
{
case
"get"
:
$operation
=
'查询'
;
break
;
case
'post'
:
$operation
=
'增加'
;
break
;
case
'put'
:
$operation
=
'更新'
;
break
;
case
'delete'
:
$operation
=
'删除'
;
break
;
default
:
$operation
=
'未知'
;
}
$params
=
[
'ip'
=>
Yii
::
$app
->
request
->
userIP
,
'operation'
=>
$operation
,
'business'
=>
Yii
::
$app
->
params
[
'handleTableAndDesc'
][
'handleTableAndDesc'
][
$handerClass
][
$handlerAction
][
$method
]
??
$handerClass
.
'-'
.
$handlerAction
,
'table'
=>
Yii
::
$app
->
params
[
'handleTableAndDesc'
][
'handleTableAndDesc'
][
$handerClass
][
$handlerAction
][
'table'
]
??
'未知'
];
$token_string
=
Yii
::
$app
->
request
->
headers
->
get
(
'Token'
);
$curl
=
new
Curl
();
$response
=
$curl
->
setRequestBody
(
json_encode
(
$params
))
->
setHeaders
([
'Content-Type'
=>
'application/json'
,
'Token'
=>
$token_string
])
->
post
(
'http://127.0.0.1:8983/api/log'
);
$response
=
json_decode
(
$response
,
true
);
if
(
!
is_array
(
$response
)
||
0
!=
$response
[
'code'
])
{
$msg
=
'同步日志错误'
;
$code
=
-
1
;
goto
doEnd
;
}
return
true
;
doEnd
:
// 返回错误
$response_message
=
new
ResponseMsg
();
$content
=
$response_message
->
jsonError
(
$msg
,
$code
);
$content
=
$response_message
->
withHeaders
(
$response_message
->
getHeaders
())
->
withContent
(
$content
);
Yii
::
$app
->
response
->
data
=
$content
;
Yii
::
$app
->
response
->
send
();
return
false
;
}
}
\ No newline at end of file
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