From 4a5cd5493607a36bc79bfb2f3691262e6fb36e14 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Thu, 18 Apr 2024 17:15:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=B7=A5=E5=8D=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD(7/10)=20=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=8D=95=E6=89=80=E6=9C=89=E8=80=85=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91=20=E9=98=BB=E6=AD=A2=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E4=B8=8D=E5=B1=9E=E4=BA=8E=E8=AF=A5=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=9A=84=E5=B7=A5=E5=8D=95=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/TicketsController.php | 29 +++++++---------------------- models/TicketReplies.php | 4 +++- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/controllers/TicketsController.php b/controllers/TicketsController.php index 2e7e6be..d644b40 100644 --- a/controllers/TicketsController.php +++ b/controllers/TicketsController.php @@ -75,6 +75,11 @@ class TicketsController extends Controller */ public function actionView(int $id): string { + //check if this ticket belongs to current user + $ticket = Tickets::findOne(['id' => $id, 'user_id' => Yii::$app->user->id]); + if ($ticket === null) { + throw new NotFoundHttpException('The requested page does not exist.'); + } //fetch all replies for this ticket $ticketReplies = $this->findTicketReplies($id); //json @@ -134,33 +139,12 @@ class TicketsController extends Controller ]); } - /** - * Updates an existing Tickets model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param int $id 工单id - * @return string|Response - * @throws NotFoundHttpException if the model cannot be found - */ - public function actionUpdate(int $id): Response|string - { - $model = $this->findModel($id); - - if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } - - return $this->render('update', [ - 'model' => $model, - ]); - } - /** * NoNoNo, you can't delete a ticket. Just close it. * @param int $id 工单id + * @param string $from * @return Response * @throws NotFoundHttpException if the model cannot be found - * @throws \Throwable - * @throws StaleObjectException */ public function actionDelete(int $id,string $from = 'unset'): Response { @@ -192,6 +176,7 @@ class TicketsController extends Controller * Ticket reply action * For user * @return Response + * @throws NotFoundHttpException */ public function actionReply(): Response { diff --git a/models/TicketReplies.php b/models/TicketReplies.php index d9c2a9b..b4a5796 100644 --- a/models/TicketReplies.php +++ b/models/TicketReplies.php @@ -84,11 +84,13 @@ class TicketReplies extends ActiveRecord public function toArray(array $fields = [], array $expand = [], $recursive = true): array { + $currentUserId = Yii::$app->user->id; // 获取当前用户ID + $name = ($this->user->id === $currentUserId) ? '您' : $this->user->username; // 判断是否是当前用户 return [ 'id' => $this->id, 'ticket_id' => $this->ticket_id, - 'name' => ($this->is_admin === 1) ? $this->user->username : '您', + 'name' => $name, 'message' => $this->message, 'created_at' => $this->created_at, 'ip' => $this->ip,