69 lines
1.6 KiB
PHP
Executable File
69 lines
1.6 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Description:操作日志记录
|
|
*/
|
|
|
|
namespace common\components;
|
|
use common\models\Logs;
|
|
use Yii;
|
|
|
|
class DoLogs {
|
|
|
|
public static function record(){
|
|
$username = '';
|
|
$uid = 0;
|
|
if(isset(Yii::$app->user->identity)){
|
|
$username = Yii::$app->user->identity->username;
|
|
$uid = Yii::$app->user->identity->id;
|
|
}
|
|
$usertypes = array(
|
|
'app-backend' => '1',
|
|
'app-frontend' => '2',
|
|
);
|
|
$usertype = $usertypes[Yii::$app->id];
|
|
$request = Yii::$app->getRequest();
|
|
$nowFile = $request -> getScriptFile();
|
|
$r = isset($_GET['r']) ? $_GET['r'] : 'null/null';
|
|
$r = explode('/',$r);
|
|
$m = '';
|
|
$m = $r[0];
|
|
$v = '';
|
|
$c = '';
|
|
$c = $r[1];
|
|
//$a = __METHOD__; //当前方法
|
|
$a = '';
|
|
$ip = Yii::$app->request->userIP;
|
|
$domain=$_SERVER['HTTP_HOST'];
|
|
$data = '';
|
|
Yii::$app->db->createCommand()->insert(
|
|
'c_logs', [
|
|
'username' => $username,
|
|
'uid' => $uid,
|
|
'usertype' => $usertype,
|
|
'file' => $nowFile,
|
|
'm' => $m,
|
|
'v' => $v,
|
|
'c' => $c,
|
|
'a' => $a,
|
|
'ip'=>$ip,
|
|
'domain' => $domain,
|
|
'data'=>$data,
|
|
'create_time' => time(),
|
|
])->execute();
|
|
}
|
|
|
|
//历史访客数
|
|
public static function getHistoryVisNum(){
|
|
$res = Logs::find()->count();
|
|
return $res;
|
|
}
|
|
|
|
//最近一个月访问量
|
|
public static function getMonthHistoryVisNum(){
|
|
$LastMonth = strtotime("-1 month");
|
|
$res = Logs::find()->where(['>','create_time',$LastMonth])->count();
|
|
return $res;
|
|
}
|
|
|
|
}
|