Преглед на файлове

feat(message): 新增管理员消息通知功能
- 为 message_notifications 表新增 admin_id 字段用于关联管理员
- 修改 SendNotificationsHook 类中的方法名 handle 为 sendNotifications
- 实现 sendAdminNotifications 方法处理管理员消息通知插入逻辑
- 支持通过钩子 message.send_admin_notifications 发送管理员通知

runphp преди 4 месеца
родител
ревизия
1e98cf360a
променени са 2 файла, в които са добавени 44 реда и са изтрити 1 реда
  1. 26 0
      database/migrations/20251102123225_message_notificaction_admin_id.php
  2. 18 1
      src/Hook/SendNotificationsHook.php

+ 26 - 0
database/migrations/20251102123225_message_notificaction_admin_id.php

@@ -0,0 +1,26 @@
+<?php
+
+declare(strict_types=1);
+
+use Phinx\Migration\AbstractMigration;
+
+final class MessageNotificactionAdminId extends AbstractMigration
+{
+    /**
+     * Change Method.
+     *
+     * Write your reversible migrations using this method.
+     *
+     * More information on writing migrations is available here:
+     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
+     *
+     * Remember to call "create()" or "update()" and NOT "save()" when working
+     * with the Table class.
+     */
+    public function change(): void
+    {
+        $this->table('message_notifications')
+            ->addColumn('admin_id', 'integer', ['null' => true, 'after' => 'user_id', 'comment' => '管理员ID'])
+            ->update();
+    }
+}

+ 18 - 1
src/Hook/SendNotificationsHook.php

@@ -14,7 +14,7 @@ readonly class SendNotificationsHook
     }
 
     #[Hook('message.send_notifications')]
-    public function handle(array $params): void
+    public function sendNotifications(array $params): void
     {
         $msgList = [];
         foreach ($params as $msg) {
@@ -30,4 +30,21 @@ readonly class SendNotificationsHook
         }
         $msgList && $this->messageNotificationsEntity->insertAll($msgList);
     }
+
+    #[Hook('message.send_admin_notifications')]
+    public function sendAdminNotifications(array $params): void
+    {
+        $msgList = [];
+        foreach ($params as $msg) {
+            $msgList[] = [
+                'admin_id' => $msg['admin_id'],
+                'title' => $msg['title'],
+                'content' => $msg['content'],
+                'type' => NotificationsTypeEnum::from((int)$msg['type']),
+                'template_code' => $msg['template_code'],
+                'template_context' => $msg['template_context'],
+            ];
+        }
+        $msgList && $this->messageNotificationsEntity->insertAll($msgList);
+    }
 }