From b65f5de9b449b449ee08dd3c6154dea8cbe17b74 Mon Sep 17 00:00:00 2001 From: cursor Date: Tue, 9 Jun 2026 02:49:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(R19):=20=E6=B6=88=E6=81=AFis=5Fread+?= =?UTF-8?q?=E7=A6=81=E8=81=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Message.php | 29 +++++++++++++++++++++++++++++ app/model/Message.php | 13 ++++++++++++- route/app.php | 3 ++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/controller/Message.php b/app/controller/Message.php index 18cbd52..e250179 100644 --- a/app/controller/Message.php +++ b/app/controller/Message.php @@ -31,6 +31,7 @@ class Message extends BaseController 'content' => $m['content'], 'time' => date('Y-m-d H:i:s', strtotime($m['created_at'])), 'staffId' => $m['staff_id'] ?? null, + 'isRead' => $m['is_read'] ?? 0, ]; }, $messages); @@ -69,8 +70,36 @@ class Message extends BaseController 'sender_type' => $senderType, 'staff_id' => $staffId, 'content' => $content, + 'is_read' => 0, // 默认未读 ]); return json(['code' => 0, 'data' => ['id' => $msg->id], 'msg' => 'ok']); } + + // 标记消息为已读 + public function read() + { + $cardNo = $this->request->post('card_no', ''); + $staffId = $this->request->post('staff_id', null); + + if (empty($cardNo)) { + return json(['code' => -1, 'data' => null, 'msg' => '缺少号码牌']); + } + + // 顾客端标记员工消息为已读 + if ($staffId === null) { + MessageModel::where('card_no', $cardNo) + ->where('sender_type', 'staff') + ->where('is_read', 0) + ->update(['is_read' => 1]); + } else { + // 员工端标记顾客消息为已读 + MessageModel::where('card_no', $cardNo) + ->where('sender_type', 'customer') + ->where('is_read', 0) + ->update(['is_read' => 1]); + } + + return json(['code' => 0, 'data' => null, 'msg' => 'ok']); + } } diff --git a/app/model/Message.php b/app/model/Message.php index a703501..2f5f5d6 100644 --- a/app/model/Message.php +++ b/app/model/Message.php @@ -1,4 +1,4 @@ - 'int', + 'card_no' => 'string', + 'sender_type' => 'string', + 'staff_id' => 'int', + 'content' => 'text', + 'is_read' => 'int', + 'created_at' => 'datetime', + ]; } diff --git a/route/app.php b/route/app.php index c179c1e..9a98579 100644 --- a/route/app.php +++ b/route/app.php @@ -1,4 +1,4 @@ -