From 8996158fb5d2377ce7e4c85e3832cb50abe69e38 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Fri, 5 Apr 2024 17:22:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E4=BA=AB=E8=AE=BF=E9=97=AE=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E7=9A=84=E4=B8=80=E9=83=A8=E5=88=86=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20*=E8=AF=A5=E5=8A=9F=E8=83=BD=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E4=BB=8D=E6=9C=AA=E5=AE=9E?= =?UTF-8?q?=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/AdminController.php | 16 +++++++++++++- models/DownloadLogs.php | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/controllers/AdminController.php b/controllers/AdminController.php index ab7edfd..3e8d5b5 100644 --- a/controllers/AdminController.php +++ b/controllers/AdminController.php @@ -2,6 +2,7 @@ namespace app\controllers; +use app\models\DownloadLogs; use app\models\LoginLogs; use app\models\SiteConfig; use app\models\User; @@ -34,7 +35,7 @@ class AdminController extends Controller 'rules' => [ [ 'allow' => true, - 'actions' => ['index', 'system', 'user', 'info', 'user-view', 'user-create', 'user-update', 'user-delete', 'user-totpoff', 'user-pwdreset', 'login-log'], + 'actions' => ['index', 'system', 'user', 'info', 'user-view', 'user-create', 'user-update', 'user-delete', 'user-totpoff', 'user-pwdreset', 'login-log','access-log'], 'roles' => ['admin'], // only admin can do these ] ], @@ -53,6 +54,7 @@ class AdminController extends Controller 'user-totpoff' => ['POST'], 'user-pwdreset' => ['POST'], 'login-log' => ['GET'], + 'access-log' => ['GET'], ], ], ] @@ -395,4 +397,16 @@ class AdminController extends Controller ]); } + /** + * @return string + */ + public function actionAccessLog(): string + { + $downloadLogs = new DownloadLogs(); + $dataProvider = $downloadLogs->search($this->request->queryParams); + return $this->render('access_log', [ + 'searchModel' => $downloadLogs, + 'dataProvider' => $dataProvider, + ]); + } } diff --git a/models/DownloadLogs.php b/models/DownloadLogs.php index c86d903..256e1e5 100644 --- a/models/DownloadLogs.php +++ b/models/DownloadLogs.php @@ -2,6 +2,7 @@ namespace app\models; +use yii\data\ActiveDataProvider; use yii\db\ActiveQuery; use yii\db\ActiveRecord; @@ -96,4 +97,42 @@ class DownloadLogs extends ActiveRecord $log->save(); } + + public function search($params): ActiveDataProvider + { + $query = DownloadLogs::find(); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, // 默认按照 'id' 倒序排序 + ] + ], + ]); + + $this->load($params); + + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'user_id' => $this->user_id, + 'share_id' => $this->share_id, + 'access_time' => $this->access_time, + ]); + + $query->andFilterWhere(['like', 'ip_address', $this->ip_address]) + ->andFilterWhere(['like', 'user_agent', $this->user_agent]); + + + return $dataProvider; + } }