Commit d2370688 by lzzzzl

增加日志功能

parent 7b38f176
......@@ -69,9 +69,10 @@ class AccessApiController extends Controller
/**
* 更新开始结束状态
*/
private function ApiUpdateStatus() {
private function ApiUpdateStatus($request) {
$data = (new SpiderModel())->updateStatus();
$user_id = $request->user->userId;
$data = (new SpiderModel())->updateStatus($user_id);
$this->Export($data);
}
......@@ -79,9 +80,10 @@ class AccessApiController extends Controller
/**
* 更新手动推送
*/
private function ApiUpdateManualPush() {
private function ApiUpdateManualPush($request) {
$data = (new DataManageModel())->updateManualPush();
$user_id = $request->user->userId;
$data = (new DataManageModel())->updateManualPush($user_id);
$this->Export($data);
}
......@@ -89,9 +91,10 @@ class AccessApiController extends Controller
/**
* 更新编辑内容
*/
private function ApiConfigContent() {
private function ApiConfigContent($request) {
$data = (new SpiderModel())->updateContent();
$user_id = $request->user->userId;
$data = (new SpiderModel())->updateContent($user_id);
$this->Export($data);
}
......@@ -99,9 +102,10 @@ class AccessApiController extends Controller
/**
* 插入新增内容
*/
private function ApiAddConfig() {
private function ApiAddConfig($request) {
$data = (new SpiderModel())->insertContent();
$user_id = $request->user->userId;
$data = (new SpiderModel())->insertContent($user_id);
$this->Export($data);
}
......@@ -109,9 +113,10 @@ class AccessApiController extends Controller
/**
* 更新节点信息
*/
private function ApiUpdateNode() {
private function ApiUpdateNode($request) {
$data = (new SpiderModel())->updateNode();
$user_id = $request->user->userId;
$data = (new SpiderModel())->updateNode($user_id);
$this->Export($data);
}
......@@ -119,9 +124,10 @@ class AccessApiController extends Controller
/**
* 更新所有节点信息
*/
private function ApiUpdateAllNode() {
private function ApiUpdateAllNode($request) {
$data = (new SpiderModel())->updateAllNode();
$user_id = $request->user->userId;
$data = (new SpiderModel())->updateAllNode($user_id);
$this->Export($data);
}
......@@ -129,11 +135,25 @@ class AccessApiController extends Controller
/**
* 更新所有面板状态
*/
private function ApiUpdateAllBoard() {
private function ApiUpdateAllBoard($request) {
$data = (new SpiderModel())->updateAllBoard();
$user_id = $request->user->userId;
$data = (new SpiderModel())->updateAllBoard($user_id);
$this->Export($data);
}
private function ApiLogsList($request) {
$limit = $request['limit'];
$p = $request['p'];
$start_time = empty($request['start_time']) ? date("Y-m-d",strtotime("-1 day")) : $request['start_time'];
$end_time = empty($request['end_time']) ? date("Y-m-d") : $request['end_time'];
$user_id = $request['user_id'];
$data = (new SpiderModel())->logsList($limit, $p, $start_time, $end_time, $user_id);
$this->ExportLayui(0,'成功',$data['data'],$data['total']);
}
}
......@@ -358,4 +358,16 @@ class AccessController extends Controller
return view('spiderwindow', $data);
}
/**
* 操作日志
* @param $request
* @param $data
* @param $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function logs($request, $data, $id) {
$data['title'] = '操作日志';
return view('spider', $data);
}
}
......@@ -48,17 +48,21 @@ class SpiderModel extends Model
* 更新状态
* @return array
*/
public function updateStatus() {
public function updateStatus($user_id) {
$collect = Request::all();
$map['id'] = !empty($collect['id']) ? $collect['id'] : '';
$collect = TrimX($collect, false, ['status']);
$result = $this->where($map)->update($collect);
if ($result) {
return [0,'成功'];
$re = [0,'成功'];
$re_log = ['result' => 'true'];
} else {
return [1,'失败'];
$re = [1,'失败'];
$re_log = ['result' => 'false'];
}
$this->writeLog($user_id, '更新状态', json_encode(['status' => $collect['status']]), json_encode($re_log));
return $re;
}
......@@ -66,13 +70,14 @@ class SpiderModel extends Model
* 插入内容
* @return mixed
*/
public function insertContent() {
public function insertContent($user_id) {
$collect = Request::all();
$collect['start_time'] = strtotime($collect['start_time']);
unset($collect['s']);
return $this->insert($collect);
$return = $this->insert($collect);
$return = $this->writeLog($user_id, '插入新任务', json_encode($collect), json_encode(['result' => $return]));
return $return;
}
......@@ -80,7 +85,7 @@ class SpiderModel extends Model
* 更新内容
* @return array
*/
public function updateContent() {
public function updateContent($user_id) {
$collect = Request::all();
$map['id'] = !empty($collect['id']) ? $collect['id'] : 0;
......@@ -93,11 +98,16 @@ class SpiderModel extends Model
$result = $this->where($map)->update($collect);
if ($result) {
return [0,'成功'];
$re = [0,'成功'];
$re_log = ['result' => 'true'];
} else {
return [1,'失败'];
$re = [1,'失败'];
$re_log = ['result' => 'false'];
}
$this->writeLog($user_id, '更新内容', json_encode($collect), json_encode($re_log));
return $re;
}
/**
......@@ -166,7 +176,7 @@ class SpiderModel extends Model
* 更新节点
* @return array
*/
public function updateNode() {
public function updateNode($user_id) {
$collect = Request::all();
$map['id'] = !empty($collect['id']) ? $collect['id'] : 0;
......@@ -176,10 +186,15 @@ class SpiderModel extends Model
$result = DB::connection('dashboard')->table('spider_node')->where($map)->update($collect);
if ($result) {
return [0,'成功'];
$re = [0,'成功'];
$re_log = ['result' => 'true'];
} else {
return [1,'失败'];
$re = [1,'失败'];
$re_log = ['result' => 'false'];
}
$this->writeLog($user_id, '更新节点', json_encode($collect), json_encode($re_log));
return $re;
}
......@@ -187,7 +202,7 @@ class SpiderModel extends Model
* 更新所有节点
* @return array
*/
public function updateAllNode() {
public function updateAllNode($user_id) {
$collect = Request::all();
......@@ -196,10 +211,15 @@ class SpiderModel extends Model
$result = DB::connection('dashboard')->table('spider_node')->update($collect);
if ($result) {
return [0,'成功'];
$re = [0,'成功'];
$re_log = ['result' => 'true'];
} else {
return [1,'失败'];
$re = [1,'失败'];
$re_log = ['result' => 'false'];
}
$this->writeLog($user_id, '更新所有节点', json_encode($collect), json_encode($re_log));
return $re;
}
......@@ -207,7 +227,7 @@ class SpiderModel extends Model
* 更新所有面板状态
* @return array
*/
public function updateAllBoard() {
public function updateAllBoard($user_id) {
$collect = Request::all();
......@@ -216,11 +236,63 @@ class SpiderModel extends Model
$result = DB::connection('dashboard')->table('spider_board')->where('status', '!=', '2')->update($collect);
if ($result) {
return [0,'成功'];
$re = [0,'成功'];
$re_log = ['result' => 'true'];
} else {
return [1,'失败'];
$re = [1,'失败'];
$re_log = ['result' => 'false'];
}
$this->writeLog($user_id, '更新所有面板', json_encode($collect), json_encode($re_log));
return $re;
}
/**
* 日志列表
*/
public function logsList($limit, $p, $start_time, $end_time, $user_id) {
$limit = !empty($limit) ? $limit : '';
$p = !empty($p) ? $p : 1;
$map = [];
$map[] = ['update_time', '>=', strtotime($start_time)];
$map[] = ['update_time', '<=', strtotime($end_time) + 86400];
if (!empty($user_id))
$map[] = ['user_id', '=', $user_id];
$data = DB::connection('dashboard')->table('spider_action_log')->where($map)->paginate($limit,['*'],'p',$p)->toArray();
foreach ($data['data'] as $k => $v) {
$data['data'][$k]['update_time'] = date("Y-m-d H:i:s", $v['update_time']);
}
return $data;
}
/**
* 写入日志
* @user_id 会员id
* @action 行为
* @content 修改内容
* @result 结果
*/
public function writeLog($user_id, $action, $content, $result) {
$arr = [
'user_id' => $user_id,
'action' => $action,
'content' => $content,
'result' => $result,
'update_time' => time()
];
DB::connection('dashboard')->table('spider_action_log')->insert($arr);
}
}
layui.use(['table', 'form', 'laydate', 'layer'], function () {
var table = layui.table;
var form = layui.form;
var laydate = layui.laydate;
laydate.render({
elem: '#start_time'
,format:'yyyy-MM-dd'
});
laydate.render({
elem: '#end_time'
,format:'yyyy-MM-dd'
});
table.render({
elem:'#table',
loading:true,
cellMinWidth: 100,
page:true,
limit: 50,
url: '/api/ApiLogsList/',
request:{pageName:'p', limitName:'limit'},
cols: [[
{field:'user_id', title:'用户id', sort: true},
{field:'action', title: '行为', sort: true},
{field:'content', title:'修改内容', sort: true},
{field:'result', title:'结果', width: 250, sort: true},
{field:'update_time', title:'更新时间', width: 140, sort: true},
]],
id: 'idTest'
});
var $ = layui.$, active = {
reload: function(){
//执行重载
table.reload('idTest', {
page: {
curr: 1 //重新从第 1 页开始
}
, where: {
start_time: $('#start_time').val(),
end_time: $('#end_time').val(),
user_id: $('#user_id').val(),
}
})
},
};
$('.load').on('click', function(){
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
})
<div class="layui-form">
<div class="layui-form-item">
<div class="layui-inline">
<div class="layui-input-inline">
<input type="text" name="start_time" id="start_time" autocomplete="off" class="layui-input" value="{{$_GET['start_time'] or ''}}">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" name="end_time" id="end_time" autocomplete="off" class="layui-input" value="{{$_GET['end_time'] or ''}}">
</div>
</div>
<div class="layui-inline">
<input type="text" id="user_id" placeholder="用户id" class="layui-input" value="{{$_GET['end_time'] or ''}}">
</div>
<div class="layui-inline">
<button class="btn btn btn-outline btn-primary load" id="search" lay-submit lay-filter="*" data-type="reload">搜索</button>
</div>
</div>
</div>
<table class="layui-table" id="table" lay-filter="demo"></table>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment