You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/admin/model/system/SystemLog.php

115 lines
3.7 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\admin\model\system;
use traits\ModelTrait;
use basic\ModelBasic;
use think\Request;
use app\admin\model\system\SystemMenus;
use app\admin\model\system\SystemAdmin;
/**
* 管理员操作记录
* Class SystemLog
* @package app\admin\model\system
*/
class SystemLog extends ModelBasic
{
use ModelTrait;
protected $insert = ['add_time'];
protected function setAddTimeAttr()
{
return time();
}
/**
* 管理员访问记录
* @param Request $request
*/
public static function adminVisit($adminId, $adminName, $type)
{
$request = Request::instance();
$module = $request->module();
$controller = $request->controller();
$action = $request->action();
$route = $request->route();
$data = [
'method' => $request->method(),
'admin_id' => $adminId,
'admin_name' => $adminName,
'path' => SystemMenus::getAuthName($action, $controller, $module, $route),
'page' => SystemMenus::getVisitName($action, $controller, $module, $route) ?: '未知',
'ip' => $request->ip(),
'type' => $type
];
return self::set($data);
}
/**
* 手动添加管理员当前页面访问记录
* @param array $adminInfo
* @param string $page 页面名称
* @return object
*/
public static function setCurrentVisit($adminInfo, $page)
{
$request = Request::instance();
$module = $request->module();
$controller = $request->controller();
$action = $request->action();
$route = $request->route();
$data = [
'method' => $request->method(),
'admin_id' => $adminInfo['id'],
'path' => SystemMenus::getAuthName($action, $controller, $module, $route),
'page' => $page,
'ip' => $request->ip()
];
return self::set($data);
}
/**
* 获取管理员访问记录
* */
public static function systemPage($where = array())
{
$model = new self;
$model = $model->alias('l');
if ($where['pages'] !== '') $model = $model->where('l.page', 'LIKE', "%$where[pages]%");
if ($where['admin_id'] != '')
$adminIds = $where['admin_id'];
else
$adminIds = SystemAdmin::where('level', '>=', $where['level'])->column('id');
$model = $model->where('l.admin_id', 'IN', $adminIds);
if ($where['data'] !== '') {
list($startTime, $endTime) = explode(' - ', $where['data']);
$model = $model->where('l.add_time', '>', strtotime($startTime));
$model = $model->where('l.add_time', '<', strtotime($endTime));
}
$model->where('l.type', 'system');
$model = $model->order('l.id desc');
return self::page($model, $where);
}
/**
* 删除超过90天的日志
*/
public static function deleteLog()
{
$model = new self;
$model->where('add_time', '<', time() - 7776000);
$model->delete();
}
}