This commit is contained in:
yaooo 2023-10-11 09:53:52 +08:00
commit 49e0be2e73

View File

@ -310,10 +310,45 @@ class TaskLogic extends BaseLogic
return true; return true;
} }
} }
$time = strtotime(date('Y-m-d'));
// 任务类型code
$taskType = (new DictData())->getTownTaskType($taskTemplate['type']);
Db::startTrans(); Db::startTrans();
$time = strtotime(date('Y-m-d'));
$directorUid = 0; // 指派给
if ($taskTemplate['extend']['task_role'] == 2) {
$marketingManagerUser = User::where(['company_id'=>$taskTemplate['company_id'], 'group_id'=> 16])->find();
Log::info(['镇农科公司定时任务下发-市场部长user信息', $marketingManagerUser]);
$directorUid = $marketingManagerUser['id'];
}
if ($taskTemplate['extend']['task_role'] == 3) {
$serviceManagerUser = User::where(['company_id'=>$taskTemplate['company_id'], 'group_id'=> 14])->find();
Log::info(['镇农科公司定时任务下发-服务部长user信息', $serviceManagerUser]);
$directorUid = $serviceManagerUser['id'];
}
// 添加任务计划
$TaskSchedulingPlan = self::addTaskSchedulePlan($taskTemplate, $time);
Log::info(['镇农科公司定时任务下发-添加plan结果', $TaskSchedulingPlan]);
// 添加任务
$task_id = self::addTask($taskTemplate, $TaskSchedulingPlan, $time, $directorUid);
Log::info(['镇农科公司定时任务下发-添加task结果', $task_id]);
// 关联任务计划和任务
TaskSchedulingPlan::where('id', $TaskSchedulingPlan['id'])->update(['task_id' => $task_id, 'is_execute' => 1]);
// 任务累计进行天数 +1
TaskTemplate::where('id', $taskTemplate['id'])->inc('day_count')->update();
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::error('定时任务添加失败'.$e->getMessage().'。line'.$e->getLine());
}
}
private static function addTaskSchedulePlan($taskTemplate, $time)
{
$TaskSchedulingPlan_data = [ $TaskSchedulingPlan_data = [
'create_user_id' => 0, 'create_user_id' => 0,
'company_id' => $taskTemplate['company_id'], 'company_id' => $taskTemplate['company_id'],
@ -325,10 +360,12 @@ class TaskLogic extends BaseLogic
'status' => 1 'status' => 1
]; ];
$TaskSchedulingPlan = TaskSchedulingPlan::create($TaskSchedulingPlan_data); $TaskSchedulingPlan = TaskSchedulingPlan::create($TaskSchedulingPlan_data);
Log::info(['镇农科公司定时任务下发-添加plan结果', $TaskSchedulingPlan]);
$serviceManagerUser = User::where(['company_id'=>$taskTemplate['company_id'], 'group_id'=> 14])->find(); return $TaskSchedulingPlan;
Log::info(['镇农科公司定时任务下发-服务部长user信息', $serviceManagerUser]); }
private static function addTask($taskTemplate, $TaskSchedulingPlan, $time, $directorUid)
{
$arr = [ $arr = [
'template_id' => $taskTemplate['id'], 'template_id' => $taskTemplate['id'],
'scheduling_plan_id' => $TaskSchedulingPlan['id'], 'scheduling_plan_id' => $TaskSchedulingPlan['id'],
@ -339,77 +376,125 @@ class TaskLogic extends BaseLogic
'content' => $taskTemplate['content'], 'content' => $taskTemplate['content'],
'start_time' => $time, 'start_time' => $time,
'end_time' => $time + 86399, 'end_time' => $time + 86399,
'director_uid' => $serviceManagerUser['id'], // 默认都指派给服务部长 'director_uid' => $directorUid, // 指派给
'create_time' => time(), 'create_time' => time(),
'update_time' => time(), 'update_time' => time(),
]; ];
$data = $arr; $data = $arr;
// 不同角色,计算任务金额有差异
if($taskTemplate['extend']['task_role'] == 2) {
$data['money'] = self::countTownTaskMarketingMoney($taskTemplate);
}
if($taskTemplate['extend']['task_role'] == 3) {
$data['money'] = self::countTownTaskMoney($taskTemplate); $data['money'] = self::countTownTaskMoney($taskTemplate);
}
$extend = []; $extend = [];
// 任务类型code
$taskType = (new DictData())->getTownTaskType($taskTemplate['type']);
// 督促小组服务团队学习任务 扩展信息 // 督促小组服务团队学习任务 扩展信息
if ($taskType == 'town_task_type_4') { if ($taskType == 'town_task_type_4') {
$extend = ['town_task_type_4' => ['study_photo'=>[], 'sign_in_table'=>'', 'study_content'=> '']]; $extend = ['town_task_type_4' => ['study_photo'=>[], 'sign_in_table'=>'', 'study_content'=> '']];
} }
$data['extend'] = json_encode($extend); $data['extend'] = json_encode($extend);
$task_id = (new Task())->insertGetId($data); $task_id = (new Task())->insertGetId($data);
Log::info(['镇农科公司定时任务下发-添加task结果', $task_id]); return $task_id;
TaskSchedulingPlan::where('id', $TaskSchedulingPlan['id'])->update(['task_id' => $task_id, 'is_execute' => 1]);
// 任务累计进行天数 +1
TaskTemplate::where('id', $taskTemplate['id'])->inc('day_count')->update();
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::error('定时任务添加失败'.$e->getMessage().'。line'.$e->getLine());
}
} }
private static function countTownTaskMoney($tempalte) private static function countTownTaskMoney($template)
{ {
$v_day_count = $tempalte['day_count']; $v_day_count = $template['day_count'];
$v_day_count = $v_day_count + 1; $v_day_count = $v_day_count + 1;
$stageDayOneAccumulative = $tempalte['stage_day_one']; // 第一阶段天数 $stageDayOneAccumulative = $template['stage_day_one']; // 第一阶段天数
$stageDayTwoAccumulative = bcadd($tempalte['stage_day_one'], $tempalte['stage_day_two']); // 第二阶段天数 第一+第二 $stageDayTwoAccumulative = bcadd($template['stage_day_one'], $template['stage_day_two']); // 第二阶段天数 第一+第二
$stageDayThreeAccumulative = bcadd($stageDayTwoAccumulative, $tempalte['stage_day_three']); // 第二阶段天数 第二阶段累计值+第三 $stageDayThreeAccumulative = bcadd($stageDayTwoAccumulative, $template['stage_day_three']); // 第二阶段天数 第二阶段累计值+第三
// 单次和循环任务 // 单次和循环任务
if ($tempalte['types'] == 1 || $tempalte['types'] == 3) { if ($template['types'] == 1 || $template['types'] == 3) {
if ($v_day_count <= $stageDayOneAccumulative) { if ($v_day_count <= $stageDayOneAccumulative) {
// 第一阶段金额 // 第一阶段金额
return $tempalte['money']; return $template['money'];
} else if ($stageDayOneAccumulative < $v_day_count && $v_day_count<= $stageDayTwoAccumulative) { } else if ($stageDayOneAccumulative < $v_day_count && $v_day_count<= $stageDayTwoAccumulative) {
// 第二阶段金额 // 第二阶段金额
return $tempalte['money_two']; return $template['money_two'];
} else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <= $stageDayThreeAccumulative) { } else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <= $stageDayThreeAccumulative) {
// 第三阶段金额 // 第三阶段金额
return $tempalte['new_money_three']; return $template['new_money_three'];
} }
} elseif ($tempalte['types'] == 2) { } elseif ($template['types'] == 2) {
// 长期任务 // 长期任务
// 督促完成需求收集和交易任务 第二个阶段即长期 // 督促完成需求收集和交易任务 第二个阶段即长期
$townTaskTypeList = DictData::where(['type_value' => 'town_task_type', 'status' => 1])->column('value', 'id'); $townTaskTypeList = DictData::where(['type_value' => 'town_task_type', 'status' => 1])->column('value', 'id');
if ($townTaskTypeList[$tempalte['type']]=== 'town_task_type_5') { if (isset($townTaskTypeList[$template['type']]) && $townTaskTypeList[$template['type']]=== 'town_task_type_5') {
if ($v_day_count<= $stageDayOneAccumulative) { if ($v_day_count<= $stageDayOneAccumulative) {
// 第一阶段金额 // 第一阶段金额
return $tempalte['money']; return $template['money'];
} elseif ( $v_day_count > $stageDayOneAccumulative) { } elseif ( $v_day_count > $stageDayOneAccumulative) {
// 长期金额 // 长期金额
return $tempalte['money_three']; return $template['money_three'];
} }
} }
if ($v_day_count<= $stageDayOneAccumulative) { if ($v_day_count<= $stageDayOneAccumulative) {
// 第一阶段金额 // 第一阶段金额
return $tempalte['money']; return $template['money'];
} elseif ( $stageDayOneAccumulative < $v_day_count && $v_day_count <= $stageDayTwoAccumulative) { } elseif ( $stageDayOneAccumulative < $v_day_count && $v_day_count <= $stageDayTwoAccumulative) {
// 第二阶段金额 // 第二阶段金额
return $tempalte['money_two']; return $template['money_two'];
} else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <=$stageDayThreeAccumulative) { } else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <=$stageDayThreeAccumulative) {
// 第三阶段金额 // 第三阶段金额
return $tempalte['new_money_three']; return $template['new_money_three'];
} else { } else {
// 长期金额 // 长期金额
return $tempalte['money_three']; return $template['money_three'];
}
}
}
private static function countTownTaskMarketingMoney($template)
{
$v_day_count = $template['day_count'];
$v_day_count = $v_day_count + 1;
$stageDayOneAccumulative = $template['stage_day_one']; // 第一阶段天数
$stageDayTwoAccumulative = bcadd($template['stage_day_one'], $template['stage_day_two']); // 第二阶段天数 第一+第二
$stageDayThreeAccumulative = bcadd($stageDayTwoAccumulative, $template['stage_day_three']); // 第二阶段天数 第二阶段累计值+第三
// 单次和循环任务
if ($template['types'] == 1 || $template['types'] == 3) {
if ($v_day_count <= $stageDayOneAccumulative) {
// 第一阶段金额
return $template['money'];
} else if ($stageDayOneAccumulative < $v_day_count && $v_day_count<= $stageDayTwoAccumulative) {
// 第二阶段金额
return $template['money_two'];
} else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <= $stageDayThreeAccumulative) {
// 第三阶段金额
return $template['new_money_three'];
}
} elseif ($template['types'] == 2) {
// 长期任务
// 市场部长协助总负责人开展日常工作 第一个阶段即长期
$townTaskTypeList = DictData::where(['type_value' => 'town_task_type_marketing_director', 'status' => 1])->column('value', 'id');
if (isset($townTaskTypeList[$template['type']]) && $townTaskTypeList[$template['type']]=== 'town_task_type_marketing_director_1') {
return $template['money_three'];
}
if ($v_day_count<= $stageDayOneAccumulative) {
// 第一阶段金额
return $template['money'];
} elseif ( $stageDayOneAccumulative < $v_day_count && $v_day_count <= $stageDayTwoAccumulative) {
// 第二阶段金额
return $template['money_two'];
} else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <=$stageDayThreeAccumulative) {
// 第三阶段金额
return $template['new_money_three'];
} else {
// 长期金额
return $template['money_three'];
} }
} }
} }