You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ResetAdminPwd.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use app\services\system\admin\SystemAdminServices;
  9. /**
  10. * 重置密码
  11. * Class ResetAdminPwd
  12. * @package app\command
  13. */
  14. class ResetAdminPwd extends Command
  15. {
  16. protected function configure()
  17. {
  18. // 指令配置
  19. $this->setName('reset:password')
  20. ->addArgument('root', Argument::OPTIONAL, '管理员账号', 'admin')
  21. ->addOption('pwd', null, Option::VALUE_REQUIRED, '重置密码', '123456')
  22. ->setDescription('the update resetPwd command');
  23. }
  24. /**
  25. * @param Input $input
  26. * @param Output $output
  27. * @return int|void|null
  28. */
  29. protected function execute(Input $input, Output $output)
  30. {
  31. $account = $input->getArgument('root');
  32. if ($input->hasOption('pwd')) {
  33. $pwd = $input->getOption('pwd');
  34. }
  35. /** @var SystemAdminServices $systemAdminServices */
  36. $systemAdminServices = app()->make(SystemAdminServices::class);
  37. $admin = $systemAdminServices->get(['account' => $account, 'status' => 1, 'is_del' => 0]);
  38. if (!$admin) {
  39. $output->warning('管理员账号不存在');
  40. } else {
  41. $pwd_ = $systemAdminServices->passwordHash($pwd);
  42. $admin->pwd = $pwd_;
  43. $admin->save();
  44. $output->info('账号:' . $account . ';密码已重置:' . $pwd);
  45. }
  46. }
  47. }