daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释 $this->everyMinute(); } /** * 执行任务 * @return mixed */ protected function execute() { //任务下发 // $time=strtotime(date('Y-m-d',strtotime('-1 day'))); $time=strtotime(date('Y-m-d')); // $tiem_end=$time+86399; $all=TaskTemplate::where('cron_time','<',$time)->where('status',1)->with('company')->select()->toArray(); // $all=TaskSchedulingPlan::where('start_time','between',[$time,$tiem_end])->where('is_execute',0)->with(['template_info','scheduling'])->select()->toArray(); $company_id=0; foreach($all as $k=>$v){ queue(TaskAdd::class,$v); $company_id=$v['company_id']; } if($company_id!=0){ Company::where('id',$company_id)->inc('day_count')->update(); } Log::error('定时任务下发执行成功'.date('Y-m-d H:i:s')); //...具体的任务执行 } }