feat: add user notification center

This commit is contained in:
hajimi
2026-08-03 21:44:30 +08:00
parent 17720e86e2
commit 9df5f5f620
17 changed files with 1401 additions and 5 deletions
+71
View File
@@ -0,0 +1,71 @@
-- 用户站内消息
-- 复用现有 la_notice_record 表:scene_id 1001-1005 为社区互动、积分到账和后台系统消息。
SET @notice_index_exists := (
SELECT COUNT(*)
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'la_notice_record'
AND index_name = 'idx_user_scene_read_id'
);
SET @notice_index_sql := IF(
@notice_index_exists = 0,
'ALTER TABLE `la_notice_record` ADD INDEX `idx_user_scene_read_id` (`user_id`, `scene_id`, `read`, `id`)',
'SELECT 1'
);
PREPARE notice_index_stmt FROM @notice_index_sql;
EXECUTE notice_index_stmt;
DEALLOCATE PREPARE notice_index_stmt;
-- 管理后台:应用管理 > 消息管理 > 站内消息。
SET @message_parent_id := (
SELECT `id`
FROM `la_system_menu`
WHERE `type` = 'M' AND `paths` = 'message'
LIMIT 1
);
INSERT INTO `la_system_menu`
(`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_cache`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
@message_parent_id, 'C', '站内消息', '', 0, 'notice.userNotice/lists', 'user_notice', 'message/user_notice/index', '', '', 0, 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
WHERE @message_parent_id IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM `la_system_menu` WHERE `perms` = 'notice.userNotice/lists'
);
SET @user_notice_menu_id := (
SELECT `id`
FROM `la_system_menu`
WHERE `perms` = 'notice.userNotice/lists'
LIMIT 1
);
INSERT INTO `la_system_menu`
(`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_cache`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT @user_notice_menu_id, permission.`name`, '', 0, permission.`perms`, '', '', '', '', 0, 0, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM (
SELECT '消息类型选项' AS `name`, 'notice.userNotice/options' AS `perms`
UNION ALL SELECT '发布系统消息', 'notice.userNotice/send'
UNION ALL SELECT '删除站内消息', 'notice.userNotice/delete'
) permission
WHERE @user_notice_menu_id IS NOT NULL
AND NOT EXISTS (
SELECT 1 FROM `la_system_menu` existing_menu WHERE existing_menu.`perms` = permission.`perms`
);
INSERT INTO `la_system_role_menu` (`role_id`, `menu_id`)
SELECT 1, menu.`id`
FROM `la_system_menu` menu
WHERE menu.`perms` IN (
'notice.userNotice/lists',
'notice.userNotice/options',
'notice.userNotice/send',
'notice.userNotice/delete'
)
AND NOT EXISTS (
SELECT 1
FROM `la_system_role_menu` role_menu
WHERE role_menu.`role_id` = 1
AND role_menu.`menu_id` = menu.`id`
);
+20
View File
@@ -2575,6 +2575,26 @@
- `uniapp/src/pages/my_comments/my_comments.vue`
- `uniapp/src/pages.json`
### 132. 用户站内消息中心
- 状态:代码已完成,待 SQL 执行及多账号验收 - 时间:2026-08-03
完成内容:
- 复用 `la_notice_record` 记录社区帖子评论、评论回复、关注、后台加积分和后台系统消息,并按接收用户独立保存已读状态。
- 用户中心的“消息通知”接入消息中心;私聊消息独立保留入口,未读角标合并私聊与站内消息数量。
- 消息卡片支持标记已读,并按记录跳转帖子详情、用户主页和积分明细等对应页面。
- 管理后台新增“站内消息”管理页,可筛选、删除记录,及向全部启用用户或指定用户发布可跳转的系统消息。
涉及模块:
- `server/app/common/service/notice/UserNoticeService.php`
- `server/app/api/controller/NoticeController.php`
- `server/app/adminapi/controller/notice/UserNoticeController.php`
- `admin/src/views/message/user_notice/index.vue`
- `uniapp/src/pages/message_notice/message_notice.vue`
- `docs/sql/create_user_notice.sql`
## 四、避坑记录
- **跨模型批量更新前必须逐表核对字段**:`la_community_post``la_community_post_category``update_time`,但 `la_community_tag` 只有 `create_time`;复用计数刷新写法时不能默认所有业务表都有更新时间字段,否则 ThinkPHP 模型会直接返回 `fields not exists` 并导致事务回滚。