Procházet zdrojové kódy

feat(message): 更新通知模板字段结构- 新增 template_context 字段用于存储模板上下文信息- 移除原有的 template_content 字段
- 修改数据表结构以支持 JSON 格式的模板上下文- 调整模型定义中的字段类型映射
- 更新发送通知钩子逻辑以传递模板代码和上下文- 修改测试用例以适配新的模板参数结构

runphp před 5 měsíci
rodič
revize
3c46f12be1

+ 27 - 0
database/migrations/20251015053004_notifications_template_context.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+use Phinx\Migration\AbstractMigration;
+
+final class NotificationsTemplateContext 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
+    {
+        $table = $this->table('message_notifications');
+        $table->addColumn('template_context', 'json', ['comment' => '模板上下文', 'after' => 'template_code'])
+            ->removeColumn('template_content')
+            ->update();
+    }
+}

+ 2 - 0
src/Hook/SendNotificationsHook.php

@@ -23,6 +23,8 @@ readonly class SendNotificationsHook
                 'title' => $msg['title'],
                 'content' => $msg['content'],
                 'type' => NotificationsTypeEnum::from((int)$msg['type']),
+                'template_code' => $msg['template_code'],
+                'template_context' => $msg['template_context'],
             ];
 
         }

+ 1 - 1
src/Model/MessageNotificationsModel.php

@@ -13,7 +13,7 @@ class MessageNotificationsModel extends Model
             'name' => 'message_notifications',
             'type' => [
                 'type' => NotificationsTypeEnum::class,
-                'template_content' => 'json'
+                'template_context' => 'json'
             ]
         ];
     }

+ 2 - 11
test/Hook/SendNotificationsHookTest.php

@@ -22,22 +22,13 @@ class SendNotificationsHookTest extends TestCase
     public function testHandle(): void
     {
         $this->event->trigger('message.send_notifications', [
-            [
-                'user_id' => 1,
-                'title' => 'test',
-                'content' => 'test',
-                'type' => 2,
-            ], [
-                'user_id' => 1,
-                'title' => 'test',
-                'content' => 'test',
-                'type' => 1,
-            ],
             [
                 'user_id' => 1,
                 'title' => 'test',
                 'content' => 'test',
                 'type' => 5,
+                'template_code' => 'fasfsad',
+                'template_context' => ['abd'=>123],
             ]
         ]);
     }