Skip to content

系统命令

php think tm

===============系统命令行==============
(1) 修改后台密码   (2) 清除登录限制
(3) 清除系统日志   (4) 清除系统缓存
=======================================

【修改后台密码】
命令: php think tm 1 --account admin --password 123456
参数:
    --account : 要修改的账号
    --password : 修改的新密码
        
【清除登录限制】
命令: php think tm 2 --account admin
参数:
    --account : 要清除限制的账号

【清除系统日志】
命令: php think tm 3 --reserve_day 30
参数:
    --reserve_day : 保留日志天数 

【清除系统缓存】
命令: php think tm 4
参数:

访问控制器

可跳过路由限制,直接访问控制方法

php think action

php think action admin/test/index --option name=jack,age=10

参数:
    --action : 控制器路径
    --option : 参数

创建命令

命令文件统一放在app/common/command目录下

以创建订单order命令为例,可传参params

<?php

namespace app\common\command;

use Exception;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Option;

/**
 * 计划任务
 */
class Crontab extends Command
{
    /**
     * 指令配置
     */
    protected function configure()
    {
        $this->setName('order')->setDescription('订单任务')->addOption('params', null, Option::VALUE_REQUIRED, '参数');
    }

    /**
     * 执行任务
     * @param Input $input
     * @param Output $output
     * @return bool
     */
    protected function execute(Input $input, Output $output): bool
    {
        // 订单任务
        $params  = $input->getOption('params'); // 获取参数
        return true;
    }
}

添加命令到配置文件,文件路径:config/console.php

<?php
return [
    // 指令定义
    'commands' => [
        // 订单命令
        "order"=>"app\common\command\Order",
    ],
];

执行命令

php think order

Released under the Apache-2.0 License.