add 任务下发和任务结算线上事故紧急修复接口

This commit is contained in:
chenbo 2023-10-07 17:30:32 +08:00
parent 432b64fd72
commit 9c3bd3c890

View File

@ -2,28 +2,25 @@
namespace app\api\controller;
use app\common\logic\CompanyLogic;
use app\common\logic\finance\ShareProfit;
use app\common\logic\task\TaskLogic;
use app\common\model\Company;
use app\common\model\company\CompanyAccountLog;
use app\common\model\task\Task;
use app\common\model\task_scheduling\TaskScheduling;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate;
use app\common\model\user\User as UserModel;
use app\common\model\user\UserAccountLog;
use think\facade\Log;
use app\job\TaskAdd;
use app\job\TaskInformationJob;
use think\facade\Log;
use app\job\TaskTenZehn;
use app\api\controller\JunziqianController;
use think\facade\Db;
use app\common\model\ShopMerchant;
use app\common\model\contract\ShopContract;
class CeshiController extends BaseApiController
{
public array $notNeedLogin = ['index', 'ceshi', 'ceshi1', 'ceshi2', 'task_ceshi'];
public array $notNeedLogin = ['index', 'ceshi', 'ceshi1', 'ceshi2', 'service_group_task_add_test', 'service_group_task_settlement_test', 'town_task_add_ceshi', 'town_task_settlement_ceshi'];
public function index()
{ //1201
@ -149,12 +146,22 @@ class CeshiController extends BaseApiController
Company::where('id','in',$company_id)->inc('day_count')->update();
}
public function task_ceshi()
{
$time = strtotime(date('Y-m-d'));
// $tiem_end=$time+86399;
$plan_all = TaskScheduling::where('cron_time', '<', $time)->where('status', 1)->where('company_type', 18)->with('company_info')->select()->toArray();
/**
* 小组服务公司任务下发 线上事故调试和紧急修复预案接口
*/
public function service_group_task_add_test()
{
//任务下发
$time = strtotime(date('Y-m-d')); // 今天的000000
// 注意 cron_time
$plan_all = TaskScheduling::where('cron_time', '<', $time)
->where('status', 1)
->where('company_type', 18)
->with('company_info')
->select()
->toArray();
dd($plan_all);
$plan_ids = [];
foreach ($plan_all as $k => $v) {
$all = TaskTemplate::where('status', 1)->where('task_scheduling', $v['id'])->limit(30)->select()->toArray();
@ -168,12 +175,232 @@ class CeshiController extends BaseApiController
$company_id = [];
foreach ($plan_all as $k => $v) {
foreach ($v['template'] as $kk => $vv) {
queue(TaskAdd::class,['data'=>$vv,'data_two'=>$v]);
// queue(TaskAdd::class,['data'=>$vv,'data_two'=>$v]);
TaskLogic::CronAdd($vv, $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'));
return $this->success('定时任务下发执行成功');
}
/**
* 小组服务公司任务结算 线上事故调试和紧急修复预案接口
*/
public function service_group_task_settlement_test()
{
//
$all = TaskSchedulingPlan::whereDay('end_time','today')
->withJoin(['scheduling'], 'left')
->where('scheduling.company_type', 18)
->where('is_pay',0)
->with(['template_info'])
->select()
->toArray();
dd($all);
foreach($all as $k=>$data){
try {
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 1]);
$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(); // 可能要判断预存金是否满足
$arr['status'] = 0;
$arr['company_account_type'] = 1;
//信息更新
if ($data['template_info']['type'] == 31) {
if ($data['template_info']['information_count'] < $data['template_info']['information_day_count']) {
Log::info('信息更新任务,信息更新未达到要求:' . json_encode($data));
Task::where('id', $data['task_id'])->update(['status' => 5]);
TaskTemplate::where('id',$data['template_id'])->update(['information_count'=>$data['template_info']['information_day_count']]);
return false;
}
$name = '小组队长';
$arr['status'] = 1;
$task = Task::where('id', $data['task_id'])->field('director_uid,money')->where('status', 3)->find();
$arr['money'] = $task['money'];
Task::where('id', $data['task_id'])->update(['status' => 3]);
} elseif
//交易金额
($data['template_info']['type'] == 33) {
$shang_date_total_price = App(RemoteController::class)->shang_date_total_price($company,[],$data['template_id']);
if ($shang_date_total_price == false) {
Log::info('交易金额任务,交易金额未达到要求:' . json_encode($data));
Task::where('id', $data['task_id'])->update(['status' => 5]);
return false;
}
$transaction_pool=$data['template_info']['transaction_pool'];//交易金额剩余池
$count_money=bcadd($shang_date_total_price['arr']['total_price'],$transaction_pool,2);//交易金额加资金池金额
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;//变化前
$shang_date_total_price['arr']['after_count_transaction_pool']=$count_money;//变化后
$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]);
$shang_date_total_price['arr']['status']=1;
}else{
Log::info('交易金额任务,交易金额小于今日金额:' . json_encode($data));
Task::where('id', $data['task_id'])->update(['status' => 5]);
return false;
}
$name = $shang_date_total_price['name'];
$arr['status'] = $shang_date_total_price['arr']['status'];
$task = Task::where('id', $data['task_id'])->field('money')->find();
$arr['money'] = $task['money'];
} elseif
//三轮车
($data['template_info']['type'] == 32){
$task = Task::where('id', $data['task_id'])->field('director_uid,money')->where('status', 3)->with('director_info')->find();
if(empty($task)){
Log::info('三轮车任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data));
Task::where('id', $data['task_id'])->update(['status' => 5]);
return true;
}
$name=$task['director_info']['nickname'];
$arr['status'] = 1;
$arr['money'] = $task['money'];
}elseif
//入股任务
($data['template_info']['type'] == 35){
$task_35 = Task::where('id', $data['task_id'])->field('director_uid,status,money,start_time,end_time')->with('director_info')->find();
if($task_35){
$day= $data['template_info']['stage_day_one'] + $data['template_info']['stage_day_two'];
if($task_35['status']==3 && $data['template_info']['day_count']<=$day){
$name = $task_35['director_info']['nickname'];
$arr['status'] = 1;
$arr['money'] = $task_35['money'];
$arr['company_account_type'] = 2;
}else{
/**
* 判断入股任务 单次类型 是否超时
* 未超时时刷新开始结束时间
* 超时则关闭
*/
if($data['template_info']['day_count']<=$day){
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 0]);
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]);
}
return false;
}
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;
}
}
}else{
Log::info('入股任务 ' . $data['template_info']['title'] . '结算失败,任务为空:' . json_encode($data));
return false;
}
}
else {
//其他类型任务
$task = Task::where('id', $data['task_id'])->with('director_info')->find();
if ($task['status'] == 3) {
$name = $task['director_info']['nickname'];
$arr['status'] = 1;
$arr['money'] = $task['money'];
} else if ($task['status'] == 2) {
// 是否超时
$day= $data['template_info']['stage_day_one'] + $data['template_info']['stage_day_two'];
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;
}
if($data['template_info']['day_count'] < $day){
TaskSchedulingPlan::where('id', $data['id'])->update(['is_pay' => 0]);
try{
Task::where('id', $data['task_id'])->update(['create_time' => $task['start_time']+86400,'update_time' =>time(),'start_time'=>$task['start_time']+86400,'end_time'=>$task['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]);
}
return false;
}
}
}
} catch (\Exception $e) {
Log::error('line:'.$e->getLine().'异常报错:任务结算失败:' . $data['template_info']['title'] . $e->getMessage() . json_encode($data));
return false;
}
if ($arr['status'] == 1) {
$arr['company_id'] = $data['scheduling']['company_id'];
$arr['msg'] = '来自任务【' . $data['template_info']['title'] . '】,完成方:' . $name . ',任务结算';
// $arr['proportion_one'] = $data['template_info']['proportion_one'];
// $arr['proportion_two'] = $data['template_info']['proportion_two'];
$arr['sn'] = $data['sn'];
$arr['id'] = $data['id'];
(new ShareProfit())->first($arr, $company,$data);
} else {
Task::where('id', $data['task_id'])->update(['status' => 5]);
Log::info('任务status=0结算失败' . $data['template_info']['title'] . '未完成' . json_encode($data));
}
// queue(TaskInformationJob::class,$v);
}
Log::info('小组服务公司定时任务结算执行成功'.date('Y-m-d H:i:s'));
return $this->success('小组服务公司定时任务结算执行成功');
}
/**
* 镇农科公司任务下发 线上事故调试和紧急修复预案接口
*/
public function town_task_add_ceshi()
{
//任务下发
$time = strtotime(date('Y-m-d'));
// 查询系统 所有镇农科公司 未下发 的 任务安排
$taskSchedulingList = TaskScheduling::where('cron_time', '<', $time)->where('status', 1)->where('company_type', 41)->with('company_info')->select()->toArray();
dd($taskSchedulingList);
$taskSchedulingIds = [];
$companyIds = [];
foreach ($taskSchedulingList as $k => $taskScheduling) {
$templateList = TaskTemplate::where('status', 1)->where('task_scheduling', $taskScheduling['id'])->limit(30)->select()->toArray();
$taskSchedulingIds[] = $taskScheduling['id'];
$companyIds[] = $taskScheduling['company_id'];
foreach ($templateList as $template) {
// queue(TownTaskAdd::class, $template);
TaskLogic::TownCronAdd($template); // 手动下发用
}
if (empty($templateList)) {
unset($taskSchedulingList[$k]);
}
}
Company::where('id', 'in', $companyIds)->inc('day_count')->update();
TaskScheduling::where('id', 'in', $taskSchedulingIds)->update(['cron_time' => time()]);
Log::info('定时任务下发执行成功' . date('Y-m-d H:i:s'));
}
/**
* 镇农科公司任务结算 线上事故调试和紧急修复预案接口
*/
public function town_task_settlement_ceshi()
{
// 今日未结算的任务计划
$taskSchedulingPlanList = TaskSchedulingPlan::whereDay('end_time','today')
->withJoin(['scheduling'], 'left')
->where('scheduling.company_type', 41)
->where('is_pay',0)
->with(['template_info'])
->select()
->toArray();
dd($taskSchedulingPlanList);
foreach($taskSchedulingPlanList as $taskSchedulingPlan) {
if (in_array($taskSchedulingPlan['template_info']['type'], [44,45,46,47,48,49,50])) {
continue;
}
TaskLogic::townTaskSettlement($taskSchedulingPlan);
}
}
}