mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 23:42:48 +08:00
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace base\common\command\admin\role;
|
|
|
|
use app\admin\model\SystemAuth;
|
|
use app\common\console\Command;
|
|
use think\console\Input;
|
|
use think\console\input\Option;
|
|
use think\console\Output;
|
|
|
|
class AdminRoleCreateBase extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
parent::configure();
|
|
|
|
$this->setName('admin:role:create')
|
|
->addOption('title', null, Option::VALUE_REQUIRED, '角色名称')
|
|
->addOption('remark', null, Option::VALUE_OPTIONAL, '角色备注')
|
|
->setDescription('创建角色');
|
|
}
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$title = $input->getOption('title');
|
|
$remark = $input->getOption('remark');
|
|
|
|
if (empty($title)) {
|
|
$output->error('角色名称不能为空');
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
$auth = new SystemAuth();
|
|
$auth->title = $title;
|
|
$auth->remark = $remark ?? '';
|
|
$auth->sort = 0;
|
|
$auth->status = 1;
|
|
$auth->save();
|
|
|
|
$output->info('角色创建成功');
|
|
$output->info('角色ID: ' . $auth->id);
|
|
$output->info('角色名称: ' . $auth->title);
|
|
} catch (\Throwable $e) {
|
|
$output->error('创建角色失败: ' . $e->getMessage());
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|