A:
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel {
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
// 已上线7天的需求邮件推送评分链接
\App\Console\Commands\MailPushLink::class,
// 已上线14天的需求邮件推送评分链接
\App\Console\Commands\MailPushLink2::class,
// 每月1号跑上个月的个人需求得分
\App\Console\Commands\autoMonthDemandScore::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// 已上线7天的需求邮件推送评分链接
$schedule->command('MailPushLink')->dailyAt('08:00');
// 已上线14天的需求邮件推送评分链接
$schedule->command('MailPushLink2')->dailyAt('09:00');
// 每月1号跑上个月的个人需求得分
$schedule->command('autoMonthDemandScore')->monthlyOn('08:00');
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
B:
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;
use Log;
use App\Services\Demand\DemandService;
class MailPushLink extends Command {
// 命令名称
protected $name = 'MailPushLink';
// 命令描述,没什么用
protected $description = '已上线7天的需求邮件推送评分链接';
public function __construct() {
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle() {
$this->MailPushLink();
}
public function MailPushLink() {
$info = DemandService::MailPushLink(date('Y-m-d 23:59:59', strtotime('-3 day')), 0);
log::info($info);
}
}
思路:
1,/app/Console/Commands 目录下创建文件,写入上面 B 代码
2,/app/Console/Kernel.php 文件修改,参考上面 A 代码
3,linux 上运行:php 项目路径/artisan MailPushLink