2023-08-09 14:43:30 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\job;
|
|
|
|
|
|
2023-08-16 15:44:36 +08:00
|
|
|
|
use app\api\controller\RemoteController;
|
2023-08-10 17:10:12 +08:00
|
|
|
|
use app\common\logic\finance\ShareProfit;
|
|
|
|
|
use app\common\model\task\Task;
|
2023-08-15 13:46:31 +08:00
|
|
|
|
use Symfony\Component\HttpClient\HttpClient;
|
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-15 13:46:31 +08:00
|
|
|
|
use app\common\model\Company;
|
2023-08-16 13:51:57 +08:00
|
|
|
|
use app\common\model\informationg\UserInformationg;
|
2023-08-16 15:44:36 +08:00
|
|
|
|
use think\facade\App;
|
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)
|
|
|
|
|
{
|
2023-08-15 13:46:31 +08:00
|
|
|
|
// if ($job->attempts() > 1) {
|
|
|
|
|
// //通过这个方法可以检查这个任务已经重试了几次了
|
|
|
|
|
// }
|
|
|
|
|
$company = Company::where('id', $data['company_id'])->field('id,deposit,company_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足
|
2023-08-16 00:14:09 +08:00
|
|
|
|
$arr['status'] = 0;
|
2023-08-15 18:14:27 +08:00
|
|
|
|
//信息更新
|
2023-08-15 13:46:31 +08:00
|
|
|
|
if ($data['template_info']['type'] == 31) {
|
2023-08-16 13:51:57 +08:00
|
|
|
|
if ($data['template_info']['information_count'] < $data['template_info']['information_day_count']) {
|
2023-08-16 11:44:04 +08:00
|
|
|
|
Log::info('任务结算失败,信息更新未达到要求:' . json_encode($data));
|
2023-08-21 10:32:45 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5]);
|
2023-08-15 13:46:31 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-08-16 11:44:04 +08:00
|
|
|
|
$name = '小组队长';
|
2023-08-17 15:30:58 +08:00
|
|
|
|
$arr['status'] = 1;
|
2023-08-16 00:14:09 +08:00
|
|
|
|
} elseif
|
|
|
|
|
//交易金额
|
2023-08-16 11:44:04 +08:00
|
|
|
|
($data['template_info']['type'] == 33) {
|
2023-08-16 15:44:36 +08:00
|
|
|
|
$shang_date_total_price = App(RemoteController::class)->shang_date_total_price($company);
|
|
|
|
|
if ($shang_date_total_price == false) {
|
|
|
|
|
Log::info('任务结算失败,交易金额未达到要求:' . json_encode($data));
|
2023-08-21 10:32:45 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5]);
|
2023-08-15 13:46:31 +08:00
|
|
|
|
return false;
|
2023-08-11 16:35:07 +08:00
|
|
|
|
}
|
2023-08-16 15:44:36 +08:00
|
|
|
|
$name = $shang_date_total_price['name'];
|
|
|
|
|
$arr['status'] = $shang_date_total_price['arr']['status'];
|
2023-08-16 00:14:09 +08:00
|
|
|
|
} else {
|
2023-08-18 16:32:41 +08:00
|
|
|
|
//其他类型任务
|
2023-08-16 00:14:09 +08:00
|
|
|
|
$task_count = Task::where('id', $data['task_id'])->field('director_uid')->where('status', 3)->with('director_info')->find();
|
|
|
|
|
if (empty($task_count)) {
|
2023-08-18 16:32:41 +08:00
|
|
|
|
Log::info('列105 任务 '.$data['template_info']['title'].'结算失败,任务为空:' . json_encode($data));
|
2023-08-21 10:32:45 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5]);
|
2023-08-16 00:14:09 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$name = $task_count['director_info']['nickname'];
|
|
|
|
|
$arr['status'] = 1;
|
2023-08-10 17:10:12 +08:00
|
|
|
|
}
|
2023-08-09 14:43:30 +08:00
|
|
|
|
|
2023-08-16 00:14:09 +08:00
|
|
|
|
try {
|
2023-08-15 13:46:31 +08:00
|
|
|
|
$arr['money'] = $data['template_info']['money'];
|
|
|
|
|
$arr['company_id'] = $data['scheduling']['company_id'];
|
2023-08-16 00:14:09 +08:00
|
|
|
|
$arr['msg'] = '来自任务【' . $data['template_info']['title'] . '】,完成人:' . $name . ',的任务结算';
|
2023-08-15 13:46:31 +08:00
|
|
|
|
$arr['proportion_one'] = $data['template_info']['proportion_one'];
|
|
|
|
|
$arr['proportion_two'] = $data['template_info']['proportion_two'];
|
|
|
|
|
$arr['sn'] = $data['sn'];
|
|
|
|
|
$arr['id'] = $data['id'];
|
|
|
|
|
} catch (\Exception $e) {
|
2023-08-18 16:32:41 +08:00
|
|
|
|
Log::error('列122 任务结算失败:'.$data['template_info']['title'] . $e->getMessage() . json_encode($data));
|
2023-08-15 13:46:31 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-08-18 16:32:41 +08:00
|
|
|
|
if($arr['status']==1){
|
|
|
|
|
(new ShareProfit())->first($arr, $company);
|
|
|
|
|
}else{
|
|
|
|
|
Log::error('任务结算失败:'.$data['template_info']['title'].'未完成' . json_encode($data));
|
|
|
|
|
}
|
2023-08-09 14:43:30 +08:00
|
|
|
|
//如果任务执行成功后 记得删除任务,不然这个任务会重复执行,直到达到最大重试次数后失败后,执行failed方法
|
|
|
|
|
$job->delete();
|
|
|
|
|
}
|
2023-08-15 13:46:31 +08:00
|
|
|
|
public function failed($data)
|
|
|
|
|
{
|
|
|
|
|
Log::error('任务结算失败' . $data);
|
2023-08-15 09:52:20 +08:00
|
|
|
|
// ...任务达到最大重试次数后,失败了
|
|
|
|
|
}
|
2023-08-09 14:43:30 +08:00
|
|
|
|
}
|