mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 继续完善用户安装脚本、数据初始化脚本
This commit is contained in:
parent
217da10fff
commit
aa9ce0f89a
@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace app\command;
|
namespace app\command;
|
||||||
|
|
||||||
|
use app\util\Strs;
|
||||||
|
use app\util\Tools;
|
||||||
use think\console\Command;
|
use think\console\Command;
|
||||||
use think\console\Input;
|
use think\console\Input;
|
||||||
use think\console\input\Option;
|
use think\console\input\Option;
|
||||||
use think\console\Output;
|
use think\console\Output;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
|
use think\exception\PDOException;
|
||||||
|
|
||||||
class Install extends Command {
|
class Install extends Command {
|
||||||
|
|
||||||
@ -24,18 +27,30 @@ class Install extends Command {
|
|||||||
* @param Output $output
|
* @param Output $output
|
||||||
* @return int|void|null
|
* @return int|void|null
|
||||||
* @throws \think\Exception
|
* @throws \think\Exception
|
||||||
|
* php think apiadmin:install --db mysql://root:123456@127.0.0.1:3306/apiadmin2#utf8
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
*/
|
*/
|
||||||
protected function execute(Input $input, Output $output) {
|
protected function execute(Input $input, Output $output) {
|
||||||
if ($input->hasOption('db')) {
|
if ($input->hasOption('db')) {
|
||||||
|
$now = time();
|
||||||
$conn = Db::connect($input->getOption('db'))->table('admin_user');
|
$conn = Db::connect($input->getOption('db'))->table('admin_user');
|
||||||
|
$user = $input->getOption('username');
|
||||||
|
$pass = $input->getOption('password');
|
||||||
|
$auth_key = Strs::uuid();
|
||||||
|
|
||||||
try {
|
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 (\PDOException $e) {
|
||||||
} catch (\Exception $e) {
|
$output->highlight($e->getMessage());
|
||||||
echo 123123;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$output->highlight("请输入数据库配置");
|
$output->highlight("请输入数据库配置");
|
||||||
|
48
database/migrations/20190514034923_ini_admin_group.php
Normal file
48
database/migrations/20190514034923_ini_admin_group.php
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user