You've already forked think-plugs-notice
84 lines
3.2 KiB
PHP
84 lines
3.2 KiB
PHP
<?php
|
|
|
|
use think\admin\extend\PhinxExtend;
|
|
use think\migration\Migrator;
|
|
|
|
@set_time_limit(0);
|
|
@ini_set('memory_limit', -1);
|
|
|
|
class InstallNoticeTable extends Migrator
|
|
{
|
|
|
|
/**
|
|
* 获取脚本名称
|
|
* @return string
|
|
*/
|
|
public function getName(): string
|
|
{
|
|
return 'NoticePlugin';
|
|
}
|
|
|
|
/**
|
|
* 创建数据库
|
|
*/
|
|
public function change()
|
|
{
|
|
$this->_create_notice();
|
|
$this->_create_broadcast();
|
|
}
|
|
|
|
/**
|
|
* 创建数据对象
|
|
* @table notice_notice
|
|
* @return void
|
|
*/
|
|
private function _create_notice()
|
|
{
|
|
// 创建数据表对象
|
|
$table = $this->table('notice_notice', [
|
|
'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '消息通知',
|
|
]);
|
|
// 创建或更新数据表
|
|
PhinxExtend::upgrade($table, [
|
|
['staff_id', 'integer', ['default' => NULL, 'null' => false, 'comment' => '员工ID']],
|
|
['type', 'string', ['limit' => 255, 'default' => NULL, 'null' => true, 'comment' => '类型']],
|
|
['content', 'string', ['limit' => 255, 'default' => NULL, 'null' => true, 'comment' => '信息内容']],
|
|
['link', 'string', ['limit' => 255, 'default' => NULL, 'null' => true, 'comment' => '跳转链接(如果有)']],
|
|
['create_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP', 'null' => false, 'comment' => '创建时间']],
|
|
['read_at', 'datetime', ['default' => NULL, 'null' => true, 'comment' => '已读时间']],
|
|
], [
|
|
'type', 'staff_id',
|
|
], false);
|
|
}
|
|
|
|
/**
|
|
* 创建数据对象
|
|
* @table notice_broadcast
|
|
* @return void
|
|
*/
|
|
private function _create_broadcast()
|
|
{
|
|
// 创建数据表对象
|
|
$table = $this->table('notice_broadcast', [
|
|
'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '通知公告',
|
|
]);
|
|
// 创建或更新数据表
|
|
PhinxExtend::upgrade($table, [
|
|
['to_all', 'tinyinteger', ['limit' => 4, 'default' => 0, 'null' => false, 'comment' => '是否发送给所有人']],
|
|
['to_depts', 'string', ['limit' => 255, 'default' => NULL, 'null' => true, 'comment' => '要发送的部门']],
|
|
['to_users', 'string', ['limit' => 255, 'default' => NULL, 'null' => true, 'comment' => '要发送的用户']],
|
|
['to', 'text', ['default' => NULL, 'null' => false, 'comment' => '对外的发送到']],
|
|
['title', 'string', ['limit' => 255, 'default' => NULL, 'null' => false, 'comment' => '标题']],
|
|
['type', 'string', ['limit' => 255, 'default' => NULL, 'null' => true, 'comment' => '类型']],
|
|
['content', 'text', ['default' => NULL, 'null' => true, 'comment' => '内容']],
|
|
['files', 'string', ['limit' => 255, 'default' => NULL, 'null' => true, 'comment' => '附件']],
|
|
['create_at', 'datetime', ['default' => 'CURRENT_TIMESTAMP', 'null' => false, 'comment' => '']],
|
|
['create_by', 'integer', ['limit' => 11, 'default' => 0, 'null' => false, 'comment' => '创建人ID']],
|
|
['is_deleted', 'tinyinteger', ['limit' => 4, 'default' => 0, 'null' => false, 'comment' => '是否已删除']],
|
|
], [
|
|
'type'
|
|
], false);
|
|
}
|
|
|
|
}
|