操作日志新增条件查询,并简单优化了操作日志控制器
This commit is contained in:
parent
a6ad9b63dd
commit
142fd71b56
@ -8,12 +8,6 @@ use catchAdmin\system\model\OperateLog as Log;
|
|||||||
|
|
||||||
class OperateLog extends CatchController
|
class OperateLog extends CatchController
|
||||||
{
|
{
|
||||||
protected $model;
|
|
||||||
|
|
||||||
public function __construct(Log $model)
|
|
||||||
{
|
|
||||||
$this->model = $model;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @time 2020年04月28日
|
* @time 2020年04月28日
|
||||||
@ -45,7 +39,7 @@ class OperateLog extends CatchController
|
|||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
*/
|
*/
|
||||||
public function delete($id)
|
public function delete($id, Log $log)
|
||||||
{
|
{
|
||||||
$ids = explode(',', $id);
|
$ids = explode(',', $id);
|
||||||
|
|
||||||
@ -53,6 +47,6 @@ class OperateLog extends CatchController
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CatchResponse::success($this->model->whereIn('id', $ids)->delete());
|
return CatchResponse::success($log->whereIn('id', $ids)->delete());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace catchAdmin\system\model;
|
namespace catchAdmin\system\model;
|
||||||
|
|
||||||
use catchAdmin\permissions\model\Users;
|
use catchAdmin\permissions\model\Users;
|
||||||
use catcher\traits\db\BaseOptionsTrait;
|
use catcher\traits\db\BaseOptionsTrait;
|
||||||
|
use catchAdmin\system\model\search\OperateLogSearch;
|
||||||
|
|
||||||
class OperateLog extends \think\Model
|
class OperateLog extends \think\Model
|
||||||
{
|
{
|
||||||
use BaseOptionsTrait;
|
use BaseOptionsTrait;
|
||||||
|
use OperateLogSearch;
|
||||||
|
|
||||||
|
|
||||||
protected $name = 'operate_log';
|
protected $name = 'operate_log';
|
||||||
|
|
||||||
protected $field = [
|
protected $field = [
|
||||||
'id', //
|
'id', //
|
||||||
'module', // 模块名称
|
'module', // 模块名称
|
||||||
'operate', // 操作模块
|
'operate', // 操作模块
|
||||||
'route', // 路由
|
'route', // 路由
|
||||||
'params', // 参数
|
'params', // 参数
|
||||||
'ip', // ip
|
'ip', // ip
|
||||||
'creator_id', // 创建人ID
|
'creator_id', // 创建人ID
|
||||||
'method', // 请求方法
|
'method', // 请求方法
|
||||||
'created_at', // 登录时间
|
'created_at', // 登录时间
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,8 +37,9 @@ class OperateLog extends \think\Model
|
|||||||
public function getList()
|
public function getList()
|
||||||
{
|
{
|
||||||
return $this->field([$this->aliasField('*')])
|
return $this->field([$this->aliasField('*')])
|
||||||
->catchJoin(Users::class, 'id', 'creator_id', ['username as creator'])
|
->catchJoin(Users::class, 'id', 'creator_id', ['username as creator'])
|
||||||
->order($this->aliasField('id'), 'desc')
|
->catchSearch()
|
||||||
->paginate();
|
->order($this->aliasField('id'), 'desc')
|
||||||
|
->paginate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
catch/system/model/search/OperateLogSearch.php
Normal file
26
catch/system/model/search/OperateLogSearch.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace catchAdmin\system\model\search;
|
||||||
|
|
||||||
|
trait OperateLogSearch
|
||||||
|
{
|
||||||
|
public function searchModuleAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->whereLike('module', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchMethodAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->whereLike('method', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchCreatorAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->where('username', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function searchCreateAtAttr($query, $value, $data)
|
||||||
|
{
|
||||||
|
return $query->whereTime($this->aliasField('created_at'), 'between', $value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user