123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- namespace addons\shopro\console;
- use think\Db;
- use Exception;
- use think\console\input\Argument;
- use think\console\input\Option;
- use app\admin\model\shopro\Admin;
- use think\Queue;
- class ShoproHelp extends Command
- {
- protected $input = null;
- protected $output = null;
-
- protected $commands = [
- ['code' => "0", 'name' => 'cancel', 'desc' => '取消'],
- ['code' => "1", 'name' => 'all', 'desc' => 'shopro 帮助工具列表'],
-
-
-
- ['code' => "4", 'name' => 'admin_reset_password', 'desc' => '重置管理员密码'],
- ['code' => "5", 'name' => 'admin_clear_login_fail', 'desc' => '清除管理员登录锁定状态'],
-
-
-
- ['code' => "9", 'name' => 'queue', 'desc' => '检查队列状态'],
-
- ];
-
- protected function configure()
- {
- $this->setName('shopro:help')
- ->addArgument('code', Argument::OPTIONAL, "请输入操作编号")
- ->setDescription('shopro 帮助命令');
- }
-
- public function all()
- {
- $this->output->newLine();
- $this->output->writeln("shopro 帮助命令行");
- $this->output->writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
- $this->output->newLine();
- if (!is_dir(RUNTIME_PATH . 'storage')) {
- @mkdir(RUNTIME_PATH . 'storage', 0755, true);
- }
- foreach ($this->commands as $command) {
- $this->output->writeln("[" . $command['code'] . "] " . $command['desc']);
- }
- $this->output->newLine();
- $code = $this->output->ask(
- $this->input,
- '请输入命令代号',
- '0'
- );
- $this->choose($code);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public function adminResetPassword()
- {
- $this->output->newLine();
- $this->output->writeln("重置管理员密码");
- $this->output->writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
- $this->output->newLine();
- $username = $this->output->ask(
- $this->input,
- '请输入要重置的管理员账号'
- );
- $admin = null;
- if ($username) {
- $admin = Admin::where('username', $username)->find();
- }
- if (!$admin) {
- $this->output->error("请输入正确的管理员账号");
- return false;
- }
- $password = $this->output->ask(
- $this->input,
- '请输入要设置的密码[6-16]'
- );
- if (empty($password) || strlen($password) < 6 || strlen($password) > 16) {
- $this->output->error("请输入正确的密码");
- return false;
- }
-
- $admin->salt = $admin->salt ?: mt_rand(1000, 9999);
- $admin->password = md5(md5($password) . $admin->salt);
- $admin->save();
- $this->output->writeln("账号 [" . $admin->username . "] 的密码重置成功");
- return true;
- }
-
- public function adminClearLoginFail()
- {
- $this->output->newLine();
- $this->output->writeln("清除管理员登录锁定状态");
- $this->output->writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
- $this->output->newLine();
- $username = $this->output->ask(
- $this->input,
- '请输入要清除的管理员账号'
- );
- $admin = null;
- if ($username) {
- $admin = Admin::where('username', $username)->find();
- }
- if (!$admin) {
- $this->output->error("请输入正确的管理员账号");
- return false;
- }
- $admin->loginfailure = 0;
- $admin->save();
- $this->output->writeln("账号 [" . $admin->username . "] 锁定状态清除成功");
- return true;
- }
-
- public function queue()
- {
- @unlink(RUNTIME_PATH . 'storage/queue/shopro.log');
- @unlink(RUNTIME_PATH . 'storage/queue/shopro-high.log');
- $queue = config('queue');
- $connector = $queue['connector'] ?? 'sync';
- if ($connector == 'sync') {
- $this->output->error("队列驱动不可以使用 sync,请选择 database 或者 redis 配置");
- return false;
- }
- $this->output->writeln('当前队列驱动为:' . $connector);
- $this->output->writeln('正在添加测试队列...');
- $this->output->newLine();
-
- Queue::push('\addons\shopro\job\Test@shopro', [], 'shopro');
- Queue::push('\addons\shopro\job\Test@shoproHigh', [], 'shopro-high');
- $this->output->writeln('测试队列添加成功');
- $this->output->writeln('请检查 ' . str_replace('\\', '/', RUNTIME_PATH . 'storage/queue') . '目录下是否存在如下文件,并且文件内容为当前测试的时间');
- $this->output->newLine();
- $this->output->writeln(str_replace('\\', '/', RUNTIME_PATH . 'storage/queue') . 'shopro.log // 如果没有该文件,则普通优先级队列未监听');
- $this->output->writeln(str_replace('\\', '/', RUNTIME_PATH . 'storage/queue') . 'shopro-high.log // 如果没有该文件,则高优先级队列未监听');
- $this->output->newLine();
- return true;
- }
- }
|