Переглянути джерело

feat(message): 添加消息已读功能并优化前端通知交互
- 后端新增消息标记为已读接口和逻辑处理
- 前端实现消息已读状态更新功能
- 优化新订单消息通知展示方式,增加"知道了"操作按钮
- 新增自动关闭定时器及手动确认关闭消息机制
- 完善消息轮询清理逻辑,避免内存泄漏

runphp 4 місяців тому
батько
коміт
2761cd377a

+ 1 - 1
route/admin.php

@@ -71,5 +71,5 @@ Route::group('setting', function () {
 
 // 获取消息列表
 Route::resource('', MessageController::class)
-    ->only(['index'])
+    ->only(['index', 'read'])
     ->middleware(['auth', MacroPageMiddleware::class]);

+ 11 - 0
src/Controller/Admin/MessageController.php

@@ -4,7 +4,10 @@ namespace SixShop\Message\Controller\Admin;
 
 use SixShop\Core\Request;
 use SixShop\Message\Entity\MessageNotificationsEntity;
+use think\Response;
+
 use function SixShop\Core\page_response;
+use function SixShop\Core\success_response;
 
 class MessageController
 {
@@ -19,4 +22,12 @@ class MessageController
         $params['user_id'] = $request->userID;
         return page_response($messageNotificationsEntity->getList($params, $request->pageAndLimit()));
     }
+
+    /**
+     * 标记消息为已读
+     */
+    public function read(int $id, MessageNotificationsEntity $messageNotificationsEntity):Response
+    {
+        return success_response($messageNotificationsEntity->read($id));
+    }
 }

+ 12 - 0
src/Entity/MessageNotificationsEntity.php

@@ -5,6 +5,7 @@ namespace SixShop\Message\Entity;
 use SixShop\Core\Entity\BaseEntity;
 use SixShop\Message\Model\MessageNotificationsModel;
 use think\Paginator;
+use function SixShop\Core\throw_logic_exception;
 
 /**
  * @mixin MessageNotificationsModel
@@ -16,4 +17,15 @@ class MessageNotificationsEntity extends BaseEntity
         return $this->withSearch(['user_id', 'is_read'], $params)
             ->paginate($pageAndLimit);
     }
+
+    public function read(int $id): self
+    {
+        $entity = $this->findOrEmpty($id);
+        if ($entity->isEmpty()) {
+            throw_logic_exception('消息不存在');
+        }
+        $entity->is_read = 1;
+        $entity->save();
+        return $entity;
+    }
 }