table('message_announcements', [ 'engine' => 'InnoDB', 'comment' => '系统公告表', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ]) ->addColumn('title', 'string', ['limit' => 255, 'null' => false, 'comment' => '公告标题']) ->addColumn('content', 'text', ['null' => false, 'comment' => '公告内容']) ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '状态:0-禁用,1-启用']) ->addColumn('type', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '类型:1-普通公告,2-重要公告,3-紧急公告']) ->addColumn('start_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '开始时间']) ->addColumn('end_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '结束时间']) ->addColumn('create_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '创建时间']) ->addColumn('update_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '更新时间']) ->addColumn('delete_time', 'integer', ['null' => true, 'comment' => '删除时间']) ->create(); // 创建用户通知表 $this->table('message_notifications', [ 'engine' => 'InnoDB', 'comment' => '用户通知表', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ]) ->addColumn('user_id', 'integer', ['limit' => 11, 'default' => 0, 'null' => false, 'comment' => '用户ID,0表示全部用户']) ->addColumn('title', 'string', ['limit' => 255, 'null' => false, 'comment' => '通知标题']) ->addColumn('content', 'text', ['null' => false, 'comment' => '通知内容']) ->addColumn('type', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '类型:1-系统通知,2-活动通知,3-订单通知,4-物流通知,5-其他']) ->addColumn('is_read', 'integer', ['limit' => 1, 'default' => 0, 'null' => false, 'comment' => '是否已读:0-未读,1-已读']) ->addColumn('read_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '阅读时间']) ->addColumn('create_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '创建时间']) ->addColumn('update_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '更新时间']) ->addColumn('delete_time', 'integer', ['null' => true, 'comment' => '删除时间']) ->addIndex(['user_id'], ['name' => 'idx_user_id']) ->create(); // 创建私信表 $this->table('message_privates', [ 'engine' => 'InnoDB', 'comment' => '私信表', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ]) ->addColumn('from_user_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '发送者用户ID,0表示系统']) ->addColumn('to_user_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '接收者用户ID']) ->addColumn('content', 'text', ['null' => false, 'comment' => '私信内容']) ->addColumn('is_read', 'integer', ['limit' => 1, 'default' => 0, 'null' => false, 'comment' => '是否已读:0-未读,1-已读']) ->addColumn('read_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '阅读时间']) ->addColumn('create_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '创建时间']) ->addColumn('update_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '更新时间']) ->addColumn('delete_time', 'integer', ['null' => true, 'comment' => '删除时间']) ->addIndex(['from_user_id'], ['name' => 'idx_from_user_id']) ->addIndex(['to_user_id'], ['name' => 'idx_to_user_id']) ->create(); // 创建消息设置表 $this->table('message_settings', [ 'engine' => 'InnoDB', 'comment' => '消息设置表', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ]) ->addColumn('user_id', 'integer', ['limit' => 11, 'null' => false, 'comment' => '用户ID,0表示系统默认设置']) ->addColumn('system_notify', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '系统通知:0-关闭,1-开启']) ->addColumn('activity_notify', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '活动通知:0-关闭,1-开启']) ->addColumn('order_notify', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '订单通知:0-关闭,1-开启']) ->addColumn('logistics_notify', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '物流通知:0-关闭,1-开启']) ->addColumn('private_message', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '私信:0-关闭,1-开启']) ->addColumn('create_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '创建时间']) ->addColumn('update_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '更新时间']) ->addIndex(['user_id'], ['name' => 'idx_user_id', 'unique' => true]) ->create(); // 创建消息模板表 $this->table('message_templates', [ 'engine' => 'InnoDB', 'comment' => '消息模板表', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci', ]) ->addColumn('code', 'string', ['limit' => 50, 'null' => false, 'comment' => '模板代码']) ->addColumn('name', 'string', ['limit' => 100, 'null' => false, 'comment' => '模板名称']) ->addColumn('title', 'string', ['limit' => 255, 'null' => false, 'comment' => '标题模板']) ->addColumn('content', 'text', ['null' => false, 'comment' => '内容模板']) ->addColumn('type', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '类型:1-系统通知,2-活动通知,3-订单通知,4-物流通知,5-私信,6-其他']) ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'null' => false, 'comment' => '状态:0-禁用,1-启用']) ->addColumn('create_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '创建时间']) ->addColumn('update_time', 'integer', ['default' => 0, 'null' => false, 'comment' => '更新时间']) ->addIndex(['code'], ['name' => 'idx_code', 'unique' => true]) ->create(); // 插入默认消息模板数据 $currentTime = time(); $this->table('message_templates') ->insert([ [ 'code' => 'system_welcome', 'name' => '欢迎注册', 'title' => '欢迎加入{site_name}', 'content' => '亲爱的{user_name},欢迎您加入{site_name},祝您购物愉快!', 'type' => 1, 'status' => 1, 'create_time' => $currentTime, 'update_time' => $currentTime ], [ 'code' => 'order_created', 'name' => '订单创建', 'title' => '您的订单已创建', 'content' => '亲爱的{user_name},您的订单{order_no}已创建成功,请及时支付。', 'type' => 3, 'status' => 1, 'create_time' => $currentTime, 'update_time' => $currentTime ], [ 'code' => 'order_paid', 'name' => '订单支付', 'title' => '您的订单已支付', 'content' => '亲爱的{user_name},您的订单{order_no}已支付成功,我们将尽快为您发货。', 'type' => 3, 'status' => 1, 'create_time' => $currentTime, 'update_time' => $currentTime ], [ 'code' => 'order_shipped', 'name' => '订单发货', 'title' => '您的订单已发货', 'content' => '亲爱的{user_name},您的订单{order_no}已发货,物流单号:{tracking_no}。', 'type' => 4, 'status' => 1, 'create_time' => $currentTime, 'update_time' => $currentTime ], [ 'code' => 'order_completed', 'name' => '订单完成', 'title' => '您的订单已完成', 'content' => '亲爱的{user_name},您的订单{order_no}已完成,感谢您的购买!', 'type' => 3, 'status' => 1, 'create_time' => $currentTime, 'update_time' => $currentTime ] ]) ->save(); // 插入默认系统设置 $this->table('message_settings') ->insert([ [ 'user_id' => 0, 'system_notify' => 1, 'activity_notify' => 1, 'order_notify' => 1, 'logistics_notify' => 1, 'private_message' => 1, 'create_time' => $currentTime, 'update_time' => $currentTime ] ]) ->save(); } /** * 回滚迁移 */ public function down() { $this->table('message_announcements')->drop(); $this->table('message_notifications')->drop(); $this->table('message_privates')->drop(); $this->table('message_settings')->drop(); $this->table('message_templates')->drop(); } }