From 96d718624e8d96a256e67a72607260372b7651d6 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sat, 6 Apr 2024 13:53:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=94=B6=E9=9B=86=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=20=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=20=E5=90=8E?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/CollectionController.php | 2 ++ models/CollectionUploaded.php | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/controllers/CollectionController.php b/controllers/CollectionController.php index 1ecbff1..2e60abf 100644 --- a/controllers/CollectionController.php +++ b/controllers/CollectionController.php @@ -239,10 +239,12 @@ class CollectionController extends Controller // 创建一个新的CollectionUploaded模型实例,并设置其属性值 $model = new CollectionUploaded(); + $model->user_id = Yii::$app->user->id; $model->task_id = $taskId; $model->uploader_ip = $uploaderIp; $model->uploaded_at = date('Y-m-d H:i:s'); // 设置上传时间为当前时间 $model->subfolder_name = $subfolderName; + $model->user_agent = $request->userAgent; if ($model->validate()) { // 进行文件上传 $targetDirectory = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . $userId . '/' . $folderPath . '/' . $subfolderName; diff --git a/models/CollectionUploaded.php b/models/CollectionUploaded.php index d3c142e..0895f4c 100644 --- a/models/CollectionUploaded.php +++ b/models/CollectionUploaded.php @@ -9,12 +9,15 @@ use yii\db\ActiveRecord; * This is the model class for table "collection_uploaded". * * @property int $id 文件收集的上传记录id + * @property int|null $user_id 用户ID * @property int $task_id 对应的文件收集id * @property string $uploader_ip 上传者ip * @property string $uploaded_at 上传时间 * @property string $subfolder_name 对应的子文件夹名 + * @property string $user_agent 浏览器UA信息 * * @property CollectionTasks $task + * @property User $user */ class CollectionUploaded extends ActiveRecord { @@ -32,12 +35,13 @@ class CollectionUploaded extends ActiveRecord public function rules(): array { return [ - [['task_id', 'uploader_ip', 'subfolder_name'], 'required'], - [['task_id'], 'integer'], + [['task_id', 'uploader_ip', 'subfolder_name', 'user_agent'], 'required'], + [['user_id', 'task_id'], 'integer'], [['uploaded_at'], 'safe'], [['uploader_ip'], 'string', 'max' => 45], [['subfolder_name'], 'string', 'max' => 255], [['task_id'], 'exist', 'skipOnError' => true, 'targetClass' => CollectionTasks::class, 'targetAttribute' => ['task_id' => 'id']], + [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']], ]; } @@ -48,10 +52,12 @@ class CollectionUploaded extends ActiveRecord { return [ 'id' => '上传记录id', + 'user_id' => '用户ID', 'task_id' => '收集任务id', 'uploader_ip' => '上传者ip', 'uploaded_at' => '上传时间', 'subfolder_name' => '所在位置', + 'user_agent' => '浏览器UA信息', ]; } @@ -64,4 +70,14 @@ class CollectionUploaded extends ActiveRecord { return $this->hasOne(CollectionTasks::class, ['id' => 'task_id']); } + + /** + * Gets query for [[User]]. + * + * @return \yii\db\ActiveQuery + */ + public function getUser() + { + return $this->hasOne(User::class, ['id' => 'user_id']); + } }