From aa9ce0f89a3997b41028f7264188a957c732b15e Mon Sep 17 00:00:00 2001 From: zhaoxiang Date: Tue, 14 May 2019 11:56:06 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E7=BB=A7=E7=BB=AD=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=AE=89=E8=A3=85=E8=84=9A=E6=9C=AC=E3=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=9D=E5=A7=8B=E5=8C=96=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/command/Install.php | 23 +++++++-- .../20190514034923_ini_admin_group.php | 48 +++++++++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 database/migrations/20190514034923_ini_admin_group.php diff --git a/application/command/Install.php b/application/command/Install.php index 4e0f6d3..b83f1a0 100644 --- a/application/command/Install.php +++ b/application/command/Install.php @@ -2,11 +2,14 @@ namespace app\command; +use app\util\Strs; +use app\util\Tools; use think\console\Command; use think\console\Input; use think\console\input\Option; use think\console\Output; use think\Db; +use think\exception\PDOException; class Install extends Command { @@ -24,18 +27,30 @@ class Install extends Command { * @param Output $output * @return int|void|null * @throws \think\Exception + * php think apiadmin:install --db mysql://root:123456@127.0.0.1:3306/apiadmin2#utf8 * @author zhaoxiang */ protected function execute(Input $input, Output $output) { if ($input->hasOption('db')) { + $now = time(); $conn = Db::connect($input->getOption('db'))->table('admin_user'); + $user = $input->getOption('username'); + $pass = $input->getOption('password'); + $auth_key = Strs::uuid(); try { - $conn->insert([ + $conn = Db::connect($input->getOption('db'))->table('admin_user'); +// $root_id = $conn->insertGetId([ +// 'username' => $user, +// 'nickname' => $user, +// 'create_time' => $now, +// 'update_time' => $now, +// 'password' => Tools::userMd5($pass, $auth_key), +// 'create_ip' => ip2long('127.0.0.1') +// ]); - ]); - } catch (\Exception $e) { - echo 123123; + } catch (\PDOException $e) { + $output->highlight($e->getMessage()); } } else { $output->highlight("请输入数据库配置"); diff --git a/database/migrations/20190514034923_ini_admin_group.php b/database/migrations/20190514034923_ini_admin_group.php new file mode 100644 index 0000000..dcaba81 --- /dev/null +++ b/database/migrations/20190514034923_ini_admin_group.php @@ -0,0 +1,48 @@ + '默认分组', + 'description' => '默认分组', + 'status' => 1, + 'hash' => 'default', + 'create_time' => time(), + 'update_time' => time(), + 'image' => '', + 'hot' => 0, + ]; + + $this->table('admin_group')->insert($data)->saveData(); + } +}