42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace app\task;
|
|
|
|
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
|
|
use app\job\TaskAdd;
|
|
use app\job\TaskInformationJob;
|
|
use think\facade\Log;
|
|
use yunwuxin\cron\Task;
|
|
class TaskCron extends Task{
|
|
|
|
public function configure()
|
|
{
|
|
$this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释
|
|
// $this->everyMinute();
|
|
}
|
|
/**
|
|
* 执行任务
|
|
* @return mixed
|
|
*/
|
|
protected function execute()
|
|
{
|
|
Log::error('定时任务执行成功'.date('Y-m-d H:i:s'));
|
|
|
|
//任务结算
|
|
$all=TaskSchedulingPlan::whereDay('start_time','yesterday')->with(['template_info','scheduling'])->select()->toArray();
|
|
foreach($all as $k=>$v){
|
|
queue(TaskInformationJob::class,$v);
|
|
}
|
|
//任务下发
|
|
// $time=strtotime(date('Y-m-d',strtotime('+1 day')));
|
|
$time=strtotime(date('Y-m-d'));
|
|
$tiem_end=$time+86399;
|
|
$all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling'])->select()->toArray();
|
|
foreach($all as $k=>$v){
|
|
queue(TaskAdd::class,$v);
|
|
}
|
|
Log::error('定时任务执行成功2');
|
|
//...具体的任务执行
|
|
}
|
|
}
|