删除旧的安装方式;

This commit is contained in:
2022-04-19 22:45:53 +08:00
parent f9ff73a631
commit fc885a0343
9 changed files with 187 additions and 1289 deletions

View File

@@ -53,8 +53,14 @@ DEBUG=true
PREFIX=ul_
第四步, 执行数据库导入
php think install
第四步, 安装数据库
php think migrate:run
第五步,初始化数据库数据
php think seed:run
最后,本地临时运行
php think run
```

View File

@@ -1,168 +0,0 @@
<?php
declare(strict_types=1);
namespace app\common\command;
use app\common\tools\PathTools;
use PDO;
use think\Config as ThinkConfig;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\facade\App;
use think\facade\Config;
use think\facade\Db;
class Install extends Command
{
protected $installLockPath = null;
protected function configure()
{
// 指令配置
$this->setName('install')
->addOption('adminname', 'u', Option::VALUE_OPTIONAL, '管理员账号')
->addOption('password', 'p', Option::VALUE_OPTIONAL, '管理员密码')
->addOption('force', 'f', Option::VALUE_OPTIONAL, '强制安装')
->setDescription('安装数据库');
$this->installLockPath = App::getRootPath() . '/config/install/lock/install.lock';
}
protected function execute(Input $input, Output $output)
{
// 指令输出
$force = $input->getOption('force');
if (is_null($force)) {
$install_lock_path = $this->installLockPath;
if (is_file($install_lock_path)) {
$errorInfo = '已安装系统,如需重新安装,可以添加 -f 1 参数或删除文件:/config/install/lock/install.lock';
$output->writeln($errorInfo);
return false;
}
}
if (!$this->checkConnect()) {
$output->writeln('数据库连接失败,请检查数据库配置');
}
$adminname = $input->getOption('adminname') ?: 'admin';
$password = $input->getOption('password') ?: 'admin';
$install_result = $this->install($adminname, $password);
if ($install_result !== true) {
$output->writeln($install_result);
return false;
}
}
protected function install($username, $password)
{
$install_lock_path = $this->installLockPath;
$sql_path = App::getRootPath() . '/config/install/sql/install.sql';
$sql_content = file_get_contents($sql_path);
$sqlArray = $this->parseSql($sql_content);
Db::startTrans();
try {
foreach ($sqlArray as $vo) {
if (strpos($vo, 'LOCK TABLES') === 0) {
continue;
}
if (strpos($vo, 'UNLOCK') === 0) {
continue;
}
Db::execute($vo);
}
Db::name('system_admin')
->where('id', 1)
->delete();
Db::name('system_admin')
->insert([
'id' => 1,
'username' => $username,
'head_img' => '/static/admin/images/head.jpg',
'password' => password($password),
'create_time' => time(),
]);
// 处理安装文件
PathTools::intiDir($install_lock_path);
@file_put_contents($install_lock_path, date('Y-m-d H:i:s'));
Db::commit();
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
return true;
}
public function checkConnect()
{
try {
Db::query("select version()");
} catch (\Exception $e) {
return false;
}
return true;
}
public function parseSql($sql = '')
{
list($pure_sql, $comment) = [[], false];
$sql = explode("\n", trim(str_replace(["\r\n", "\r"], "\n", $sql)));
$prefix = Config::get('database.connections.' . Config::get('database.default') . '.prefix');
foreach ($sql as $key => $line) {
if ($line == '') {
continue;
}
if (preg_match("/^(#|--)/", $line)) {
continue;
}
if (preg_match("/^\/\*(.*?)\*\//", $line)) {
continue;
}
if (substr($line, 0, 2) == '/*') {
$comment = true;
continue;
}
if (substr($line, -2) == '*/') {
$comment = false;
continue;
}
if ($comment) {
continue;
}
$line = str_replace('`ul_', '`' . $prefix, $line);
if ($line == 'BEGIN;' || $line == 'COMMIT;') {
continue;
}
array_push($pure_sql, $line);
}
//$pure_sql = implode($pure_sql, "\n");
$pure_sql = implode("\n", $pure_sql);
$pure_sql = explode(";\n", $pure_sql);
return $pure_sql;
}
}

View File

@@ -4,7 +4,6 @@
// +----------------------------------------------------------------------
use app\common\command\admin\ResetPassword;
use app\common\command\Install;
use app\common\command\Timer;
return [
@@ -14,7 +13,6 @@ return [
'node' => 'app\common\command\Node',
'OssStatic' => 'app\common\command\OssStatic',
ResetPassword::class,
Install::class,
Timer::class,
],
];

View File

@@ -1,10 +1,11 @@
<?php
use think\facade\App;
use think\facade\Env;
return [
// 默认使用的数据库连接配置
'default' => Env::get('database.driver', 'mysql'),
'default' => Env::get('database.driver', 'sqlite'),
// 自定义时间查询规则
'time_query_rule' => [],
@@ -58,6 +59,45 @@ return [
],
'sqlite' => [
// 数据库类型
'type' => 'sqlite',
// 服务器地址
'hostname' => Env::get('root_path').'ul.db',
// 数据库名
'database' => App::getRootPath().'ul.db',
// 用户名
'username' => Env::get('database.username', ''),
// 密码
'password' => Env::get('database.password', ''),
// 端口
'hostport' => Env::get('database.hostport', '3306'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => Env::get('database.charset', 'utf8'),
// 数据库表前缀
'prefix' => Env::get('database.prefix', 'ul_'),
// 数据库调试模式
'debug' => Env::get('database.debug', true),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要进行SQL性能分析
'sql_explain' => false,
// 是否需要断线重连
'break_reconnect' => false,
],
// 更多的数据库配置信息
],
];

View File

@@ -1,401 +0,0 @@
-- MySQL dump 10.13 Distrib 5.5.62, for Win64 (AMD64)
--
-- Host: 47.96.111.169 Database: admin_demo_ultho
-- ------------------------------------------------------
-- Server version 5.6.46-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `ul_debug_log`
--
DROP TABLE IF EXISTS `ul_debug_log`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_debug_log` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` varchar(30) NOT NULL DEFAULT '',
`level` varchar(30) NOT NULL DEFAULT '',
`create_time` int(10) unsigned NOT NULL DEFAULT '0',
`create_time_title` varchar(30) NOT NULL DEFAULT '',
`content` text NOT NULL,
`app_name` varchar(30) NOT NULL DEFAULT '',
`controller_name` varchar(30) NOT NULL DEFAULT '',
`action_name` varchar(30) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `ul_debug_log_create_time_IDX` (`create_time`) USING BTREE,
KEY `ul_debug_log_uid_IDX` (`uid`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='日志表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_debug_log`
--
LOCK TABLES `ul_debug_log` WRITE;
/*!40000 ALTER TABLE `ul_debug_log` DISABLE KEYS */;
/*!40000 ALTER TABLE `ul_debug_log` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_mall_cate`
--
DROP TABLE IF EXISTS `ul_mall_cate`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_mall_cate` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(20) NOT NULL COMMENT '分类名',
`image` varchar(500) DEFAULT NULL COMMENT '分类图片',
`sort` int(11) DEFAULT '0' COMMENT '排序',
`status` tinyint(1) unsigned DEFAULT '1' COMMENT '状态(1:禁用,2:启用)',
`remark` varchar(255) DEFAULT NULL COMMENT '备注说明',
`create_time` int(11) DEFAULT NULL COMMENT '创建时间',
`update_time` int(11) DEFAULT NULL COMMENT '更新时间',
`delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
UNIQUE KEY `title` (`title`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='商品分类';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_mall_cate`
--
LOCK TABLES `ul_mall_cate` WRITE;
/*!40000 ALTER TABLE `ul_mall_cate` DISABLE KEYS */;
INSERT INTO `ul_mall_cate` VALUES (9,'手机','http://admin.host/upload/20200514/98fc09b0c4ad4d793a6f04bef79a0edc.jpg',0,1,'',1589440437,1589440437,NULL);
/*!40000 ALTER TABLE `ul_mall_cate` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_mall_goods`
--
DROP TABLE IF EXISTS `ul_mall_goods`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_mall_goods` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`cate_id` int(11) DEFAULT NULL COMMENT '分类ID',
`title` varchar(20) NOT NULL COMMENT '商品名称',
`logo` varchar(500) DEFAULT NULL COMMENT '商品logo',
`images` text COMMENT '商品图片 以 | 做分割符号',
`describe` text COMMENT '商品描述',
`market_price` decimal(10,2) DEFAULT '0.00' COMMENT '市场价',
`discount_price` decimal(10,2) DEFAULT '0.00' COMMENT '折扣价',
`sales` int(11) DEFAULT '0' COMMENT '销量',
`virtual_sales` int(11) DEFAULT '0' COMMENT '虚拟销量',
`stock` int(11) DEFAULT '0' COMMENT '库存',
`total_stock` int(11) DEFAULT '0' COMMENT '总库存',
`sort` int(11) DEFAULT '0' COMMENT '排序',
`status` tinyint(1) unsigned DEFAULT '1' COMMENT '状态(1:禁用,2:启用)',
`remark` varchar(255) DEFAULT NULL COMMENT '备注说明',
`create_time` int(11) DEFAULT NULL COMMENT '创建时间',
`update_time` int(11) DEFAULT NULL COMMENT '更新时间',
`delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
KEY `cate_id` (`cate_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='商品列表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_mall_goods`
--
LOCK TABLES `ul_mall_goods` WRITE;
/*!40000 ALTER TABLE `ul_mall_goods` DISABLE KEYS */;
INSERT INTO `ul_mall_goods` VALUES (8,10,'落地-风扇','http://admin.host/upload/20200514/a0f7fe9637abd219f7e93ceb2820df9b.jpg','http://admin.host/upload/20200514/95496713918290f6315ea3f87efa6bf2.jpg|http://admin.host/upload/20200514/ae29fa9cba4fc02defb7daed41cb2b13.jpg|http://admin.host/upload/20200514/f0a104d88ec7dc6fb42d2f87cbc71b76.jpg|http://admin.host/upload/20200514/3b88be4b1934690e5c1bd6b54b9ab5c8.jpg','<p>76654757</p>\n\n<p><img alt=\"\" src=\"http://admin.host/upload/20200515/198070421110fa01f2c2ac2f52481647.jpg\" style=\"height:689px; width:790px\" /></p>\n\n<p><img alt=\"\" src=\"http://admin.host/upload/20200515/a07a742c15a78781e79f8a3317006c1d.jpg\" style=\"height:877px; width:790px\" /></p>\n',599.00,368.00,0,594,0,0,675,1,'',1589454309,1589567016,NULL),(9,9,'电脑','http://admin.host/upload/20200514/bbf858d469dec2e12a89460110068d3d.jpg','http://admin.host/upload/20200514/f0a104d88ec7dc6fb42d2f87cbc71b76.jpg','<p>477</p>\n',0.00,0.00,0,0,115,320,0,1,'',1589465215,1589476345,NULL);
/*!40000 ALTER TABLE `ul_mall_goods` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_system_admin`
--
DROP TABLE IF EXISTS `ul_system_admin`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_system_admin` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`auth_ids` varchar(255) DEFAULT NULL COMMENT '角色权限ID',
`head_img` varchar(255) DEFAULT NULL COMMENT '头像',
`username` varchar(50) NOT NULL DEFAULT '' COMMENT '用户登录名',
`password` char(40) NOT NULL DEFAULT '' COMMENT '用户登录密码',
`phone` varchar(16) DEFAULT NULL COMMENT '联系手机号',
`remark` varchar(255) DEFAULT '' COMMENT '备注说明',
`login_num` bigint(20) unsigned DEFAULT '0' COMMENT '登录次数',
`sort` int(11) DEFAULT '0' COMMENT '排序',
`status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态(0:禁用,1:启用,)',
`create_time` int(11) DEFAULT NULL COMMENT '创建时间',
`update_time` int(11) DEFAULT NULL COMMENT '更新时间',
`delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`) USING BTREE,
KEY `phone` (`phone`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='系统用户表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_system_admin`
--
LOCK TABLES `ul_system_admin` WRITE;
/*!40000 ALTER TABLE `ul_system_admin` DISABLE KEYS */;
INSERT INTO `ul_system_admin` VALUES (1,NULL,'/static/admin/images/head.jpg','admin','a33b679d5581a8692988ec9f92ad2d6a2259eaa7',NULL,'',0,0,1,1648970786,NULL,NULL);
/*!40000 ALTER TABLE `ul_system_admin` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_system_auth`
--
DROP TABLE IF EXISTS `ul_system_auth`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_system_auth` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(20) NOT NULL COMMENT '权限名称',
`sort` int(11) DEFAULT '0' COMMENT '排序',
`status` tinyint(1) unsigned DEFAULT '1' COMMENT '状态(1:禁用,2:启用)',
`remark` varchar(255) DEFAULT NULL COMMENT '备注说明',
`create_time` int(11) DEFAULT NULL COMMENT '创建时间',
`update_time` int(11) DEFAULT NULL COMMENT '更新时间',
`delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
UNIQUE KEY `title` (`title`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='系统权限表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_system_auth`
--
LOCK TABLES `ul_system_auth` WRITE;
/*!40000 ALTER TABLE `ul_system_auth` DISABLE KEYS */;
INSERT INTO `ul_system_auth` VALUES (1,'管理员',1,1,'测试管理员',1588921753,1589614331,NULL),(6,'游客权限',0,1,'',1588227513,1589591751,1589591751);
/*!40000 ALTER TABLE `ul_system_auth` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_system_auth_node`
--
DROP TABLE IF EXISTS `ul_system_auth_node`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_system_auth_node` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`auth_id` bigint(20) unsigned DEFAULT NULL COMMENT '角色ID',
`node_id` bigint(20) DEFAULT NULL COMMENT '节点ID',
PRIMARY KEY (`id`),
KEY `index_system_auth_auth` (`auth_id`) USING BTREE,
KEY `index_system_auth_node` (`node_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='角色与节点关系表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_system_auth_node`
--
LOCK TABLES `ul_system_auth_node` WRITE;
/*!40000 ALTER TABLE `ul_system_auth_node` DISABLE KEYS */;
INSERT INTO `ul_system_auth_node` VALUES (1,6,1),(2,6,2),(3,6,9),(4,6,12),(5,6,18),(6,6,19),(7,6,21),(8,6,22),(9,6,29),(10,6,30),(11,6,38),(12,6,39),(13,6,45),(14,6,46),(15,6,52),(16,6,53);
/*!40000 ALTER TABLE `ul_system_auth_node` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_system_config`
--
DROP TABLE IF EXISTS `ul_system_config`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_system_config` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL DEFAULT '' COMMENT '变量名',
`group` varchar(30) NOT NULL DEFAULT '' COMMENT '分组',
`value` text COMMENT '变量值',
`remark` varchar(100) DEFAULT '' COMMENT '备注信息',
`sort` int(10) DEFAULT '0',
`create_time` int(11) DEFAULT NULL COMMENT '创建时间',
`update_time` int(11) DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `group` (`group`)
) ENGINE=InnoDB AUTO_INCREMENT=90 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='系统配置表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_system_config`
--
LOCK TABLES `ul_system_config` WRITE;
/*!40000 ALTER TABLE `ul_system_config` DISABLE KEYS */;
INSERT INTO `ul_system_config` VALUES (41,'alisms_access_key_id','sms','填你的','阿里大于公钥',0,NULL,NULL),(42,'alisms_access_key_secret','sms','填你的','阿里大鱼私钥',0,NULL,NULL),(55,'upload_type','upload','local','当前上传方式 local,alioss,qnoss,txoss',0,NULL,NULL),(56,'upload_allow_ext','upload','doc,gif,ico,icon,jpg,mp3,mp4,p12,pem,png,rar,jpeg','允许上传的文件类型',0,NULL,NULL),(57,'upload_allow_size','upload','1024000','允许上传的大小',0,NULL,NULL),(58,'upload_allow_mime','upload','image/gif,image/jpeg,video/x-msvideo,text/plain,image/png','允许上传的文件mime',0,NULL,NULL),(59,'upload_allow_type','upload','local,alioss,qnoss,txcos','可用的上传文件方式',0,NULL,NULL),(60,'alioss_access_key_id','upload','填你的','阿里云oss公钥',0,NULL,NULL),(61,'alioss_access_key_secret','upload','填你的','阿里云oss私钥',0,NULL,NULL),(62,'alioss_endpoint','upload','填你的','阿里云oss数据中心',0,NULL,NULL),(63,'alioss_bucket','upload','填你的','阿里云oss空间名称',0,NULL,NULL),(64,'alioss_domain','upload','填你的','阿里云oss访问域名',0,NULL,NULL),(65,'logo_title','site','ulthon_admin','LOGO标题',0,NULL,NULL),(66,'logo_image','site','/favicon.ico','logo图片',0,NULL,NULL),(68,'site_name','site','ulthon_admin后台系统','站点名称',0,NULL,NULL),(69,'site_ico','site','填你的','浏览器图标',0,NULL,NULL),(70,'site_copyright','site','填你的','版权信息',0,NULL,NULL),(71,'site_beian','site','填你的','备案信息',0,NULL,NULL),(72,'site_version','site','2.0.0','版本信息',0,NULL,NULL),(75,'sms_type','sms','alisms','短信类型',0,NULL,NULL),(76,'miniapp_appid','wechat','填你的','小程序公钥',0,NULL,NULL),(77,'miniapp_appsecret','wechat','填你的','小程序私钥',0,NULL,NULL),(78,'web_appid','wechat','填你的','公众号公钥',0,NULL,NULL),(79,'web_appsecret','wechat','填你的','公众号私钥',0,NULL,NULL),(80,'txcos_secret_id','upload','填你的','腾讯云cos密钥',0,NULL,NULL),(81,'txcos_secret_key','upload','填你的','腾讯云cos私钥',0,NULL,NULL),(82,'txcos_region','upload','填你的','存储桶地域',0,NULL,NULL),(83,'tecos_bucket','upload','填你的','存储桶名称',0,NULL,NULL),(84,'qnoss_access_key','upload','填你的','访问密钥',0,NULL,NULL),(85,'qnoss_secret_key','upload','填你的','安全密钥',0,NULL,NULL),(86,'qnoss_bucket','upload','填你的','存储空间',0,NULL,NULL),(87,'qnoss_domain','upload','填你的','访问域名',0,NULL,NULL),(88,'file','site','','',0,1646053882,1646053882),(89,'site_domain','site','http://admin.demo.ulthon.com','',0,1646053882,1646053882);
/*!40000 ALTER TABLE `ul_system_config` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_system_menu`
--
DROP TABLE IF EXISTS `ul_system_menu`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_system_menu` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`pid` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '父id',
`title` varchar(100) NOT NULL DEFAULT '' COMMENT '名称',
`icon` varchar(100) NOT NULL DEFAULT '' COMMENT '菜单图标',
`href` varchar(100) NOT NULL DEFAULT '' COMMENT '链接',
`params` varchar(500) DEFAULT '' COMMENT '链接参数',
`target` varchar(20) NOT NULL DEFAULT '_self' COMMENT '链接打开方式',
`sort` int(11) DEFAULT '0' COMMENT '菜单排序',
`status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '状态(0:禁用,1:启用)',
`remark` varchar(255) DEFAULT NULL,
`create_time` int(11) DEFAULT NULL COMMENT '创建时间',
`update_time` int(11) DEFAULT NULL COMMENT '更新时间',
`delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`),
KEY `title` (`title`),
KEY `href` (`href`)
) ENGINE=InnoDB AUTO_INCREMENT=254 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='系统菜单表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_system_menu`
--
LOCK TABLES `ul_system_menu` WRITE;
/*!40000 ALTER TABLE `ul_system_menu` DISABLE KEYS */;
INSERT INTO `ul_system_menu` VALUES (227,99999999,'后台首页','fa fa-home','index/welcome','','_self',0,1,NULL,NULL,1573120497,NULL),(228,0,'系统管理','fa fa-cog','','','_self',0,1,'',NULL,1588999529,NULL),(234,228,'菜单管理','fa fa-tree','system.menu/index','','_self',10,1,'',NULL,1588228555,NULL),(244,228,'管理员管理','fa fa-user','system.admin/index','','_self',12,1,'',1573185011,1588228573,NULL),(245,228,'角色管理','fa fa-bitbucket-square','system.auth/index','','_self',11,1,'',1573435877,1588228634,NULL),(246,228,'节点管理','fa fa-list','system.node/index','','_self',9,1,'',1573435919,1588228648,NULL),(247,228,'配置管理','fa fa-asterisk','system.config/index','','_self',8,1,'',1573457448,1588228566,NULL),(248,228,'上传管理','fa fa-arrow-up','system.uploadfile/index','','_self',0,1,'',1573542953,1588228043,NULL),(249,0,'商城管理','fa fa-list','','','_self',0,1,'',1589439884,1589439884,NULL),(250,249,'商品分类','fa fa-calendar-check-o','mall.cate/index','','_self',0,1,'',1589439910,1589439966,NULL),(251,249,'商品管理','fa fa-list','mall.goods/index','','_self',0,1,'',1589439931,1589439942,NULL),(252,228,'快捷入口','fa fa-list','system.quick/index','','_self',0,1,'',1589623683,1589623683,NULL),(253,228,'日志管理','fa fa-connectdevelop','system.log/index','','_self',0,1,'',1589623684,1589623684,NULL);
/*!40000 ALTER TABLE `ul_system_menu` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_system_node`
--
DROP TABLE IF EXISTS `ul_system_node`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_system_node` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`node` varchar(100) DEFAULT NULL COMMENT '节点代码',
`title` varchar(500) DEFAULT NULL COMMENT '节点标题',
`type` tinyint(1) DEFAULT '3' COMMENT '节点类型1控制器2节点',
`is_auth` tinyint(1) unsigned DEFAULT '1' COMMENT '是否启动RBAC权限控制',
`create_time` int(10) DEFAULT NULL COMMENT '创建时间',
`update_time` int(10) DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `node` (`node`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=69 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='系统节点表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_system_node`
--
LOCK TABLES `ul_system_node` WRITE;
/*!40000 ALTER TABLE `ul_system_node` DISABLE KEYS */;
INSERT INTO `ul_system_node` VALUES (1,'system.admin','管理员管理',1,1,1589580432,1589580432),(2,'system.admin/index','列表',2,1,1589580432,1589580432),(3,'system.admin/add','添加',2,1,1589580432,1589580432),(4,'system.admin/edit','编辑',2,1,1589580432,1589580432),(5,'system.admin/password','编辑',2,1,1589580432,1589580432),(6,'system.admin/delete','删除',2,1,1589580432,1589580432),(7,'system.admin/modify','属性修改',2,1,1589580432,1589580432),(8,'system.admin/export','导出',2,1,1589580432,1589580432),(9,'system.auth','角色权限管理',1,1,1589580432,1589580432),(10,'system.auth/authorize','授权',2,1,1589580432,1589580432),(11,'system.auth/saveAuthorize','授权保存',2,1,1589580432,1589580432),(12,'system.auth/index','列表',2,1,1589580432,1589580432),(13,'system.auth/add','添加',2,1,1589580432,1589580432),(14,'system.auth/edit','编辑',2,1,1589580432,1589580432),(15,'system.auth/delete','删除',2,1,1589580432,1589580432),(16,'system.auth/export','导出',2,1,1589580432,1589580432),(17,'system.auth/modify','属性修改',2,1,1589580432,1589580432),(18,'system.config','系统配置管理',1,1,1589580432,1589580432),(19,'system.config/index','列表',2,1,1589580432,1589580432),(20,'system.config/save','保存',2,1,1589580432,1589580432),(21,'system.menu','菜单管理',1,1,1589580432,1589580432),(22,'system.menu/index','列表',2,1,1589580432,1589580432),(23,'system.menu/add','添加',2,1,1589580432,1589580432),(24,'system.menu/edit','编辑',2,1,1589580432,1589580432),(25,'system.menu/delete','删除',2,1,1589580432,1589580432),(26,'system.menu/modify','属性修改',2,1,1589580432,1589580432),(27,'system.menu/getMenuTips','添加菜单提示',2,1,1589580432,1589580432),(28,'system.menu/export','导出',2,1,1589580432,1589580432),(29,'system.node','系统节点管理',1,1,1589580432,1589580432),(30,'system.node/index','列表',2,1,1589580432,1589580432),(31,'system.node/refreshNode','系统节点更新',2,1,1589580432,1589580432),(32,'system.node/clearNode','清除失效节点',2,1,1589580432,1589580432),(33,'system.node/add','添加',2,1,1589580432,1589580432),(34,'system.node/edit','编辑',2,1,1589580432,1589580432),(35,'system.node/delete','删除',2,1,1589580432,1589580432),(36,'system.node/export','导出',2,1,1589580432,1589580432),(37,'system.node/modify','属性修改',2,1,1589580432,1589580432),(38,'system.uploadfile','上传文件管理',1,1,1589580432,1589580432),(39,'system.uploadfile/index','列表',2,1,1589580432,1589580432),(40,'system.uploadfile/add','添加',2,1,1589580432,1589580432),(41,'system.uploadfile/edit','编辑',2,1,1589580432,1589580432),(42,'system.uploadfile/delete','删除',2,1,1589580432,1589580432),(43,'system.uploadfile/export','导出',2,1,1589580432,1589580432),(44,'system.uploadfile/modify','属性修改',2,1,1589580432,1589580432),(45,'mall.cate','商品分类管理',1,1,1589580432,1589580432),(46,'mall.cate/index','列表',2,1,1589580432,1589580432),(47,'mall.cate/add','添加',2,1,1589580432,1589580432),(48,'mall.cate/edit','编辑',2,1,1589580432,1589580432),(49,'mall.cate/delete','删除',2,1,1589580432,1589580432),(50,'mall.cate/export','导出',2,1,1589580432,1589580432),(51,'mall.cate/modify','属性修改',2,1,1589580432,1589580432),(52,'mall.goods','商城商品管理',1,1,1589580432,1589580432),(53,'mall.goods/index','列表',2,1,1589580432,1589580432),(54,'mall.goods/stock','入库',2,1,1589580432,1589580432),(55,'mall.goods/add','添加',2,1,1589580432,1589580432),(56,'mall.goods/edit','编辑',2,1,1589580432,1589580432),(57,'mall.goods/delete','删除',2,1,1589580432,1589580432),(58,'mall.goods/export','导出',2,1,1589580432,1589580432),(59,'mall.goods/modify','属性修改',2,1,1589580432,1589580432),(60,'system.quick','快捷入口管理',1,1,1589623188,1589623188),(61,'system.quick/index','列表',2,1,1589623188,1589623188),(62,'system.quick/add','添加',2,1,1589623188,1589623188),(63,'system.quick/edit','编辑',2,1,1589623188,1589623188),(64,'system.quick/delete','删除',2,1,1589623188,1589623188),(65,'system.quick/export','导出',2,1,1589623188,1589623188),(66,'system.quick/modify','属性修改',2,1,1589623188,1589623188),(67,'system.log','操作日志管理',1,1,1589623188,1589623188),(68,'system.log/index','列表',2,1,1589623188,1589623188);
/*!40000 ALTER TABLE `ul_system_node` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_system_quick`
--
DROP TABLE IF EXISTS `ul_system_quick`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_system_quick` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(20) NOT NULL COMMENT '快捷入口名称',
`icon` varchar(100) DEFAULT NULL COMMENT '图标',
`href` varchar(255) DEFAULT NULL COMMENT '快捷链接',
`sort` int(11) DEFAULT '0' COMMENT '排序',
`status` tinyint(1) unsigned DEFAULT '1' COMMENT '状态(1:禁用,2:启用)',
`remark` varchar(255) DEFAULT NULL COMMENT '备注说明',
`create_time` int(11) DEFAULT NULL COMMENT '创建时间',
`update_time` int(11) DEFAULT NULL COMMENT '更新时间',
`delete_time` int(11) DEFAULT NULL COMMENT '删除时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='系统快捷入口表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_system_quick`
--
LOCK TABLES `ul_system_quick` WRITE;
/*!40000 ALTER TABLE `ul_system_quick` DISABLE KEYS */;
INSERT INTO `ul_system_quick` VALUES (1,'管理员管理','fa fa-user','system.admin/index',0,1,'',1589624097,1589624792,NULL),(2,'角色管理','fa fa-bitbucket-square','system.auth/index',0,1,'',1589624772,1589624781,NULL),(3,'菜单管理','fa fa-tree','system.menu/index',0,1,NULL,1589624097,1589624792,NULL),(6,'节点管理','fa fa-list','system.node/index',0,1,NULL,1589624772,1589624781,NULL),(7,'配置管理','fa fa-asterisk','system.config/index',0,1,NULL,1589624097,1589624792,NULL),(8,'上传管理','fa fa-arrow-up','system.uploadfile/index',0,1,NULL,1589624772,1589624781,NULL),(10,'商品分类','fa fa-calendar-check-o','mall.cate/index',0,1,NULL,1589624097,1589624792,NULL),(11,'商品管理','fa fa-list','mall.goods/index',0,1,NULL,1589624772,1589624781,NULL);
/*!40000 ALTER TABLE `ul_system_quick` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `ul_system_uploadfile`
--
DROP TABLE IF EXISTS `ul_system_uploadfile`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ul_system_uploadfile` (
`id` int(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`upload_type` varchar(20) NOT NULL DEFAULT 'local' COMMENT '存储位置',
`original_name` varchar(255) DEFAULT NULL COMMENT '文件原名',
`url` varchar(255) NOT NULL DEFAULT '' COMMENT '物理路径',
`image_width` varchar(30) NOT NULL DEFAULT '' COMMENT '宽度',
`image_height` varchar(30) NOT NULL DEFAULT '' COMMENT '高度',
`image_type` varchar(30) NOT NULL DEFAULT '' COMMENT '图片类型',
`image_frames` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '图片帧数',
`mime_type` varchar(100) NOT NULL DEFAULT '' COMMENT 'mime类型',
`file_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '文件大小',
`file_ext` varchar(100) DEFAULT NULL,
`sha1` varchar(40) NOT NULL DEFAULT '' COMMENT '文件 sha1编码',
`create_time` int(10) DEFAULT NULL COMMENT '创建日期',
`update_time` int(10) DEFAULT NULL COMMENT '更新时间',
`upload_time` int(10) DEFAULT NULL COMMENT '上传时间',
PRIMARY KEY (`id`),
KEY `upload_type` (`upload_type`),
KEY `original_name` (`original_name`)
) ENGINE=InnoDB AUTO_INCREMENT=316 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='上传文件表';
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `ul_system_uploadfile`
--
LOCK TABLES `ul_system_uploadfile` WRITE;
/*!40000 ALTER TABLE `ul_system_uploadfile` DISABLE KEYS */;
INSERT INTO `ul_system_uploadfile` VALUES (286,'alioss','image/jpeg','https://lxn-99php.oss-cn-shenzhen.aliyuncs.com/upload/20191111/0a6de1ac058ee134301501899b84ecb1.jpg','','','',0,'image/jpeg',0,'jpg','',NULL,NULL,NULL),(287,'alioss','image/jpeg','https://lxn-99php.oss-cn-shenzhen.aliyuncs.com/upload/20191111/46d7384f04a3bed331715e86a4095d15.jpg','','','',0,'image/jpeg',0,'jpg','',NULL,NULL,NULL),(288,'alioss','image/x-icon','https://lxn-99php.oss-cn-shenzhen.aliyuncs.com/upload/20191111/7d32671f4c1d1b01b0b28f45205763f9.ico','','','',0,'image/x-icon',0,'ico','',NULL,NULL,NULL),(289,'alioss','image/jpeg','https://lxn-99php.oss-cn-shenzhen.aliyuncs.com/upload/20191111/28cefa547f573a951bcdbbeb1396b06f.jpg','','','',0,'image/jpeg',0,'jpg','',NULL,NULL,NULL),(290,'alioss','image/jpeg','https://lxn-99php.oss-cn-shenzhen.aliyuncs.com/upload/20191111/2c412adf1b30c8be3a913e603c7b6e4a.jpg','','','',0,'image/jpeg',0,'jpg','',NULL,NULL,NULL),(291,'alioss','timg (1).jpg','http://ulthon_admin.oss-cn-shenzhen.aliyuncs.com/upload/20191113/ff793ced447febfa9ea2d86f9f88fa8e.jpg','','','',0,'image/jpeg',0,'jpg','',1573612437,NULL,NULL),(296,'txcos','22243.jpg','https://ulthon_admin-1251997243.cos.ap-guangzhou.myqcloud.com/upload/20191114/2381eaf81208ac188fa994b6f2579953.jpg','','','',0,'image/jpeg',0,'jpg','',1573712153,NULL,NULL),(297,'local','timg.jpg','http://admin.host/upload/20200423/5055a273cf8e3f393d699d622b74f247.jpg','','','',0,'image/jpeg',0,'jpg','',1587614155,NULL,NULL),(298,'local','timg.jpg','http://admin.host/upload/20200423/243f4e59f1b929951ef79c5f8be7468a.jpg','','','',0,'image/jpeg',0,'jpg','',1587614269,NULL,NULL),(299,'local','head.jpg','http://admin.host/upload/20200512/a5ce9883379727324f5686ef61205ce2.jpg','','','',0,'image/jpeg',0,'jpg','',1589255649,NULL,NULL),(300,'local','896e5b87c9ca70e4.jpg','http://admin.host/upload/20200514/577c65f101639f53dbbc9e7aa346f81c.jpg','','','',0,'image/jpeg',0,'jpg','',1589427798,NULL,NULL),(301,'local','896e5b87c9ca70e4.jpg','http://admin.host/upload/20200514/98fc09b0c4ad4d793a6f04bef79a0edc.jpg','','','',0,'image/jpeg',0,'jpg','',1589427840,NULL,NULL),(302,'local','18811e7611c8f292.jpg','http://admin.host/upload/20200514/e1c6c9ef6a4b98b8f7d95a1a0191a2df.jpg','','','',0,'image/jpeg',0,'jpg','',1589438645,NULL,NULL);
/*!40000 ALTER TABLE `ul_system_uploadfile` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Dumping routines for database 'admin_demo_ultho'
--
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-04-03 15:27:35

View File

@@ -9,163 +9,163 @@ use PDO;
class DebugMysql implements LogHandlerInterface
{
protected $enableLog = true;
protected $enableLog = true;
protected $config = [];
protected $config = [];
protected $pdo = null;
protected $pdo = null;
protected $fileRescource = null;
protected $fileRescource = null;
protected $tableName = '';
protected $tableName = '';
public function __construct(App $app, $config = [])
{
if (is_array($config)) {
$this->config = array_merge($this->config, $config);
}
$dsn = $this->parseDsn($config);
try {
$pdo = $this->createPdo($dsn, $config['username'], $config['password'], $config['params']);
$this->pdo = $pdo;
} catch (\Throwable $th) {
$this->pdo = null;
$log_path = App::getRuntimePath() . 'log/' . date('ymd') . '.csv';
$dirname = dirname($log_path);
if (!is_dir($dirname)) {
mkdir($log_path, 0777, true);
}
$first_line = false;
if (!file_exists($log_path)) {
$first_line = true;
}
$this->fileRescource = fopen($log_path, 'a');
if ($first_line) {
$fields = [
'level',
'content',
'create_time',
'create_time_title',
'uid',
'app_name',
'controller_name',
'action_name',
];
fputcsv($this->fileRescource, $fields);
}
}
$this->tableName = $config['prefix'] . 'debug_log';
}
public function save(array $log): bool
{
$app_name = app('http')->getName() ?: '';
$controller_name = request()->controller();
$action_name = request()->action();
if (App::runningInConsole()) {
$app_name = 'cli';
}
$create_time = time();
$create_time_title = date('Y-m-d H:i:s', $create_time);
$log_key = uniqid();
foreach ($log as $log_level => $log_list) {
foreach ($log_list as $key => $log_item) {
if (!is_string($log_item)) {
$log_item = json_encode($log_item, JSON_UNESCAPED_UNICODE);
public function __construct(App $app, $config = [])
{
if (is_array($config)) {
$this->config = array_merge($this->config, $config);
}
$log_data = [
'level' => $log_level,
'content' => $log_item,
'create_time' => $create_time,
'create_time_title' => $create_time_title,
'uid' => $log_key,
'app_name' => $app_name,
'controller_name' => $controller_name,
'action_name' => $action_name,
];
if (!is_null($this->pdo)) {
$dsn = $this->parseDsn($config);
foreach ($log_data as $key => &$value) {
$value = str_replace('\'', '\\\'', $value);
}
try {
$data_keys = array_keys($log_data);
$pdo = $this->createPdo($dsn, $config['username'], $config['password'], $config['params']);
$data_keys_in_sql = join(',', $data_keys);
$this->pdo = $pdo;
} catch (\Throwable $th) {
$this->pdo = null;
$data_values_in_sql = join('\',\'', $log_data);
$log_path = App::getRuntimePath() . 'log/' . date('ymd') . '.csv';
$sql = "INSERT INTO {$this->tableName} ($data_keys_in_sql) VALUES ('$data_values_in_sql');";
$dirname = dirname($log_path);
$this->pdo->exec($sql);
if (!is_dir($dirname)) {
mkdir($log_path, 0777, true);
}
$first_line = false;
if (!file_exists($log_path)) {
$first_line = true;
}
$this->fileRescource = fopen($log_path, 'a');
if ($first_line) {
$fields = [
'level',
'content',
'create_time',
'create_time_title',
'uid',
'app_name',
'controller_name',
'action_name',
];
fputcsv($this->fileRescource, $fields);
}
}
$this->tableName = $config['prefix'] . 'debug_log';
}
public function save(array $log): bool
{
$app_name = app('http')->getName() ?: '';
$controller_name = request()->controller();
$action_name = request()->action();
if (App::runningInConsole()) {
$app_name = 'cli';
}
$create_time = time();
$create_time_title = date('Y-m-d H:i:s', $create_time);
$log_key = uniqid();
foreach ($log as $log_level => $log_list) {
foreach ($log_list as $key => $log_item) {
if (!is_string($log_item)) {
$log_item = json_encode($log_item, JSON_UNESCAPED_UNICODE);
}
$log_data = [
'level' => $log_level,
'content' => $log_item,
'create_time' => $create_time,
'create_time_title' => $create_time_title,
'uid' => $log_key,
'app_name' => $app_name,
'controller_name' => $controller_name,
'action_name' => $action_name,
];
if (!is_null($this->pdo)) {
foreach ($log_data as $key => &$value) {
$value = str_replace('\'', '\\\'', $value);
}
$data_keys = array_keys($log_data);
$data_keys_in_sql = join(',', $data_keys);
$data_values_in_sql = join('\',\'', $log_data);
$sql = "INSERT INTO {$this->tableName} ($data_keys_in_sql) VALUES ('$data_values_in_sql');";
$this->pdo->exec($sql);
} else {
fputcsv($this->fileRescource, $log_data);
}
}
}
return true;
}
/**
* 解析pdo连接的dsn信息
* @access protected
* @param array $config 连接信息
* @return string
*/
protected function parseDsn(array $config): string
{
if (!empty($config['socket'])) {
$dsn = 'mysql:unix_socket=' . $config['socket'];
} elseif (!empty($config['hostport'])) {
$dsn = 'mysql:host=' . $config['hostname'] . ';port=' . $config['hostport'];
} else {
fputcsv($this->fileRescource, $log_data);
$dsn = 'mysql:host=' . $config['hostname'];
}
}
$dsn .= ';dbname=' . $config['database'];
if (!empty($config['charset'])) {
$dsn .= ';charset=' . $config['charset'];
}
return $dsn;
}
return true;
}
/**
* 解析pdo连接的dsn信息
* @access protected
* @param array $config 连接信息
* @return string
*/
protected function parseDsn(array $config): string
{
if (!empty($config['socket'])) {
$dsn = 'mysql:unix_socket=' . $config['socket'];
} elseif (!empty($config['hostport'])) {
$dsn = 'mysql:host=' . $config['hostname'] . ';port=' . $config['hostport'];
} else {
$dsn = 'mysql:host=' . $config['hostname'];
}
$dsn .= ';dbname=' . $config['database'];
if (!empty($config['charset'])) {
$dsn .= ';charset=' . $config['charset'];
protected function createPdo($dsn, $username, $password, $params)
{
return new PDO($dsn, $username, $password, $params);
}
return $dsn;
}
public function __destruct()
{
$this->pdo = null;
protected function createPdo($dsn, $username, $password, $params)
{
return new PDO($dsn, $username, $password, $params);
}
public function __destruct()
{
$this->pdo = null;
if (!is_null($this->fileRescource)) {
fclose($this->fileRescource);
if (!is_null($this->fileRescource)) {
fclose($this->fileRescource);
}
}
}
}

View File

@@ -18,11 +18,6 @@ require __DIR__ . '/../vendor/autoload.php';
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_PATH', __DIR__ . DS . '..' . DS);
// 判断是否安装程序
if (!is_file(ROOT_PATH . 'config' . DS . 'install' . DS . 'lock' . DS . 'install.lock')) {
exit(header("location:/install.php"));
}
// 执行HTTP应用并响应
$http = (new App())->http;

View File

@@ -1,572 +0,0 @@
<?php
ini_set('display_errors', 'On');
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use think\facade\Db;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/topthink/framework/src/helper.php';
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_PATH', __DIR__ . DS . '..' . DS);
define('INSTALL_PATH', ROOT_PATH . 'config' . DS . 'install' . DS);
define('CONFIG_PATH', ROOT_PATH . 'config' . DS);
$currentHost = ($_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . '/';
function isReadWrite($file)
{
if (DIRECTORY_SEPARATOR == '\\') {
return true;
}
if (DIRECTORY_SEPARATOR == '/' && @ ini_get("safe_mode") === false) {
return is_writable($file);
}
if (!is_file($file) || ($fp = @fopen($file, "r+")) === false) {
return false;
}
fclose($fp);
return true;
}
$errorInfo = null;
if (is_file(INSTALL_PATH . 'lock' . DS . 'install.lock')) {
$errorInfo = '已安装系统,如需重新安装请删除文件:/config/install/lock/install.lock';
} elseif (!isReadWrite(ROOT_PATH . 'config' . DS)) {
$errorInfo = ROOT_PATH . 'config' . DS . ':读写权限不足';
} elseif (!isReadWrite(ROOT_PATH . 'runtime' . DS)) {
$errorInfo = ROOT_PATH . 'runtime' . DS . ':读写权限不足';
} elseif (!isReadWrite(ROOT_PATH . 'public' . DS)) {
$errorInfo = ROOT_PATH . 'public' . DS . ':读写权限不足';
} elseif (!checkPhpVersion('7.1.0')) {
$errorInfo = 'PHP版本不能小于7.1.0';
} elseif (!extension_loaded("PDO")) {
$errorInfo = '当前未开启PDO无法进行安装';
}
// POST请求
if (isAjax()) {
$post = $_POST;
$cover = $post['cover'] == 1 ? true : false;
$database = $post['database'];
$hostname = $post['hostname'];
$hostport = $post['hostport'];
$dbUsername = $post['db_username'];
$dbPassword = $post['db_password'];
$prefix = $post['prefix'];
$adminUrl = $post['admin_url'];
$username = $post['username'];
$password = $post['password'];
// 参数验证
$validateError = null;
// 判断是否有特殊字符
$check = preg_match('/[0-9a-zA-Z]+$/', $adminUrl, $matches);
if (!$check) {
$validateError = '后台地址不能含有特殊字符, 只能包含字母或数字。';
$data = [
'code' => 0,
'msg' => $validateError,
];
die(json_encode($data));
}
if (strlen($adminUrl) < 2) {
$validateError = '后台的地址不能小于2位数';
} elseif (strlen($password) < 5) {
$validateError = '管理员密码不能小于5位数';
} elseif (strlen($username) < 4) {
$validateError = '管理员账号不能小于4位数';
}
if (!empty($validateError)) {
$data = [
'code' => 0,
'msg' => $validateError,
];
die(json_encode($data));
}
// DB类初始化
$config = [
'type' => 'mysql',
'hostname' => $hostname,
'username' => $dbUsername,
'password' => $dbPassword,
'hostport' => $hostport,
'charset' => 'utf8',
'prefix' => $prefix,
'debug' => true,
];
Db::setConfig([
'default' => 'mysql',
'connections' => [
'mysql' => $config,
'install' => array_merge($config, ['database' => $database]),
],
]);
// 检测数据库连接
if (!checkConnect()) {
$data = [
'code' => 0,
'msg' => '数据库连接失败',
];
die(json_encode($data));
}
// 检测数据库是否存在
if (!$cover && checkDatabase($database)) {
$data = [
'code' => 0,
'msg' => '数据库已存在,请选择覆盖安装或者修改数据库名',
];
die(json_encode($data));
}
// 创建数据库
createDatabase($database);
// 导入sql语句等等
$install = install($username, $password, array_merge($config, ['database' => $database]), $adminUrl);
if ($install !== true) {
$data = [
'code' => 0,
'msg' => '系统安装失败:' . $install,
];
die(json_encode($data));
}
$data = [
'code' => 1,
'msg' => '系统安装成功,正在跳转登录页面',
'url' => $adminUrl,
];
die(json_encode($data));
}
function isAjax()
{
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
return true;
} else {
return false;
}
}
function isPost()
{
return ($_SERVER['REQUEST_METHOD'] == 'POST' && checkurlHash($GLOBALS['verify'])
&& (empty($_SERVER['HTTP_REFERER']) || preg_replace("~https?:\/\/([^\:\/]+).*~i", "\\1", $_SERVER['HTTP_REFERER']) == preg_replace("~([^\:]+).*~", "\\1", $_SERVER['HTTP_HOST']))) ? 1 : 0;
}
function checkPhpVersion($version)
{
$php_version = explode('-', phpversion());
$check = strnatcasecmp($php_version[0], $version) >= 0 ? true : false;
return $check;
}
function checkConnect()
{
try {
Db::query("select version()");
} catch (\Exception $e) {
return false;
}
return true;
}
function checkDatabase($database)
{
$check = Db::query("SELECT * FROM information_schema.schemata WHERE schema_name='{$database}'");
if (empty($check)) {
return false;
} else {
return true;
}
}
function createDatabase($database)
{
try {
Db::execute("CREATE DATABASE IF NOT EXISTS `{$database}` DEFAULT CHARACTER SET utf8");
} catch (\Exception $e) {
return false;
}
return true;
}
function parseSql($sql = '', $to, $from)
{
list($pure_sql, $comment) = [[], false];
$sql = explode("\n", trim(str_replace(["\r\n", "\r"], "\n", $sql)));
foreach ($sql as $key => $line) {
if ($line == '') {
continue;
}
if (preg_match("/^(#|--)/", $line)) {
continue;
}
if (preg_match("/^\/\*(.*?)\*\//", $line)) {
continue;
}
if (substr($line, 0, 2) == '/*') {
$comment = true;
continue;
}
if (substr($line, -2) == '*/') {
$comment = false;
continue;
}
if ($comment) {
continue;
}
if ($from != '') {
$line = str_replace('`' . $from, '`' . $to, $line);
}
if ($line == 'BEGIN;' || $line == 'COMMIT;') {
continue;
}
array_push($pure_sql, $line);
}
//$pure_sql = implode($pure_sql, "\n");
$pure_sql = implode("\n",$pure_sql);
$pure_sql = explode(";\n", $pure_sql);
return $pure_sql;
}
function install($username, $password, $config, $adminUrl)
{
$sqlPath = file_get_contents(INSTALL_PATH . 'sql' . DS . 'install.sql');
$sqlArray = parseSql($sqlPath, $config['prefix'], 'ul_');
Db::startTrans();
try {
foreach ($sqlArray as $vo) {
foreach ($sqlArray as $vo) {
if (strpos($vo, 'LOCK TABLES') === 0) {
continue;
}
if (strpos($vo, 'UNLOCK') === 0) {
continue;
}
Db::execute($vo);
}
Db::connect('install')->execute($vo);
}
Db::connect('install')
->name('system_admin')
->where('id', 1)
->delete();
Db::connect('install')
->name('system_admin')
->insert([
'id' => 1,
'username' => $username,
'head_img' => '/static/admin/images/head.jpg',
'password' => password($password),
'create_time' => time(),
]);
// 处理安装文件
!is_dir(INSTALL_PATH) && @mkdir(INSTALL_PATH);
!is_dir(INSTALL_PATH . 'lock' . DS) && @mkdir(INSTALL_PATH . 'lock' . DS);
@file_put_contents(INSTALL_PATH . 'lock' . DS . 'install.lock', date('Y-m-d H:i:s'));
@file_put_contents(CONFIG_PATH . 'app.php', getAppConfig($adminUrl));
@file_put_contents(CONFIG_PATH . 'database.php', getDatabaseConfig($config));
Db::commit();
} catch (\Exception $e) {
Db::rollback();
return $e->getMessage();
}
return true;
}
function password($value)
{
$value = sha1('blog_') . md5($value) . md5('_encrypt') . sha1($value);
return sha1($value);
}
function getAppConfig($admin)
{
$config = <<<EOT
<?php
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
use think\\facade\Env;
return [
// 应用地址
'app_host' => Env::get('app.host', ''),
// 应用的命名空间
'app_namespace' => '',
// 是否启用路由
'with_route' => true,
// 是否启用事件
'with_event' => true,
// 开启应用快速访问
'app_express' => true,
// 默认应用
'default_app' => 'index',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 应用映射(自动多应用模式有效)
'app_map' => [
Env::get('adminsystem.admin', '{$admin}') => 'admin',
],
// 后台别名
'admin_alias_name' => Env::get('adminsystem.admin', '{$admin}'),
// 域名绑定(自动多应用模式有效)
'domain_bind' => [],
// 禁止URL访问的应用列表自动多应用模式有效
'deny_app_list' => ['common'],
// 异常页面的模板文件
'exception_tmpl' => Env::get('app_debug') == 1 ? app()->getThinkPath() . 'tpl/think_exception.tpl' : app()->getBasePath() . 'common' . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . 'think_exception.tpl',
// 跳转页面的成功模板文件
'dispatch_success_tmpl' => app()->getBasePath() . 'common' . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . 'dispatch_jump.tpl',
// 跳转页面的失败模板文件
'dispatch_error_tmpl' => app()->getBasePath() . 'common' . DIRECTORY_SEPARATOR . 'tpl' . DIRECTORY_SEPARATOR . 'dispatch_jump.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
// 静态资源上传到OSS前缀
'oss_static_prefix' => Env::get('adminsystem.oss_static_prefix', 'static_ulthon_admin'),
];
EOT;
return $config;
}
function getDatabaseConfig($data)
{
$config = <<<EOT
<?php
use think\\facade\Env;
return [
// 默认使用的数据库连接配置
'default' => Env::get('database.driver', 'mysql'),
// 自定义时间查询规则
'time_query_rule' => [],
// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp' => true,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 数据库连接配置信息
'connections' => [
'mysql' => [
// 数据库类型
'type' => Env::get('database.type', 'mysql'),
// 服务器地址
'hostname' => Env::get('database.hostname', '{$data['hostname']}'),
// 数据库名
'database' => Env::get('database.database', '{$data['database']}'),
// 用户名
'username' => Env::get('database.username', '{$data['username']}'),
// 密码
'password' => Env::get('database.password', '{$data['password']}'),
// 端口
'hostport' => Env::get('database.hostport', '{$data['hostport']}'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => Env::get('database.charset', 'utf8'),
// 数据库表前缀
'prefix' => Env::get('database.prefix', '{$data['prefix']}'),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => true,
// 开启字段缓存
'fields_cache' => false,
// 字段缓存路径
'schema_cache_path' => app()->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR,
],
// 更多的数据库配置信息
],
];
EOT;
return $config;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>安装EasyAdmin后台程序</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="static/plugs/layui-v2.5.6/css/layui.css?v=<?php echo time() ?>" media="all">
<link rel="stylesheet" href="static/common/css/insatll.css?v=<?php echo time() ?>" media="all">
</head>
<body>
<h1><img src="static/common/images/logo-1.png"></h1>
<h2>安装EasyAdmin后台系统</h2>
<div class="content">
<p class="desc">
使用过程中遇到任何问题可参考
<a href="http://easyadmin.99php.cn/docs" target="_blank">文档教程</a>
<a href="https://jq.qq.com/?_wv=1027&k=5IHJawE">QQ交流群</a>
</p>
<form class="layui-form layui-form-pane" action="">
<?php if ($errorInfo): ?>
<div class="error">
<?php echo $errorInfo; ?>
</div>
<?php endif; ?>
<div class="bg">
<div class="layui-form-item">
<label class="layui-form-label">数据库地址</label>
<div class="layui-input-block">
<input class="layui-input" name="hostname" autocomplete="off" lay-verify="required" lay-reqtext="请输入数据库地址" placeholder="请输入数据库地址" value="host.docker.internal">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">数据库端口</label>
<div class="layui-input-block">
<input class="layui-input" name="hostport" autocomplete="off" lay-verify="required" lay-reqtext="请输入数据库端口" placeholder="请输入数据库端口" value="3306">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">数据库名称</label>
<div class="layui-input-block">
<input class="layui-input" name="database" autocomplete="off" lay-verify="required" lay-reqtext="请输入数据库名称" placeholder="请输入数据库名称" value="easyadmin">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">数据表前缀</label>
<div class="layui-input-block">
<input class="layui-input" name="prefix" autocomplete="off" lay-verify="required" lay-reqtext="请输入数据表前缀" placeholder="请输入数据表前缀" value="ul_">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">数据库账号</label>
<div class="layui-input-block">
<input class="layui-input" name="db_username" autocomplete="off" lay-verify="required" lay-reqtext="请输入数据库账号" placeholder="请输入数据库账号" value="root">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">数据库密码</label>
<div class="layui-input-block">
<input type="password" class="layui-input" name="db_password" autocomplete="off" lay-verify="required" lay-reqtext="请输入数据库密码" placeholder="请输入数据库密码">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">覆盖数据库</label>
<div class="layui-input-block" style="text-align: left">
<input type="radio" name="cover" value="1" title="覆盖">
<input type="radio" name="cover" value="0" title="不覆盖" checked>
</div>
</div>
</div>
<div class="bg">
<div class="layui-form-item">
<label class="layui-form-label">后台的地址</label>
<div class="layui-input-block">
<input class="layui-input" id="admin_url" name="admin_url" autocomplete="off" lay-verify="required" lay-reqtext="请输入后台的地址" placeholder="为了后台安全不建议将后台路径设置为admin" value="admin">
<span class="tips">后台登录地址: <?php echo $currentHost; ?><span id="admin_name">admin</span></span>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">管理员账号</label>
<div class="layui-input-block">
<input class="layui-input" name="username" autocomplete="off" lay-verify="required" lay-reqtext="请输入管理员账号" placeholder="请输入管理员账号" value="admin">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">管理员密码</label>
<div class="layui-input-block">
<input type="password" class="layui-input" name="password" autocomplete="off" lay-verify="required" lay-reqtext="请输入管理员密码" placeholder="请输入管理员密码">
</div>
</div>
</div>
<div class="layui-form-item">
<button class="layui-btn layui-btn-normal <?php echo $errorInfo ? 'layui-btn-disabled' : '' ?>" lay-submit="" lay-filter="install">确定安装</button>
</div>
</form>
</div>
<script src="static/plugs/layui-v2.5.6/layui.js?v=<?php echo time() ?>" charset="utf-8"></script>
<script>
layui.use(['form', 'layer'], function () {
var $ = layui.jquery,
form = layui.form,
layer = layui.layer;
$("#admin_url").bind("input propertychange", function () {
var val = $(this).val();
$("#admin_name").text(val);
});
form.on('submit(install)', function (data) {
if ($(this).hasClass('layui-btn-disabled')) {
return false;
}
var _data = data.field;
var loading = layer.msg('正在安装...', {
icon: 16,
shade: 0.2,
time: false
});
$.ajax({
url: window.location.href,
type: 'post',
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
dataType: "json",
data: _data,
timeout: 60000,
success: function (data) {
layer.close(loading);
if (data.code === 1) {
layer.msg(data.msg, {icon: 1}, function () {
window.location.href = location.protocol + '//' + location.host + '/' + data.url;
});
} else {
layer.msg(data.msg, {icon: 2});
}
},
error: function (xhr, textstatus, thrown) {
layer.close(loading);
layer.msg('Status:' + xhr.status + '' + xhr.statusText + ',请稍后再试!', {icon: 2});
return false;
}
});
return false;
});
});
</script>
</body>
</html>