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 <zhaoxiang051405@gmail.com> */ 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 @@ +<?php + +use think\migration\Migrator; +use think\migration\db\Column; + +class IniAdminGroup extends Migrator { + /** + * Change Method. + * + * Write your reversible migrations using this method. + * + * More information on writing migrations is available here: + * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class + * + * The following commands can be used in this method and Phinx will + * automatically reverse them when rolling back: + * + * createTable + * renameTable + * addColumn + * renameColumn + * addIndex + * addForeignKey + * + * Remember to call "create()" or "update()" and NOT "save()" when working + * with the Table class. + */ + + /** INSERT INTO `admin_group` (`id`, `name`, `description`, `status`, `hash`, `addTime`, `updateTime`, `image`, `hot`) + * VALUES + * (1, '默认分组', '默认分组', 1, 'default', 0, 0, '', 0); + */ + + public function up() { + $data = [ + 'name' => '默认分组', + 'description' => '默认分组', + 'status' => 1, + 'hash' => 'default', + 'create_time' => time(), + 'update_time' => time(), + 'image' => '', + 'hot' => 0, + ]; + + $this->table('admin_group')->insert($data)->saveData(); + } +}