93 lines
2.7 KiB
PHP
93 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\controller;
|
|
|
|
use app\admin\model\AuthGroup;
|
|
use app\common\controller\adminApi;
|
|
use app\common\controller\Backend;
|
|
|
|
/**
|
|
* 管理员日志
|
|
*
|
|
* @icon
|
|
* @remark 管理员可以查看自己所拥有的权限的管理员日志
|
|
*/
|
|
class Adminlog extends adminApi
|
|
{
|
|
|
|
/**
|
|
* @var \app\admin\model\AdminLog
|
|
*/
|
|
protected $model = null;
|
|
protected $childrenAdminIds = [];
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->model = model('admin/AdminLog');
|
|
$this->childrenAdminIds = $this->auth->getChildrenAdminIds(true);
|
|
}
|
|
|
|
/**
|
|
* 查看
|
|
*/
|
|
public function index()
|
|
{
|
|
//设置过滤方法
|
|
$this->request->filter(['strip_tags', 'trim']);
|
|
$page = input('page', 1);
|
|
$page_limit = input('page_limit', 30);
|
|
$search_username = input('search_username', '');
|
|
$search_title = input('search_title', '');
|
|
$search_stime = input('search_time', '');
|
|
$search_etime = input('search_etime', '');
|
|
$where = [];
|
|
if ($search_username) {
|
|
$where['username'] = ['like', '%' . $search_username . '%'];
|
|
}
|
|
if ($search_title) {
|
|
$where['title'] = ['like', '%' . $search_title . '%'];
|
|
}
|
|
if ($search_stime) {
|
|
$where['createtime'] = ['>=', strtotime($search_stime)];
|
|
}
|
|
if ($search_etime) {
|
|
$where['createtime'] = ['<=', strtotime($search_etime)];
|
|
}
|
|
if(!empty($search_stime) && !empty($search_etime)){
|
|
$where['createtime'] = ['between',[strtotime($search_stime),strtotime($search_etime)]];
|
|
}
|
|
|
|
$list_data = $this->model->where($where)->where('admin_id', 'in', $this->childrenAdminIds)->order('createtime', 'desc')->paginate($page_limit, false, ['page' => $page]);
|
|
foreach ($list_data as &$v) {
|
|
$v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
|
|
}
|
|
$return_data = [
|
|
'page' =>$page,
|
|
'page_limit' => $page_limit,
|
|
'count' => $list_data->total(),
|
|
'lists' => $list_data->items(),
|
|
];
|
|
return V(1,"成功", $return_data);
|
|
}
|
|
|
|
/**
|
|
* 详情
|
|
*/
|
|
public function detail($id=0)
|
|
{
|
|
$id = input('id', 0);
|
|
$row = $this->model->get(['id' => $id]);
|
|
if (!$row) {
|
|
return V(0,"日志不存在", null);
|
|
}
|
|
if (!$this->auth->isSuperAdmin()) {
|
|
if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) {
|
|
return V(0,"你没有权限访问", null);
|
|
}
|
|
}
|
|
return V(1,"成功", $row->toArray());
|
|
}
|
|
|
|
}
|