12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace app\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\console\input\Argument;
- use think\console\input\Option;
- use app\services\system\admin\SystemAdminServices;
- class ResetAdminPwd extends Command
- {
- protected function configure()
- {
-
- $this->setName('reset:password')
- ->addArgument('root', Argument::OPTIONAL, '管理员账号', 'admin')
- ->addOption('pwd', null, Option::VALUE_REQUIRED, '重置密码', '123456')
- ->setDescription('the update resetPwd command');
- }
-
- protected function execute(Input $input, Output $output)
- {
- $account = $input->getArgument('root');
- if ($input->hasOption('pwd')) {
- $pwd = $input->getOption('pwd');
- }
-
- $systemAdminServices = app()->make(SystemAdminServices::class);
- $admin = $systemAdminServices->get(['account' => $account, 'status' => 1, 'is_del' => 0]);
- if (!$admin) {
- $output->warning('管理员账号不存在');
- } else {
- $pwd_ = $systemAdminServices->passwordHash($pwd);
- $admin->pwd = $pwd_;
- $admin->save();
- $output->info('账号:' . $account . ';密码已重置:' . $pwd);
- }
- }
- }
|