更新
This commit is contained in:
parent
5826045771
commit
df5cdfca24
57
app/api/controller/CronController.php
Normal file
57
app/api/controller/CronController.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
|
||||
use app\job\TaskInformationJob;
|
||||
use think\facade\Log;
|
||||
use app\common\model\Company;
|
||||
use app\common\model\task_template\TaskTemplate;
|
||||
use app\common\model\task_scheduling\TaskScheduling;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class HetongController extends BaseApiController
|
||||
{
|
||||
/**
|
||||
* 结算
|
||||
*/
|
||||
public function settlement(){
|
||||
$all=TaskSchedulingPlan::whereDay('end_time','yesterday')->where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray();
|
||||
foreach($all as $k=>$v){
|
||||
queue(TaskInformationJob::class,$v);
|
||||
}
|
||||
Log::info('定时任务结算执行成功'.date('Y-m-d H:i:s'));
|
||||
}
|
||||
|
||||
public function task_add(){
|
||||
//任务下发
|
||||
// $time=strtotime(date('Y-m-d',strtotime('-1 day')));
|
||||
$time = strtotime(date('Y-m-d'));
|
||||
// $tiem_end=$time+86399;
|
||||
$plan_all = TaskScheduling::where('cron_time', '<', $time)->where('status', 1)->with('company_info')->select()->toArray();
|
||||
$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 {
|
||||
unset($plan_all[$k]);
|
||||
}
|
||||
}
|
||||
$company_id = [];
|
||||
foreach ($plan_all as $k => $v) {
|
||||
foreach ($v['template'] as $kk => $vv) {
|
||||
queue(TaskAdd::class,['data'=>$vv,'data_two'=>$v]);
|
||||
}
|
||||
$company_id[] = $v['company_id'];
|
||||
}
|
||||
Company::where('id', 'in', $company_id)->inc('day_count')->update();
|
||||
TaskScheduling::where('id', 'in', $plan_ids)->update(['cron_time' => time()]);
|
||||
Log::info('定时任务下发执行成功' . date('Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user