116 lines
3.5 KiB
PHP
116 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Repository;
|
|
use think\Request;
|
|
/**
|
|
* 操作日志服务
|
|
* Class LogRepositories
|
|
* @package repositories
|
|
*/
|
|
class LogRepository
|
|
{
|
|
|
|
/**
|
|
* 写入操作日志
|
|
* @param string $action
|
|
* @param string $content
|
|
* @return bool
|
|
*/
|
|
public static function write($action = '行为', $content = "内容描述")
|
|
{
|
|
$request = Request::instance();
|
|
$node = strtolower(join('/', [$request->module(), $request->controller(), $request->action()]));
|
|
$data = [
|
|
'ip' => $request->ip(),
|
|
'node' => $node,
|
|
'action' => $action,
|
|
'content' => $content,
|
|
'user_name' => session('user_name') . '',
|
|
];
|
|
return db('system_log')->insert($data) !== false;
|
|
}
|
|
|
|
/**
|
|
* 支付账号操作日志记录
|
|
*/
|
|
public static function paymentLogWrite($actionData)
|
|
{
|
|
$data = [
|
|
'pay_account' => $actionData['pay_account'],
|
|
'history_qrcode' => $actionData['history_qrcode'],
|
|
'new_qrcode' => $actionData['new_qrcode'],
|
|
'history_kf' => $actionData['history_kf'],
|
|
'new_kf' => $actionData['new_kf'],
|
|
'action_type' => $actionData['action_type'],
|
|
'action_user' => session('user_name') . '',
|
|
];
|
|
return db('payment_action_log')->insert($data) !== false;
|
|
}
|
|
|
|
/**
|
|
* 客服操作日志记录
|
|
*/
|
|
public static function userLogWrite($action = '行为', $content = "内容描述")
|
|
{
|
|
$request = Request::instance();
|
|
$node = strtolower(join('/', [$request->module(), $request->controller(), $request->action()]));
|
|
$data = [
|
|
'ip' => $request->ip(),
|
|
'node' => $node,
|
|
'action' => $action,
|
|
'content' => $content,
|
|
'kf_id' => session('l_user_id'),
|
|
'user_name' => session('l_user_name'),
|
|
];
|
|
return db('user_action_log')->insert($data) !== false;
|
|
}
|
|
|
|
/**
|
|
* api日志记录
|
|
*/
|
|
public static function apiLogWrite($action = '行为', $content = "内容描述")
|
|
{
|
|
$request = Request::instance();
|
|
$node = strtolower(join('/', [$request->module(), $request->controller(), $request->action()]));
|
|
$data = [
|
|
'ip' => $request->ip(),
|
|
'node' => $node,
|
|
'action' => $action,
|
|
'content' => $content,
|
|
];
|
|
return db('api_log')->insert($data) !== false;
|
|
}
|
|
|
|
/**
|
|
* 请求访问记录
|
|
*/
|
|
public static function requestLog()
|
|
{
|
|
$request = Request::instance();
|
|
$data['node'] = strtolower(join('/', [$request->module(), $request->controller(), $request->action()]));
|
|
$param = array(
|
|
'headers'=> self::getallheaders(),
|
|
'get' =>$_GET,
|
|
'post' =>$_POST,
|
|
);
|
|
$data['param'] = json_encode($param);
|
|
$data['ip'] = $request->ip();
|
|
$data['add_time'] = date('Y-m-d H:i:s');
|
|
trace($data,'info');
|
|
}
|
|
|
|
/**
|
|
* 获取请求头部信息
|
|
* @return array
|
|
*/
|
|
public static function getallheaders() {
|
|
$headers = [];
|
|
foreach ($_SERVER as $name => $value) {
|
|
if (substr($name, 0, 5) == 'HTTP_') {
|
|
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
|
}
|
|
}
|
|
return $headers;
|
|
}
|
|
|
|
} |