新增系统管理

This commit is contained in:
wuyanwen 2019-12-12 22:33:12 +08:00
parent d53b0bae73
commit 15be66ec26
12 changed files with 363 additions and 0 deletions

View File

@ -0,0 +1,79 @@
<?php
namespace catchAdmin\login;
use catchAdmin\user\model\Users;
use think\facade\Db;
class LoginEvent
{
protected $params;
public function __construct(array $params)
{
$this->params = $params;
}
public function handle()
{
dd('ad');
$agent = request()->header('user-agent');
$username = Users::where('email', $this->params['email'])->value('username');
Db::name('login_log')->insert([
'login_name' => $username ? : $this->params['email'],
'login_ip' => ip2long(request()->ip()),
'browser' => $this->getBrowser($agent),
'os' => $this->getOs($agent),
'login_at' => time(),
'status' => $this->params['success'] ? 1 : 2,
]);
}
private function getOs($agent)
{
if (false !== stripos($agent, 'win') && preg_match('/nt 6.1/i', $agent)) {
return 'Windows 7';
}
if (false !== stripos($agent, 'win') && preg_match('/nt 6.2/i', $agent)) {
return 'Windows 8';
}
if(false !== stripos($agent, 'win') && preg_match('/nt 10.0/i', $agent)) {
return 'Windows 10';#添加win10判断
}
if (false !== stripos($agent, 'win') && preg_match('/nt 5.1/i', $agent)) {
return 'Windows XP';
}
if (false !== stripos($agent, 'linux')) {
return 'Linux';
}
if (false !== stripos($agent, 'mac')) {
return 'mac';
}
return '未知';
}
private function getBrowser($agent)
{
if (false !== stripos($agent, "MSIE")) {
return 'MSIE';
}
if (false !== stripos($agent, "Firefox")) {
return 'Firefox';
}
if (false !== stripos($agent, "Chrome")) {
return 'Chrome';
}
if (false !== stripos($agent, "Safari")) {
return 'Safari';
}
if (false !== stripos($agent, "Opera")) {
return 'Opera';
}
return '未知';
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace catchAdmin\permissions;
class OperateEvent
{
}

View File

@ -0,0 +1,19 @@
<?php
namespace catchAdmin\system\controller;
use catcher\base\CatchController;
use catcher\CatchResponse;
use think\facade\Db;
class LoginLog extends CatchController
{
public function index()
{
return $this->fetch();
}
public function list()
{
return CatchResponse::paginate(Db::name('login_log')->paginate(10));
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace catchAdmin\system\controller;
use catcher\base\CatchController;
use catcher\CatchResponse;
use think\facade\Db;
class OperateLog extends CatchController
{
public function index()
{
return $this->fetch();
}
public function list()
{
return CatchResponse::paginate(
Db::name('operate_log')
->field(['operate_log.*', 'users.username as creator'])
->join('users','users.id = operate_log.creator_id')
->order('id', 'desc')
->paginate(10)
);
}
}

View File

@ -0,0 +1,40 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class LoginLog extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('login_log',['engine'=>'Myisam', 'comment' => '登录日志', 'signed' => false]);
$table->addColumn('login_name', 'string',['limit' => 50,'default'=>'','comment'=>'用户名'])
->addColumn('login_ip', 'string',['default'=>0, 'limit' => 20, 'comment'=>'登录地点ip', 'signed' => false])
->addColumn('browser', 'string',['default'=> '','comment'=>'浏览器'])
->addColumn('os', 'string',['default'=> '','comment'=>'操作系统'])
->addColumn('login_at', 'integer', array('default'=>0,'comment'=>'登录时间', 'signed' => false ))
->addColumn('status', 'integer',['limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY,'default'=> 1,'comment'=>'1 成功 2 失败'])
->create();
}
}

View File

@ -0,0 +1,40 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class OperateLog extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->table('operate_log',['engine'=>'Myisam', 'comment' => '操作日志', 'signed' => false]);
$table->addColumn('module', 'string',['limit' => 50,'default'=>'','comment'=>'模块名称'])
->addColumn('ip', 'string',['default'=>'', 'limit' => 20,'comment'=>'ip', 'signed' => false])
->addColumn('operate', 'string',['default'=> '','comment'=>'操作模块'])
->addColumn('creator_id', 'integer',['default'=> 0,'comment'=>'创建人ID', 'signed' => false])
->addColumn('method', 'string',['default'=> '','comment'=>'请求方法'])
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'登录时间', 'signed' => false ))
->create();
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace catchAdmin\system\event;
class LoginLogEvent
{
protected $params;
public function __construct(array $params)
{
$this->params = $params;
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace catchAdmin\system\event;
class OperateLogEvent
{
protected $params;
public function __construct(array $params)
{
$this->params = $params;
}
}

View File

@ -0,0 +1,11 @@
{
"name": "系统管理",
"alias": "system",
"description": "",
"keywords": [],
"order": 2,
"services": [],
"aliases": {},
"files": [],
"requires": []
}

View File

@ -0,0 +1,8 @@
<?php
// 登录日志
$router->get('log/login', '\catchAdmin\system\controller\LoginLog@list');
$router->get('loginLog/index', '\catchAdmin\system\controller\LoginLog@index');
// 操作日志
$router->get('log/operate', '\catchAdmin\system\controller\OperateLog@list');
$router->get('operateLog/index', '\catchAdmin\system\controller\OperateLog@index');

View File

@ -0,0 +1,57 @@
{extend name="../../../view/layout"}
{block name="title"}登录日志{/block}
{block name="search"}
<div class="layui-form toolbar">
<div class="layui-form-item">
<!--<div class="layui-inline">
<div class="layui-input-inline mr0">
<input id="edtSearchAuth" class="layui-input" type="text" placeholder="输入角色名称"/>
</div>
</div>
<div class="layui-inline">
<button id="btnSearchAuth" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
</button>-->
<button id="btnAddAuth" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
<!--</div>-->
</div>
</div>
{/block}
{block name="table"}
<table class="layui-table" id="log"></table>
{/block}
{block name="script"}
<script>
layui.use(['layer', 'form', 'table', 'util',], function () {
var $ = layui.jquery;
var table = layui.table;
var util = layui.util;
table.render({
elem: '#log',
url: '{:url("log/login")}',
page: true,
response: {
statusCode: 10000,
},
// toolbar: true,
cellMinWidth: 100,
cols: [[
{type: 'id', title: '#', field: 'id'},
{field: 'login_name', sort: true, title: '登录名'},
{field: 'login_ip', sort: true, title: '登录IP'},
{field: 'browser', sort: true, title: '浏览器'},
{field: 'os', sort: true, title: '操作系统'},
{field: 'status', sort: true, title: '状态', templet: function (d) {
return d.status === 1 ? '成功' : '失败'
}
},
{
field: 'login_at', sort: true, templet: function (d) {
return util.toDateString(d.login_at);
}, title: '登录时间'
},
]],
});
});
</script>
{/block}

View File

@ -0,0 +1,53 @@
{extend name="../../../view/layout"}
{block name="title"}操作日志{/block}
{block name="search"}
<div class="layui-form toolbar">
<div class="layui-form-item">
<!--<div class="layui-inline">
<div class="layui-input-inline mr0">
<input id="edtSearchAuth" class="layui-input" type="text" placeholder="输入角色名称"/>
</div>
</div>
<div class="layui-inline">
<button id="btnSearchAuth" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索
</button>-->
<button id="btnAddAuth" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
<!--</div>-->
</div>
</div>
{/block}
{block name="table"}
<table class="layui-table" id="log"></table>
{/block}
{block name="script"}
<script>
layui.use(['layer', 'form', 'table', 'util',], function () {
var $ = layui.jquery;
var table = layui.table;
var util = layui.util;
table.render({
elem: '#log',
url: '{:url("log/operate")}',
page: true,
response: {
statusCode: 10000,
},
// toolbar: true,
cellMinWidth: 100,
cols: [[
{type: 'id', title: '#', field: 'id'},
{field: 'module', sort: true, title: '模块'},
{field: 'ip', sort: true, title: 'IP'},
{field: 'operate', sort: true, title: 'operate'},
{field: 'creator', sort: true, title: '操作者'},
{field: 'method', sort: true, title: '请求方法'},
{field: 'created_at', sort: true, title: '创建时间', templet: function (d) {
return d.status === 1 ? '成功' : '失败'
}
},
]],
});
});
</script>
{/block}