ResetAdminPwd.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\command;
  12. use think\console\Command;
  13. use think\console\Input;
  14. use think\console\Output;
  15. use think\console\input\Argument;
  16. use think\console\input\Option;
  17. use app\services\system\admin\SystemAdminServices;
  18. /**
  19. * 重置密码
  20. * Class ResetAdminPwd
  21. * @package app\command
  22. */
  23. class ResetAdminPwd extends Command
  24. {
  25. protected function configure()
  26. {
  27. // 指令配置
  28. $this->setName('reset:password')
  29. ->addArgument('root', Argument::OPTIONAL, '管理员账号', 'admin')
  30. ->addOption('pwd', null, Option::VALUE_REQUIRED, '重置密码', '123456')
  31. ->setDescription('the update resetPwd command');
  32. }
  33. /**
  34. * @param Input $input
  35. * @param Output $output
  36. * @return int|void|null
  37. */
  38. protected function execute(Input $input, Output $output)
  39. {
  40. $account = $input->getArgument('root');
  41. if ($input->hasOption('pwd')) {
  42. $pwd = $input->getOption('pwd');
  43. }
  44. /** @var SystemAdminServices $systemAdminServices */
  45. $systemAdminServices = app()->make(SystemAdminServices::class);
  46. $admin = $systemAdminServices->get(['account' => $account, 'status' => 1, 'is_del' => 0]);
  47. if (!$admin) {
  48. $output->warning('管理员账号不存在');
  49. } else {
  50. $pwd_ = $systemAdminServices->passwordHash($pwd);
  51. $admin->pwd = $pwd_;
  52. $admin->save();
  53. $output->info('账号:' . $account . ';密码已重置:' . $pwd);
  54. }
  55. }
  56. }