TaskSystem/app/task/TaskCron.php

44 lines
1.4 KiB
PHP
Raw Normal View History

2023-08-10 10:29:57 +08:00
<?php
namespace app\task;
2023-08-10 17:10:12 +08:00
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\job\TaskAdd;
2023-08-11 16:35:07 +08:00
use think\facade\Log;
2023-08-10 17:10:12 +08:00
use yunwuxin\cron\Task;
2023-08-14 17:44:55 +08:00
use app\common\model\Company;
2023-08-18 16:32:41 +08:00
use app\common\model\task_template\TaskTemplate;
2023-08-14 17:44:55 +08:00
2023-08-10 10:29:57 +08:00
class TaskCron extends Task{
public function configure()
{
2023-08-18 16:32:41 +08:00
// $this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释
$this->everyMinute();
2023-08-10 10:29:57 +08:00
}
/**
* 执行任务
* @return mixed
*/
protected function execute()
{
2023-08-10 17:10:12 +08:00
//任务下发
2023-08-18 16:32:41 +08:00
// $time=strtotime(date('Y-m-d',strtotime('-1 day')));
2023-08-11 16:35:07 +08:00
$time=strtotime(date('Y-m-d'));
2023-08-18 16:32:41 +08:00
// $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();
2023-08-14 17:44:55 +08:00
$company_id=0;
2023-08-10 17:10:12 +08:00
foreach($all as $k=>$v){
queue(TaskAdd::class,$v);
2023-08-14 17:44:55 +08:00
$company_id=$v['company_id'];
}
if($company_id!=0){
Company::where('id',$company_id)->inc('day_count')->update();
2023-08-10 17:10:12 +08:00
}
2023-08-18 16:32:41 +08:00
Log::error('定时任务下发执行成功'.date('Y-m-d H:i:s'));
2023-08-10 10:29:57 +08:00
//...具体的任务执行
}
}