找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 30|回复: 0

[维护日志] [2026-06-09] [功能] [批量删帖邮件通知] - 前台管理面板批量删帖邮件通知功能实现

[复制链接]
  • 打卡等级:本地老炮

9337

威望

7448

金钱

1万

贡献

管理员

自由的灵魂

积分
107434
主题
5630
回帖
26661
注册时间
2003-4-10
最后登录
2026-10-2
发表于 2026-6-9 21:35:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

1、问题缘起

论坛已有帖子页面勾选回帖的「管理」操作邮件通知功能,但前台管理面板(modcp)的批量删帖功能一直没有邮件通知。当版主或管理员通过 forum.php?mod=modcp&action=thread&op=post 批量删除回帖时,被删帖用户收不到任何通知,导致用户不知道自己的帖子为何消失,影响用户体验和社区沟通效率。

讨论过程中发现的相关问题:

问题解决方案
后台批量删帖代码位置不明确通过 grep 搜索定位到 modcp_thread.php
被删除的帖子需要按作者分组遍历 $pidsdelete 数组,按 authorid 分组
需要区分单条和批量删除根据 $post_count 判断,分别构建邮件内容
操作名称需要醒目使用红色 <span> 包裹「删除回帖」
邮件发送不能阻塞删除操作使用现有 common_mail_queue 异步发送





2、解决方案

(1)简要技术分析:
在 modcp_thread.php 的批量删除逻辑中,收集被删除的帖子信息,按作者分组后,通过邮件队列异步发送通知邮件。

(2)修改文件列表:

操作文件路径
修改/source/include/modcp/modcp_thread.php


(3)关键代码段:

  1. // ========= 批量删帖邮件通知 =========
  2. if ($pidsdelete) {
  3.     require_once libfile('function/mail');
  4.    
  5.     // 收集被删除的帖子信息
  6.     $deleted_pids = array();
  7.     foreach ($pidsdelete as $fid => $pids) {
  8.         foreach ($pids as $pid) {
  9.             $deleted_pids[] = $pid;
  10.         }
  11.     }
  12.    
  13.     if (!empty($deleted_pids)) {
  14.         // 获取帖子详情
  15.         $posts = C::t('forum_post')->fetch_all($posttableid, $deleted_pids);
  16.         $tids = array();
  17.         foreach ($posts as $post) {
  18.             $tids[$post['tid']] = $post['tid'];
  19.         }
  20.         $threads = C::t('forum_thread')->fetch_all($tids);
  21.         
  22.         // 按作者分组
  23.         $author_posts = array();
  24.         foreach ($posts as $post) {
  25.             $authorid = $post['authorid'];
  26.             if ($authorid > 0) {
  27.                 $author_posts[$authorid][] = $post;
  28.             }
  29.         }
  30.         
  31.         // 发送邮件给每个作者
  32.         foreach ($author_posts as $authorid => $user_posts) {
  33.             $author = C::t('common_member')->fetch($authorid);
  34.             if (empty($author['email'])) continue;
  35.             
  36.             $post_count = count($user_posts);
  37.             $subject = '您在 『' . $_G['forum']['name'] . '』 的回帖被批量删除';
  38.             
  39.             $mail_message = "<html><body>";
  40.             $mail_message .= "<p>尊敬的 " . $author['username'] . ",您好:</p>";
  41.             
  42.             if ($post_count == 1) {
  43.                 $post = $user_posts[0];
  44.                 $thread = $threads[$post['tid']];
  45.                 $mail_message .= "<p>您在主题《" . htmlspecialchars($thread['subject']) . "》中的回帖被执行了「<span style="color:red;">删除回帖</span>」操作。</p>";
  46.                 $mail_message .= "<p>查看详情:<a href="" . $_G['siteurl'] . "forum.php?mod=viewthread&tid=" . $post['tid'] . "">" . $_G['siteurl'] . "forum.php?mod=viewthread&tid=" . $post['tid'] . "</a></p>";
  47.             } else {
  48.                 $mail_message .= "<p>您在论坛发布的以下 " . $post_count . " 个回帖被执行了「<span style="color:red;">删除回帖</span>」操作:</p><ul>";
  49.                 foreach ($user_posts as $post) {
  50.                     $thread = $threads[$post['tid']];
  51.                     $mail_message .= "<li><a href="" . $_G['siteurl'] . "forum.php?mod=viewthread&tid=" . $post['tid'] . "">" . htmlspecialchars($thread['subject']) . "</a></li>";
  52.                 }
  53.                 $mail_message .= "</ul>";
  54.                 $mail_message .= "<p>操作人:" . $_G['member']['username'] . "</p>";
  55.                 $mail_message .= "<p>操作时间:" . date('Y-m-d H:i:s') . "</p>";
  56.             }
  57.             $mail_message .= "<p>登录论坛查看详细操作记录。</p>";
  58.             $mail_message .= "</body></html>";
  59.             
  60.             C::t('common_mail_queue')->insert(array(
  61.                 'uid' => $authorid,
  62.                 'toemail' => $author['email'],
  63.                 'username' => $author['username'],
  64.                 'subject' => $subject,
  65.                 'message' => $mail_message,
  66.                 'dateline' => TIMESTAMP,
  67.                 'status' => 0,
  68.             ));
  69.         }
  70.     }
  71. }
  72. // ========= 批量删帖邮件通知结束 =========
复制代码





3、最终实现效果

场景邮件内容红色高亮
单条回帖被删除显示具体主题标题和查看链接✅ 「删除回帖」
多条回帖被删除显示所有被删帖子的主题列表✅ 「删除回帖」
跨不同用户删除每个作者独立收到自己的通知✅
删除主题(整帖)由现有 send_topicadmin_notification_universal 处理—





4、重要技术沉淀

需更新到固化摘要:

  1. 十七、前台管理面板批量删帖邮件通知(2026-06-09)

  2. 功能:版主/管理员通过 modcp 批量删除回帖时,自动发送邮件通知被删帖用户
  3. 涉及文件:source/include/modcp/modcp_thread.php
  4. 触发位置:批量删除操作完成后、showmessage 之前
  5. 邮件格式:HTML,删除操作红色高亮
  6. 发送方式:异步邮件队列,不阻塞删除操作
复制代码


踩坑点:

踩坑正确做法
误以为 admincp_members.php 是批量删帖入口实际在 modcp_thread.php 的 $op == 'post' 分支
删除主题和删除回帖混在一起处理通过 $post['first'] 判断,主题由现有函数处理
邮件发送阻塞删除操作使用 common_mail_queue 异步队列





5、进一步优化可能性

  • 操作原因支持:前台管理面板目前不需要填写原因,如需增加可在表单中添加 reason 字段
  • 合并通知:同一用户短时间内多次被删帖,可合并为一封邮件
  • 版块开关:允许版主设置是否发送删除通知

不懂就搜!点此搜点拨论坛。如果本坛没有,请尝试点此问AI,或跟帖提问。
发帖前注意看置顶帖。
不定期借助AI对点拨论坛陈年老帖进行挖坟回复,打扰勿怪!
自己麻烦些,让帮你的人轻松些
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|点拨论坛 |网站地图

GMT+8, 2026-10-2 02:10 , Processed in 0.091407 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表