修改数据库管理

This commit is contained in:
邹景立 2022-10-28 10:50:11 +08:00
parent 58bbd06e15
commit 7d4983ca43
4 changed files with 22 additions and 28 deletions

View File

@ -17,9 +17,9 @@ class InstallAdminData extends Migrator
*/
public function change()
{
$this->createUser();
$this->createMenu();
$this->createConf();
$this->insertUser();
$this->insertMenu();
$this->insertConf();
}
/**
@ -27,7 +27,7 @@ class InstallAdminData extends Migrator
* @return void
* @throws \think\db\exception\DbException
*/
private function createUser()
private function insertUser()
{
// 检查是否存在
$map = ['username' => 'admin'];
@ -37,7 +37,7 @@ class InstallAdminData extends Migrator
// 初始化默认数据
SystemUser::mk()->save([
'id' => 10000,
'id' => '10000',
'username' => 'admin',
'nickname' => '超级管理员',
'password' => '21232f297a57a5a743894a0e4a801fc3',
@ -49,7 +49,7 @@ class InstallAdminData extends Migrator
* 初始化系统菜单
* @return void
*/
private function createMenu()
private function insertMenu()
{
// 初始化菜单数据
ToolsExtend::write2menu([
@ -85,11 +85,12 @@ class InstallAdminData extends Migrator
* @return void
* @throws \think\db\exception\DbException
*/
private function createConf()
private function insertConf()
{
if (SystemConfig::mk()->count()) {
return;
}
// 检查数据
if (SystemConfig::mk()->count()) return;
// 写入数据
SystemConfig::mk()->insertAll([
['type' => 'base', 'name' => 'app_name', 'value' => 'ThinkAdmin'],
['type' => 'base', 'name' => 'app_version', 'value' => 'v6'],

View File

@ -13,16 +13,16 @@ class InstallUserData extends Migrator
*/
public function change()
{
$this->createMenu();
$this->insertMenu();
}
/**
* 创建菜单
* @return boolean
* @return void
*/
protected function createMenu(): bool
protected function insertMenu()
{
return ToolsExtend::write2menu([
ToolsExtend::write2menu([
[
'name' => '控制台',
'sort' => '300',

View File

@ -1,6 +1,5 @@
<?php
use think\admin\Library;
use think\migration\Migrator;
/**
@ -9,12 +8,13 @@ use think\migration\Migrator;
class InstallUserRegion extends Migrator
{
/**
* 写入默认区域数据
* @return void
* @throws \think\db\exception\DbException
*/
public function change()
{
$this->createRegion();
$this->installRegion();
}
/**
@ -22,11 +22,12 @@ class InstallUserRegion extends Migrator
* @return void
* @throws \think\db\exception\DbException
*/
private function createRegion()
private function installRegion()
{
// 检查数据
$table = 'base_postage_region';
if (Library::$sapp->db->table($table)->count() > 0) return;
$result = $this->fetchRow("select count(1) _count from $table");
if (isset($result['_count']) && $result['_count'] > 0) return;
// 写入数据
$this->execute(<<<SQL

View File

@ -1,7 +1,6 @@
<?php
use think\admin\extend\ToolsExtend;
use think\admin\model\SystemMenu;
use think\migration\Migrator;
/**
@ -12,24 +11,17 @@ class InstallWechatData extends Migrator
/**
* 初始化数据
* @return void
* @throws \think\db\exception\DbException
*/
public function change()
{
$this->createMenu();
$this->insertMenu();
}
/**
* 初始化菜单
* @return void
* @throws \think\db\exception\DbException
*/
private function createMenu()
private function insertMenu()
{
// 检查菜单数据
$map = ['node' => 'wechat/config/options'];
if (SystemMenu::mk()->where($map)->count() > 0) return;
// 写入微信菜单
ToolsExtend::write2menu([
[