소스 검색

feat(message): 添加通知模板内容字段并更新模型定义

- 在 message_notifications 表中新增 template_code 和 template_content 字段
- 更新 MessageNotificationsModel 模型以支持 template_content JSON 类型
- 移除旧版数据库安装与卸载 SQL 脚本- 引入 Phinx 迁移文件管理通知模板结构变更
runphp 5 달 전
부모
커밋
7b0e68ab80
4개의 변경된 파일28개의 추가작업 그리고 102개의 파일을 삭제
  1. 0 88
      database/install.sql
  2. 27 0
      database/migrations/20251015013049_notifications_template.php
  3. 0 14
      database/uninstall.sql
  4. 1 0
      src/Model/MessageNotificationsModel.php

+ 0 - 88
database/install.sql

@@ -1,88 +0,0 @@
--- 系统公告表
-CREATE TABLE IF NOT EXISTS `cy_message_announcements` (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '公告ID',
-  `title` varchar(255) NOT NULL COMMENT '公告标题',
-  `content` text NOT NULL COMMENT '公告内容',
-  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态:0-禁用,1-启用',
-  `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '类型:1-普通公告,2-重要公告,3-紧急公告',
-  `start_time` int(11) NOT NULL DEFAULT '0' COMMENT '开始时间',
-  `end_time` int(11) NOT NULL DEFAULT '0' COMMENT '结束时间',
-  `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
-  `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
-  `delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统公告表';
-
--- 用户通知表
-CREATE TABLE IF NOT EXISTS `cy_message_notifications` (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '通知ID',
-  `user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID,0表示全部用户',
-  `title` varchar(255) NOT NULL COMMENT '通知标题',
-  `content` text NOT NULL COMMENT '通知内容',
-  `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '类型:1-系统通知,2-活动通知,3-订单通知,4-物流通知,5-其他',
-  `is_read` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已读:0-未读,1-已读',
-  `read_time` int(11) NOT NULL DEFAULT '0' COMMENT '阅读时间',
-  `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
-  `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
-  `delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
-  PRIMARY KEY (`id`),
-  KEY `idx_user_id` (`user_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户通知表';
-
--- 私信表
-CREATE TABLE IF NOT EXISTS `cy_message_privates` (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '私信ID',
-  `from_user_id` int(11) unsigned NOT NULL COMMENT '发送者用户ID,0表示系统',
-  `to_user_id` int(11) unsigned NOT NULL COMMENT '接收者用户ID',
-  `content` text NOT NULL COMMENT '私信内容',
-  `is_read` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已读:0-未读,1-已读',
-  `read_time` int(11) NOT NULL DEFAULT '0' COMMENT '阅读时间',
-  `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
-  `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
-  `delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
-  PRIMARY KEY (`id`),
-  KEY `idx_from_user_id` (`from_user_id`),
-  KEY `idx_to_user_id` (`to_user_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='私信表';
-
--- 消息设置表
-CREATE TABLE IF NOT EXISTS `cy_message_settings` (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '设置ID',
-  `user_id` int(11) unsigned NOT NULL COMMENT '用户ID,0表示系统默认设置',
-  `system_notify` tinyint(1) NOT NULL DEFAULT '1' COMMENT '系统通知:0-关闭,1-开启',
-  `activity_notify` tinyint(1) NOT NULL DEFAULT '1' COMMENT '活动通知:0-关闭,1-开启',
-  `order_notify` tinyint(1) NOT NULL DEFAULT '1' COMMENT '订单通知:0-关闭,1-开启',
-  `logistics_notify` tinyint(1) NOT NULL DEFAULT '1' COMMENT '物流通知:0-关闭,1-开启',
-  `private_message` tinyint(1) NOT NULL DEFAULT '1' COMMENT '私信:0-关闭,1-开启',
-  `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
-  `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
-  PRIMARY KEY (`id`),
-  UNIQUE KEY `idx_user_id` (`user_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息设置表';
-
--- 消息模板表
-CREATE TABLE IF NOT EXISTS `cy_message_templates` (
-  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '模板ID',
-  `code` varchar(50) NOT NULL COMMENT '模板代码',
-  `name` varchar(100) NOT NULL COMMENT '模板名称',
-  `title` varchar(255) NOT NULL COMMENT '标题模板',
-  `content` text NOT NULL COMMENT '内容模板',
-  `type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '类型:1-系统通知,2-活动通知,3-订单通知,4-物流通知,5-私信,6-其他',
-  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态:0-禁用,1-启用',
-  `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
-  `update_time` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
-  PRIMARY KEY (`id`),
-  UNIQUE KEY `idx_code` (`code`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='消息模板表';
-
--- 插入默认消息模板数据
-INSERT INTO `cy_message_templates` (`code`, `name`, `title`, `content`, `type`, `status`, `create_time`, `update_time`) VALUES
-('system_welcome', '欢迎注册', '欢迎加入{site_name}', '亲爱的{user_name},欢迎您加入{site_name},祝您购物愉快!', 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
-('order_created', '订单创建', '您的订单已创建', '亲爱的{user_name},您的订单{order_no}已创建成功,请及时支付。', 3, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
-('order_paid', '订单支付', '您的订单已支付', '亲爱的{user_name},您的订单{order_no}已支付成功,我们将尽快为您发货。', 3, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
-('order_shipped', '订单发货', '您的订单已发货', '亲爱的{user_name},您的订单{order_no}已发货,物流单号:{tracking_no}。', 4, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
-('order_completed', '订单完成', '您的订单已完成', '亲爱的{user_name},您的订单{order_no}已完成,感谢您的购买!', 3, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());
-
--- 插入默认系统设置
-INSERT INTO `cy_message_settings` (`user_id`, `system_notify`, `activity_notify`, `order_notify`, `logistics_notify`, `private_message`, `create_time`, `update_time`) VALUES
-(0, 1, 1, 1, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP());

+ 27 - 0
database/migrations/20251015013049_notifications_template.php

@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+use Phinx\Migration\AbstractMigration;
+
+final class NotificationsTemplate 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_code', 'string', ['limit' => 64, 'comment' => '模板代码'])
+            ->addColumn('template_content', 'json', ['comment' => '模板内容'])
+            ->update();
+    }
+}

+ 0 - 14
database/uninstall.sql

@@ -1,14 +0,0 @@
--- 删除系统公告表
-DROP TABLE IF EXISTS `cy_message_announcements`;
-
--- 删除用户通知表
-DROP TABLE IF EXISTS `cy_message_notifications`;
-
--- 删除私信表
-DROP TABLE IF EXISTS `cy_message_privates`;
-
--- 删除消息设置表
-DROP TABLE IF EXISTS `cy_message_settings`;
-
--- 删除消息模板表
-DROP TABLE IF EXISTS `cy_message_templates`;

+ 1 - 0
src/Model/MessageNotificationsModel.php

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