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
af4f0de5
Commit
af4f0de5
authored
Aug 13, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/log-operation' into 'master'
Feature/log operation See merge request
!365
parents
9562d71c
4bd37ac6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
+91
-0
OperationLogInterceptor.php
common/behaviors/OperationLogInterceptor.php
+91
-0
No files found.
common/behaviors/OperationLogInterceptor.php
0 → 100644
View file @
af4f0de5
<?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
(
'login'
==
$handlerAction
)
{
return
true
;
}
// if (!isset(Yii::$app->params['handleTableAndDesc']['handleTableAndDesc'][$handerClass][$handlerAction][$method])) {
// return false;
// }
if
(
'asset'
==
$handerClass
)
{
$uri
=
Yii
::
$app
->
request
->
post
(
'uri'
,
''
);
$params
=
[
'ip'
=>
Yii
::
$app
->
request
->
userIP
,
'operation'
=>
'操作'
,
'business'
=>
Yii
::
$app
->
params
[
'handleTableAndDesc'
][
'handleTableAndDesc'
][
$handerClass
][
$handlerAction
][
$uri
]
??
Yii
::
$app
->
params
[
'handleTableAndDesc'
][
'handleTableAndDesc'
][
$handerClass
][
$handlerAction
][
$uri
]
.
'-'
.
$uri
,
'table'
=>
'asset'
];
}
else
{
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
(
Yii
::
$app
->
params
[
'go_biqianbao'
]
.
'/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