TaskSystem/app/task/TaskCron.php
2023-08-24 14:30:42 +08:00

44 lines
1.4 KiB
PHP

<?php
namespace app\task;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\job\TaskAdd;
use think\facade\Log;
use yunwuxin\cron\Task;
use app\common\model\Company;
use app\common\model\task_template\TaskTemplate;
class TaskCron extends Task{
public function configure()
{
$this->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=[];
foreach($all as $k=>$v){
queue(TaskAdd::class,$v);
$company_id[]=$v['company_id'];
}
$arr=array_unique($company_id);
if(count($arr)){
Company::where('id','in',$arr)->inc('day_count')->update();
}
Log::error('定时任务下发执行成功'.date('Y-m-d H:i:s'));
//...具体的任务执行
}
}