Discuz! 群組(Group)發文時,預設不會通知所有成員。需在發文流程中掛入通知邏輯,讓群組內每位成員收到系統提醒。
檔案:source/class/module/module_forum_thread.php
位置:post_new_thread() 方法結束前(約第 139 行),資料寫入成功後。
<?php
// 在 module_forum_thread.php 適當位置插入
if ($this->param['isgroup'] == 1) {
$subject = $this->param['subject']; // 主題標題
$author = $_G['username']; // 發文者
// 取得群組所有成員 UID
$query = DB::fetch_all('SELECT uid FROM ' . DB::table('forum_groupuser') . " WHERE fid={$this->forum['fid']}");
foreach ($query as $member) {
// 避免通知發文者自己
if ($member['uid'] == $_G['uid']) continue;
notification_add(
$member['uid'], // 接收者 UID
'system', // 通知類型:系統通知
$author . ' 發表了新主題:' . $subject, // 通知內容
[
'from_id' => 0,
'from_idtype' => 'sendnotice'
],
1 // $system = 1 系統通知
);
}
}
| 參數 | 說明 | 常用值 |
|---|---|---|
$touid | 接收通知的用戶 UID | 整數 |
$type | 通知類型 | system、pm、post、comment |
$note | 通知文字內容 | 字串 |
$notevars | 額外變數陣列,供模板渲染使用 | ['from_id' => $tid, 'from_idtype' => 'thread'] |
$system | 是否為系統通知(1=是,0=否) | 1 或 0 |
cron 或 task)分批發送,避免請求超時forum.php?mod=viewthread&tid={$tid},方便直接跳轉此修改基於 Discuz! X 系列(X3.4/X3.5)。若為 Discuz! 7.2/8.0,表名稱與欄位可能不同,請依實際資料庫結構調整 SQL。