创建数据库

This commit is contained in:
邹景立 2022-10-27 11:29:24 +08:00
parent d72c26cba7
commit f518828cdc
3 changed files with 163 additions and 87 deletions

View File

@ -103,33 +103,6 @@ class InstallAdmin extends Migrator
->addIndex('type', ['name' => 'idx_system_config_type'])
->addIndex('name', ['name' => 'idx_system_config_name'])
->save();
// 初始化配置信息
$this->execute(<<<SQL
INSERT INTO {$table} VALUES (1, 'base', 'app_name', 'ThinkAdmin');
INSERT INTO {$table} VALUES (2, 'base', 'app_version', 'v6');
INSERT INTO {$table} VALUES (3, 'base', 'beian', '');
INSERT INTO {$table} VALUES (4, 'base', 'editor', 'ckeditor5');
INSERT INTO {$table} VALUES (5, 'base', 'login_image', '');
INSERT INTO {$table} VALUES (6, 'base', 'login_name', '系统管理');
INSERT INTO {$table} VALUES (7, 'base', 'miitbeian', '');
INSERT INTO {$table} VALUES (8, 'base', 'site_copy', '©版权所有 2014-2022 楚才科技');
INSERT INTO {$table} VALUES (9, 'base', 'site_host', '');
INSERT INTO {$table} VALUES (10, 'base', 'site_icon', 'https://v6.thinkadmin.top/upload/4b/5a423974e447d5502023f553ed370f.png');
INSERT INTO {$table} VALUES (11, 'base', 'site_name', 'ThinkAdmin');
INSERT INTO {$table} VALUES (12, 'base', 'site_theme', 'default');
INSERT INTO {$table} VALUES (13, 'base', 'xpath', 'admin');
INSERT INTO {$table} VALUES (14, 'storage', 'alioss_http_protocol', 'http');
INSERT INTO {$table} VALUES (15, 'storage', 'allow_exts', 'doc,gif,ico,jpg,mp3,mp4,p12,pem,png,zip,rar,xls,xlsx');
INSERT INTO {$table} VALUES (16, 'storage', 'link_type', 'none');
INSERT INTO {$table} VALUES (17, 'storage', 'local_http_domain', '');
INSERT INTO {$table} VALUES (18, 'storage', 'local_http_protocol', 'follow');
INSERT INTO {$table} VALUES (19, 'storage', 'name_type', 'xmd5');
INSERT INTO {$table} VALUES (20, 'storage', 'type', 'local');
INSERT INTO {$table} VALUES (21, 'wechat', 'type', 'api');
INSERT INTO {$table} VALUES (22, 'storage', 'qiniu_http_protocol', 'http');
SQL
);
}
private function _data()
@ -212,56 +185,6 @@ SQL
->addIndex('sort', ['name' => 'idx_system_menu_sort'])
->addIndex('status', ['name' => 'idx_system_menu_status'])
->save();
// 初始化菜单数据
$this->execute(<<<SQL
INSERT INTO {$table} VALUES (1, 0, '控制台', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (2, 1, '数据管理', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (3, 2, '数据统计报表', 'layui-icon layui-icon-theme', 'data/total.portal/index', 'data/total.portal/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (4, 2, '轮播图片管理', 'layui-icon layui-icon-carousel', 'data/base.slider/index', 'data/base.slider/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (5, 2, '页面内容管理', 'layui-icon layui-icon-read', 'data/base.pager/index', 'data/base.pager/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (6, 2, '文章内容管理', 'layui-icon layui-icon-template', 'data/news.item/index', 'data/news.item/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (7, 2, '支付参数管理', 'layui-icon layui-icon-rmb', 'data/base.payment/index', 'data/base.payment/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (8, 2, '系统通知管理', 'layui-icon layui-icon-notice', 'data/base.message/index', 'data/base.message/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (9, 2, '微信小程序配置', 'layui-icon layui-icon-set', 'data/base.config/wxapp', 'data/base.config/wxapp', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (10, 2, '邀请二维码设置', 'layui-icon layui-icon-cols', 'data/base.config/cropper', 'data/base.config/cropper', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (11, 1, '用户管理', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (12, 11, '会员用户管理', 'layui-icon layui-icon-user', 'data/user.admin/index', 'data/user.admin/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (13, 11, '余额充值管理', 'layui-icon layui-icon-rmb', 'data/user.balance/index', 'data/user.balance/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (14, 11, '用户返利管理', 'layui-icon layui-icon-transfer', 'data/user.rebate/index', 'data/user.rebate/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (15, 11, '用户提现管理', 'layui-icon layui-icon-component', 'data/user.transfer/index', 'data/user.transfer/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (16, 11, '用户等级管理', 'layui-icon layui-icon-senior', 'data/base.upgrade/index', 'data/base.upgrade/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (17, 11, '用户折扣方案', 'layui-icon layui-icon-set', 'data/base.discount/index', 'data/base.discount/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (18, 1, '商城管理', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (19, 18, '商品数据管理', 'layui-icon layui-icon-star', 'data/shop.goods/index', 'data/shop.goods/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (20, 18, '商品分类管理', 'layui-icon layui-icon-tabs', 'data/shop.cate/index', 'data/shop.cate/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (21, 18, '订单数据管理', 'layui-icon layui-icon-template', 'data/shop.order/index', 'data/shop.order/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (22, 18, '订单发货管理', 'layui-icon layui-icon-transfer', 'data/shop.send/index', 'data/shop.send/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (23, 18, '快递公司管理', 'layui-icon layui-icon-website', 'data/base.postage.company/index', 'data/base.postage.company/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (24, 18, '邮费模板管理', 'layui-icon layui-icon-template-1', 'data/base.postage.template/index', 'data/base.postage.template/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (25, 0, '微信管理', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (26, 25, '微信管理', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (27, 26, '微信接口配置', 'layui-icon layui-icon-set', '', 'wechat/config/options', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (28, 26, '微信支付配置', 'layui-icon layui-icon-rmb', '', 'wechat/config/payment', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (29, 25, '微信定制', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (30, 29, '微信粉丝管理', 'layui-icon layui-icon-username', '', 'wechat/fans/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (31, 29, '微信菜单配置', 'layui-icon layui-icon-cellphone', '', 'wechat/menu/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (32, 29, '微信图文管理', 'layui-icon layui-icon-template-1', '', 'wechat/news/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (33, 29, '回复规则管理', 'layui-icon layui-icon-engine', '', 'wechat/keys/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (34, 29, '关注自动回复', 'layui-icon layui-icon-release', 'wechat/auto/index', 'wechat/auto/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (35, 0, '系统管理', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (36, 35, '系统配置', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (37, 36, '系统参数配置', 'layui-icon layui-icon-set', '', 'admin/config/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (38, 36, '系统任务管理', 'layui-icon layui-icon-log', '', 'admin/queue/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (39, 36, '系统日志管理', 'layui-icon layui-icon-form', '', 'admin/oplog/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (40, 36, '数据字典管理', 'layui-icon layui-icon-code-circle', 'admin/base/index', 'admin/base/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (41, 36, '系统文件管理', 'layui-icon layui-icon-carousel', 'admin/file/index', 'admin/file/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (42, 36, '系统菜单管理', 'layui-icon layui-icon-layouts', '', 'admin/menu/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (43, 35, '权限管理', '', '', '#', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (44, 43, '访问权限管理', 'layui-icon layui-icon-vercode', '', 'admin/auth/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
INSERT INTO {$table} VALUES (45, 43, '系统用户管理', 'layui-icon layui-icon-username', '', 'admin/user/index', '', '_self', 0, 1, '2022-10-13 12:19:45');
SQL
);
}
private function _oplog()
@ -353,15 +276,5 @@ SQL
->addIndex('username', ['name' => 'idx_system_user_username'])
->addIndex('is_deleted', ['name' => 'idx_system_user_is_deleted'])
->save();
// 初始化默认数据
$data = [
'id' => 10000,
'username' => 'admin',
'nickname' => '超级管理员',
'password' => '21232f297a57a5a743894a0e4a801fc3',
'headimg' => 'https://thinkadmin.top/static/img/icon.png',
];
$this->table($table)->insert($data)->saveData();
}
}

View File

@ -0,0 +1,105 @@
<?php
use think\admin\extend\ToolsExtend;
use think\admin\model\SystemConfig;
use think\admin\model\SystemUser;
use think\migration\Migrator;
/**
* 系统模块初始化
*/
class InstallAdminData extends Migrator
{
/**
* 数据库初始化
* @return void
* @throws \think\db\exception\DbException
*/
public function change()
{
$this->_createUser();
$this->_createMenu();
$this->_createConf();
}
/**
* 初始化配置参数
* @return void
* @throws \think\db\exception\DbException
*/
private function _createConf()
{
if (SystemConfig::mk()->count()) {
return;
}
SystemConfig::mk()->insertAll([
['type' => 'base', 'name' => 'app_name', 'value' => 'ThinkAdmin'],
['type' => 'base', 'name' => 'app_version', 'value' => 'v6'],
['type' => 'base', 'name' => 'editor', 'value' => 'ckeditor5'],
['type' => 'base', 'name' => 'login_name', 'value' => '系统管理'],
['type' => 'base', 'name' => 'site_copy', 'value' => '©版权所有 2014-' . date('Y') . ' 楚才科技'],
['type' => 'base', 'name' => 'site_icon', 'value' => 'https://v6.thinkadmin.top/upload/4b/5a423974e447d5502023f553ed370f.png'],
['type' => 'base', 'name' => 'site_name', 'value' => 'ThinkAdmin'],
['type' => 'base', 'name' => 'site_theme', 'value' => 'default'],
['type' => 'storage', 'name' => 'allow_exts', 'value' => 'doc,gif,ico,jpg,mp3,mp4,p12,pem,png,zip,rar,xls,xlsx'],
['type' => 'storage', 'name' => 'type', 'value' => 'local'],
['type' => 'wechat', 'name' => 'type', 'value' => 'api'],
]);
}
/**
* 初始化用户数据
* @return void
* @throws \think\db\exception\DbException
*/
private function _createUser()
{
// 检查是否存在
$map = ['username' => 'admin'];
if (SystemUser::mk()->where($map)->count() > 0) {
return;
}
// 初始化默认数据
SystemUser::mk()->save([
'id' => 10000,
'username' => 'admin',
'nickname' => '超级管理员',
'password' => '21232f297a57a5a743894a0e4a801fc3',
'headimg' => 'https://thinkadmin.top/static/img/icon.png',
]);
}
// 创建系统菜单
private function _createMenu()
{
// 初始化菜单数据
ToolsExtend::write2menu([
[
'name' => '系统管理',
'subs' => [
[
'name' => '系统配置',
'subs' => [
['name' => '系统参数配置', 'icon' => 'layui-icon layui-icon-set', 'node' => 'admin/config/index'],
['name' => '系统任务管理', 'icon' => 'layui-icon layui-icon-log', 'node' => 'admin/queue/index'],
['name' => '系统日志管理', 'icon' => 'layui-icon layui-icon-form', 'node' => 'admin/oplog/index'],
['name' => '数据字典管理', 'icon' => 'layui-icon layui-icon-code-circle', 'node' => 'admin/module/index'],
['name' => '系统文件管理', 'icon' => 'layui-icon layui-icon-carousel', 'node' => 'admin/base/index'],
['name' => '系统菜单管理', 'icon' => 'layui-icon layui-icon-layouts', 'node' => 'admin/base/index'],
],
],
[
'name' => '权限管理',
'subs' => [
['name' => '访问权限管理', 'icon' => 'layui-icon layui-icon-vercode', 'node' => 'admin/auth/index'],
['name' => '系统用户管理', 'icon' => 'layui-icon layui-icon-username', 'node' => 'admin/user/index'],
],
],
],
],
], [
'node' => 'admin/config/index',
]);
}
}

View File

@ -0,0 +1,58 @@
<?php
use think\admin\extend\ToolsExtend;
use think\admin\model\SystemMenu;
use think\migration\Migrator;
/**
* 微信初始化
*/
class InstallWechatData extends Migrator
{
/**
* 改变数据库
* @return void
* @throws \think\db\exception\DbException
*/
public function change()
{
$this->createMenu();
}
/**
* 初始化数据库
* @return void
* @throws \think\db\exception\DbException
*/
private function createMenu()
{
$map = ['node' => 'wechat/config/options'];
if (SystemMenu::mk()->where($map)->count() > 0) {
return;
}
ToolsExtend::write2menu([
[
'name' => '微信管理',
'subs' => [
[
'name' => '微信管理',
'subs' => [
['name' => '微信接口配置', 'icon' => 'layui-icon layui-icon-set', 'node' => 'wechat/config/options'],
['name' => '微信支付配置', 'icon' => 'layui-icon layui-icon-rmb', 'node' => 'wechat/config/payment'],
],
],
[
'name' => '微信定制',
'subs' => [
['name' => '微信粉丝管理', 'icon' => 'layui-icon layui-icon-username', 'node' => 'wechat/fans/index'],
['name' => '微信图文管理', 'icon' => 'layui-icon layui-icon-template-1', 'node' => 'wechat/news/index'],
['name' => '微信菜单配置', 'icon' => 'layui-icon layui-icon-cellphone', 'node' => 'wechat/menu/index'],
['name' => '回复规则管理', 'icon' => 'layui-icon layui-icon-engine', 'node' => 'wechat/keys/index'],
['name' => '关注自动回复', 'icon' => 'layui-icon layui-icon-release', 'node' => 'wechat/auto/index'],
],
],
],
],
]);
}
}