2018-02-28 21:34:45 +08:00

77 lines
2.0 KiB
PHP

<?php
/**
* 后台操作日志管理
* @since 2018-02-06
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
namespace app\admin\controller;
use app\model\ApiAuthGroupAccess;
use app\model\ApiUser;
use app\model\ApiUserAction;
use app\model\ApiUserData;
use app\util\ReturnCode;
use app\util\Tools;
class Log extends Base {
/**
* 获取操作日志列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public function index() {
$limit = $this->request->get('size', config('apiAdmin.ADMIN_LIST_DEFAULT'));
$start = $limit * ($this->request->get('page', 1) - 1);
$type = $this->request->get('type', '');
$keywords = $this->request->get('keywords', '');
$where = [];
if ($type) {
switch ($type) {
case 1:
$where['url'] = ['like', "%{$keywords}%"];
break;
case 2:
$where['nickname'] = ['like', "%{$keywords}%"];
break;
case 3:
$where['uid'] = $keywords;
break;
}
}
$listInfo = (new ApiUserAction())->where($where)->order('addTime', 'DESC')->limit($start, $limit)->select();
$count = (new ApiUserAction())->where($where)->count();
$listInfo = Tools::buildArrFromObj($listInfo);
return $this->buildSuccess([
'list' => $listInfo,
'count' => $count
]);
}
/**
* 删除日志
* @return array
* @author zhaoxiang <zhaoxiang051405@gmail.com>
*/
public function del() {
$id = $this->request->get('id');
if (!$id) {
return $this->buildFailed(ReturnCode::EMPTY_PARAMS, '缺少必要参数');
}
ApiUserAction::destroy($id);
return $this->buildSuccess([]);
}
}