TaskSystem/app/job/TaskInformationJob.php

50 lines
1.7 KiB
PHP
Raw Normal View History

2023-08-09 14:43:30 +08:00
<?php
namespace app\job;
2023-08-10 17:10:12 +08:00
use app\common\logic\finance\ShareProfit;
use app\common\model\task\Task;
2023-08-09 14:43:30 +08:00
use think\queue\Job;
2023-08-14 17:44:55 +08:00
use think\facade\Log;
2023-08-09 14:43:30 +08:00
2023-08-10 17:10:12 +08:00
/**
* 任务结算执行的具体逻辑
*/
2023-08-09 14:43:30 +08:00
class TaskInformationJob
{
public function fire(Job $job, $data)
{
if ($job->attempts() > 3) {
//通过这个方法可以检查这个任务已经重试了几次了
}
2023-08-10 17:10:12 +08:00
$task_id=explode(',',$data['task_id']);
2023-08-14 09:12:55 +08:00
$task_count=Task::where('id','in',$task_id)->field('director_uid')->with('director_info')->select();
2023-08-14 17:44:55 +08:00
if(empty($task_count)){
Log::error('任务结算失败任务id'.$task_id);
}
2023-08-10 17:10:12 +08:00
if(count($task_count)==count($task_id)){
2023-08-11 16:35:07 +08:00
$name_arr=[];
foreach ($task_count as $key => $value) {
$name_arr[$key]=$value['director_info']['nickname'];
}
$name=implode('、',$name_arr);
2023-08-10 17:10:12 +08:00
$arr['money']=$data['template_info']['money'];
$arr['company_id']=$data['scheduling']['company_id'];
2023-08-11 16:35:07 +08:00
$arr['msg']='来自任务【'.$data['template_info']['title'].'】,执行人:'.$name.',的任务结算';
2023-08-14 17:44:55 +08:00
$arr['proportion_one']=$data['template_info']['proportion_one'];
$arr['proportion_two']=$data['template_info']['proportion_two'];
2023-08-10 17:10:12 +08:00
$arr['sn']=$data['sn'];
2023-08-14 17:44:55 +08:00
$arr['id']=$data['id'];
2023-08-10 17:10:12 +08:00
(new ShareProfit())->first($arr);
}
2023-08-09 14:43:30 +08:00
//如果任务执行成功后 记得删除任务不然这个任务会重复执行直到达到最大重试次数后失败后执行failed方法
$job->delete();
}
2023-08-15 09:52:20 +08:00
public function failed($data){
Log::error('任务结算失败'.$data);
// ...任务达到最大重试次数后,失败了
}
2023-08-09 14:43:30 +08:00
}