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-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-28 09:31:13 +08:00
|
|
|
|
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
|
2023-08-29 23:05:08 +08:00
|
|
|
|
use app\common\model\task_template\TaskTemplate;
|
2023-09-04 16:42:24 +08:00
|
|
|
|
use think\facade\Db;
|
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) {
|
|
|
|
|
// //通过这个方法可以检查这个任务已经重试了几次了
|
|
|
|
|
// }
|
2023-08-21 15:14:39 +08:00
|
|
|
|
try {
|
2023-09-06 09:36:41 +08:00
|
|
|
|
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 1]);
|
2023-08-31 10:01:11 +08:00
|
|
|
|
$company = Company::where('id', $data['company_id'])->field('id,deposit,responsible_area,company_money,shareholder_money,user_id,day_count,company_type,province,city,area,street,village,brigade')->find(); // 可能要判断预存金是否满足
|
2023-08-21 15:14:39 +08:00
|
|
|
|
$arr['status'] = 0;
|
2023-08-29 18:11:54 +08:00
|
|
|
|
$arr['company_account_type'] = 1;
|
2023-08-21 15:14:39 +08:00
|
|
|
|
//信息更新
|
|
|
|
|
if ($data['template_info']['type'] == 31) {
|
|
|
|
|
if ($data['template_info']['information_count'] < $data['template_info']['information_day_count']) {
|
2023-08-28 14:45:37 +08:00
|
|
|
|
Log::info('信息更新任务,信息更新未达到要求:' . json_encode($data));
|
2023-08-21 15:14:39 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5]);
|
2023-09-07 14:50:16 +08:00
|
|
|
|
TaskTemplate::where('id',$data['template_id'])->update(['information_count'=>$data['template_info']['information_day_count']]);
|
2023-08-21 15:14:39 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$name = '小组队长';
|
|
|
|
|
$arr['status'] = 1;
|
2023-08-28 14:45:37 +08:00
|
|
|
|
$task = Task::where('id', $data['task_id'])->field('director_uid,money')->where('status', 3)->find();
|
|
|
|
|
$arr['money'] = $task['money'];
|
2023-08-28 09:31:13 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 3]);
|
2023-08-21 15:14:39 +08:00
|
|
|
|
} elseif
|
|
|
|
|
//交易金额
|
|
|
|
|
($data['template_info']['type'] == 33) {
|
2023-09-13 14:56:44 +08:00
|
|
|
|
$shang_date_total_price = App(RemoteController::class)->shang_date_total_price($company,[],$data['template_id']);
|
|
|
|
|
|
2023-08-21 15:14:39 +08:00
|
|
|
|
if ($shang_date_total_price == false) {
|
2023-08-28 14:45:37 +08:00
|
|
|
|
Log::info('交易金额任务,交易金额未达到要求:' . json_encode($data));
|
2023-08-28 09:31:13 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5]);
|
2023-08-21 15:14:39 +08:00
|
|
|
|
return false;
|
2023-08-24 11:52:56 +08:00
|
|
|
|
}
|
2023-08-29 23:05:08 +08:00
|
|
|
|
$transaction_pool=$data['template_info']['transaction_pool'];//交易金额剩余池
|
2023-09-13 13:09:53 +08:00
|
|
|
|
$count_money=bcadd($shang_date_total_price['arr']['total_price'],$transaction_pool,2);//交易金额加资金池金额
|
2023-09-09 09:46:59 +08:00
|
|
|
|
if($count_money>$shang_date_total_price['arr']['day_money']){
|
|
|
|
|
$day_money=bcsub($count_money,$shang_date_total_price['arr']['day_money'],2);//当计算剩余池before_transaction_pool
|
|
|
|
|
$shang_date_total_price['arr']['before_transaction_pool']=$transaction_pool;//变化前
|
2023-09-13 14:56:44 +08:00
|
|
|
|
$shang_date_total_price['arr']['after_count_transaction_pool']=$count_money;//变化后
|
2023-09-09 09:46:59 +08:00
|
|
|
|
$shang_date_total_price['arr']['after_transaction_pool']=$day_money;//变化后
|
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 3,'extend'=>json_encode(['transaction'=>$shang_date_total_price])]);
|
|
|
|
|
TaskTemplate::where('id',$data['template_info']['id'])->update(['transaction_pool'=>$day_money]);
|
2023-08-29 23:05:08 +08:00
|
|
|
|
$shang_date_total_price['arr']['status']=1;
|
2023-09-09 09:46:59 +08:00
|
|
|
|
}else{
|
|
|
|
|
Log::info('交易金额任务,交易金额小于今日金额:' . json_encode($data));
|
2023-09-13 13:09:53 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5,'transaction_pool'=>$count_money]);
|
2023-09-09 09:46:59 +08:00
|
|
|
|
return false;
|
2023-08-21 15:14:39 +08:00
|
|
|
|
}
|
|
|
|
|
$name = $shang_date_total_price['name'];
|
|
|
|
|
$arr['status'] = $shang_date_total_price['arr']['status'];
|
2023-08-28 14:45:37 +08:00
|
|
|
|
$task = Task::where('id', $data['task_id'])->field('money')->find();
|
|
|
|
|
$arr['money'] = $task['money'];
|
2023-08-21 16:32:56 +08:00
|
|
|
|
} elseif
|
|
|
|
|
//三轮车
|
|
|
|
|
($data['template_info']['type'] == 32){
|
2023-08-28 14:45:37 +08:00
|
|
|
|
$task = Task::where('id', $data['task_id'])->field('director_uid,money')->where('status', 3)->with('director_info')->find();
|
2023-08-21 16:32:56 +08:00
|
|
|
|
if(empty($task)){
|
2023-08-28 14:45:37 +08:00
|
|
|
|
Log::info('三轮车任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data));
|
2023-08-22 14:32:57 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5]);
|
|
|
|
|
return true;
|
2023-08-21 16:32:56 +08:00
|
|
|
|
}
|
2023-08-28 09:31:13 +08:00
|
|
|
|
$name=$task['director_info']['nickname'];
|
|
|
|
|
$arr['status'] = 1;
|
2023-08-28 14:45:37 +08:00
|
|
|
|
$arr['money'] = $task['money'];
|
2023-08-29 17:13:44 +08:00
|
|
|
|
}elseif
|
|
|
|
|
//入股任务
|
|
|
|
|
($data['template_info']['type'] == 35){
|
2023-09-07 14:50:16 +08:00
|
|
|
|
$task_35 = Task::where('id', $data['task_id'])->field('director_uid,status,money,start_time,end_time')->with('director_info')->find();
|
2023-08-29 17:13:44 +08:00
|
|
|
|
if($task_35){
|
2023-08-29 23:05:08 +08:00
|
|
|
|
$day= $data['template_info']['stage_day_one'] + $data['template_info']['stage_day_two'];
|
2023-08-30 21:08:12 +08:00
|
|
|
|
if($task_35['status']==3 && $data['template_info']['day_count']<=$day){
|
2023-08-29 17:13:44 +08:00
|
|
|
|
$name = $task_35['director_info']['nickname'];
|
|
|
|
|
$arr['status'] = 1;
|
2023-08-30 21:08:12 +08:00
|
|
|
|
$arr['money'] = $task_35['money'];
|
2023-08-29 18:11:54 +08:00
|
|
|
|
$arr['company_account_type'] = 2;
|
2023-08-29 17:13:44 +08:00
|
|
|
|
}else{
|
2023-09-05 16:34:14 +08:00
|
|
|
|
if($data['template_info']['day_count']<=$day){
|
2023-09-09 09:46:59 +08:00
|
|
|
|
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 0]);
|
2023-09-08 20:27:52 +08:00
|
|
|
|
try{
|
|
|
|
|
Task::where('id', $data['task_id'])->update(['create_time' => $task_35['start_time']+86400,'update_time' =>time(),'start_time'=>$task_35['start_time']+86400,'end_time'=>$task_35['start_time']+86400+86399]);
|
|
|
|
|
}catch(\Exception $e){
|
|
|
|
|
$start_time = strtotime(date('Y-m-d'));
|
|
|
|
|
Task::where('id', $data['task_id'])->update(['create_time' => $start_time+86400,'update_time' =>time(),'start_time'=>$start_time+86400,'end_time'=> $start_time + 86400+86399]);
|
|
|
|
|
|
|
|
|
|
}
|
2023-09-07 14:50:16 +08:00
|
|
|
|
return false;
|
2023-08-29 23:05:08 +08:00
|
|
|
|
}
|
2023-09-01 10:40:01 +08:00
|
|
|
|
if($data['template_info']['day_count']>$day){
|
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' =>5]);
|
|
|
|
|
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为超时:' . json_encode($data));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-08-29 17:13:44 +08:00
|
|
|
|
}
|
2023-08-30 21:08:12 +08:00
|
|
|
|
}else{
|
|
|
|
|
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data));
|
|
|
|
|
return false;
|
2023-08-29 17:13:44 +08:00
|
|
|
|
}
|
2023-08-21 16:32:56 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
2023-08-21 15:14:39 +08:00
|
|
|
|
//其他类型任务
|
2023-08-28 14:45:37 +08:00
|
|
|
|
$task_count = Task::where('id', $data['task_id'])->field('director_uid,money')->where('status', 3)->with('director_info')->find();
|
2023-08-21 15:14:39 +08:00
|
|
|
|
if (empty($task_count)) {
|
2023-08-28 14:45:37 +08:00
|
|
|
|
Log::info('其他任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data));
|
2023-08-21 15:14:39 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5]);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$name = $task_count['director_info']['nickname'];
|
|
|
|
|
$arr['status'] = 1;
|
2023-08-28 14:45:37 +08:00
|
|
|
|
$arr['money'] = $task_count['money'];
|
2023-08-16 00:14:09 +08:00
|
|
|
|
}
|
2023-09-05 15:52:01 +08:00
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
Log::error('line:'.$e->getLine().'异常报错:任务结算失败:' . $data['template_info']['title'] . $e->getMessage() . json_encode($data));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if ($arr['status'] == 1) {
|
2023-08-15 13:46:31 +08:00
|
|
|
|
$arr['company_id'] = $data['scheduling']['company_id'];
|
2023-08-28 09:31:13 +08:00
|
|
|
|
$arr['msg'] = '来自任务【' . $data['template_info']['title'] . '】,完成方:' . $name . ',任务结算';
|
2023-08-29 23:05:08 +08:00
|
|
|
|
// $arr['proportion_one'] = $data['template_info']['proportion_one'];
|
|
|
|
|
// $arr['proportion_two'] = $data['template_info']['proportion_two'];
|
2023-08-15 13:46:31 +08:00
|
|
|
|
$arr['sn'] = $data['sn'];
|
|
|
|
|
$arr['id'] = $data['id'];
|
2023-08-30 13:50:50 +08:00
|
|
|
|
(new ShareProfit())->first($arr, $company,$data);
|
2023-08-21 15:14:39 +08:00
|
|
|
|
} else {
|
2023-09-05 15:52:01 +08:00
|
|
|
|
Task::where('id', $data['task_id'])->update(['status' => 5]);
|
2023-08-28 14:45:37 +08:00
|
|
|
|
Log::info('任务status=0结算失败:' . $data['template_info']['title'] . '未完成' . json_encode($data));
|
2023-08-18 16:32:41 +08:00
|
|
|
|
}
|
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
|
|
|
|
}
|