TaskSystem/app/task/TaskCron.php

119 lines
4.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-28 09:31:13 +08:00
use app\common\logic\task\TaskLogic;
use app\common\model\task_scheduling\TaskScheduling;
2023-08-28 11:13:03 +08:00
class TaskCron extends Task
{
2023-08-10 10:29:57 +08:00
public function configure()
{
2023-08-28 15:04:10 +08:00
$this->daily(); //设置任务的周期,每天执行一次,更多的方法可以查看源代码,都有注释
// $this->everyMinute();//每分钟
2023-08-10 10:29:57 +08:00
}
/**
* 小组服务公司执行任务下发
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-28 11:13:03 +08:00
$time = strtotime(date('Y-m-d'));
2023-08-18 16:32:41 +08:00
// $tiem_end=$time+86399;
// 查询系统目前小组公司的任务安排
$plan_all = TaskScheduling::where('cron_time', '<', $time)->where('status', 1)->where('company_type', 18)->with('company_info')->select()->toArray();
2023-08-28 11:13:03 +08:00
$plan_ids = [];
foreach ($plan_all as $k => $v) {
$all = TaskTemplate::where('status', 1)->where('task_scheduling', $v['id'])->limit(30)->select()->toArray();
$plan_ids[] = $v['id'];
if ($all) {
$plan_all[$k]['template'] = $all;
} else {
2023-08-28 09:31:13 +08:00
unset($plan_all[$k]);
}
}
2023-08-28 11:13:03 +08:00
$company_id = [];
foreach ($plan_all as $k => $v) {
foreach ($v['template'] as $kk => $vv) {
queue(TaskAdd::class,['data'=>$vv,'data_two'=>$v]);
2023-08-28 09:31:13 +08:00
}
2023-08-28 14:45:37 +08:00
$company_id[] = $v['company_id'];
2023-08-14 17:44:55 +08:00
}
2023-08-28 11:13:03 +08:00
Company::where('id', 'in', $company_id)->inc('day_count')->update();
TaskScheduling::where('id', 'in', $plan_ids)->update(['cron_time' => time()]);
2023-08-29 23:05:08 +08:00
Log::info('定时任务下发执行成功' . date('Y-m-d H:i:s'));
2023-08-10 10:29:57 +08:00
//...具体的任务执行
}
2023-08-28 09:31:13 +08:00
2023-08-28 11:13:03 +08:00
public function stage_inspection($v, $moeny_type = 'moeny', $title = '一')
{
$count_moeny = 0;
foreach ($v['template'] as $kkkk => $vvvv) {
$count_moeny += $vvvv[$moeny_type];
2023-08-28 09:31:13 +08:00
}
2023-08-28 11:13:03 +08:00
if ($count_moeny > 200) {
Log::info($title . '阶段金额大于200无法下达' . json_encode($v['company_info']));
return false;
2023-08-28 09:31:13 +08:00
}
return true;
}
2023-08-10 10:29:57 +08:00
}
2023-08-28 11:13:03 +08:00
// foreach($plan_all as $k=>$v){
// foreach($v['template'] as $kkk=>$vvv){
// if ($v['types'] == 1 ||$vvv['types'] == 3) {
// if ($v['company_info'] && $v['company_info']['day_count'] <=$vvv['stage_day_one']) {
// $res=$this->stage_inspection($v['template'],'moeny','一');
// if($res==false){
// return false;
// }
// } else {
// $res=$this->stage_inspection($v['template'],'money_two','二');
// if($res==false){
// return false;
// }
// }
// } elseif ($v['types'] == 2) {
// if ($v['company_info']['day_count'] <=$vvv['stage_day_one']) {
// $res=$this->stage_inspection($v['template'],'moeny','一');
// if($res==false){
// return false;
// }
// } elseif ($v['company_info']['day_count'] <=$vvv['stage_day_two']) {
// $res=$this->stage_inspection($v['template'],'money_two','二');
// if($res==false){
// return false;
// }
// } else {
// $res=$this->stage_inspection($v['template'],'money_three','三');
// if($res==false){
// return false;
// }
// }
// } else {
// if ( $v['company_info']['day_count'] <=$vvv['stage_day_one']) {
// $res=$this->stage_inspection($v['template'],'money_three','三');
// if($res==false){
// return false;
// }
// } else {
// $res=$this->stage_inspection($v['template'],'money_two','二');
// if($res==false){
// return false;
// }
// }
// }
// }
// foreach($v['template'] as $kk=>$vv){
// TaskLogic::CronAdd($vv,$v);
// }
// $company_id[]=$v['company_id'];
// }