diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index 5d78eefc2..2af85a176 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -310,52 +310,36 @@ class TaskLogic extends BaseLogic return true; } } - $time = strtotime(date('Y-m-d')); - // 任务类型code - $taskType = (new DictData())->getTownTaskType($taskTemplate['type']); Db::startTrans(); - $TaskSchedulingPlan_data = [ - 'create_user_id' => 0, - 'company_id' => $taskTemplate['company_id'], - 'template_id' => $taskTemplate['id'], - 'scheduling_id' => $taskTemplate['task_scheduling'], - 'start_time' => $time, - 'end_time' => $time + 86399, - 'sn' => User::createUserSn(), - 'status' => 1 - ]; - $TaskSchedulingPlan = TaskSchedulingPlan::create($TaskSchedulingPlan_data); + + $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]); - $serviceManagerUser = User::where(['company_id'=>$taskTemplate['company_id'], 'group_id'=> 14])->find(); - Log::info(['镇农科公司定时任务下发-服务部长user信息', $serviceManagerUser]); - $arr = [ - 'template_id' => $taskTemplate['id'], - 'scheduling_plan_id' => $TaskSchedulingPlan['id'], - 'company_id' => $taskTemplate['company_id'], - 'title' => $taskTemplate['title'], - 'money' => $taskTemplate['money'], - 'type' => $taskTemplate['type'], - 'content' => $taskTemplate['content'], - 'start_time' => $time, - 'end_time' => $time + 86399, - 'director_uid' => $serviceManagerUser['id'], // 默认都指派给服务部长 - 'create_time' => time(), - 'update_time' => time(), - ]; - $data = $arr; - $data['money'] = self::countTownTaskMoney($taskTemplate); - $extend = []; - // 督促小组服务团队学习任务 扩展信息 - if ($taskType == 'town_task_type_4') { - $extend = ['town_task_type_4' => ['study_photo'=>[], 'sign_in_table'=>'', 'study_content'=> '']]; - } - $data['extend'] = json_encode($extend); - $task_id = (new Task())->insertGetId($data); + // 添加任务 + $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(); @@ -363,53 +347,154 @@ class TaskLogic extends BaseLogic } } - private static function countTownTaskMoney($tempalte) + private static function addTaskSchedulePlan($taskTemplate, $time) { - $v_day_count = $tempalte['day_count']; + $TaskSchedulingPlan_data = [ + 'create_user_id' => 0, + 'company_id' => $taskTemplate['company_id'], + 'template_id' => $taskTemplate['id'], + 'scheduling_id' => $taskTemplate['task_scheduling'], + 'start_time' => $time, + 'end_time' => $time + 86399, + 'sn' => User::createUserSn(), + 'status' => 1 + ]; + $TaskSchedulingPlan = TaskSchedulingPlan::create($TaskSchedulingPlan_data); + + return $TaskSchedulingPlan; + } + + private static function addTask($taskTemplate, $TaskSchedulingPlan, $time, $directorUid) + { + $arr = [ + 'template_id' => $taskTemplate['id'], + 'scheduling_plan_id' => $TaskSchedulingPlan['id'], + 'company_id' => $taskTemplate['company_id'], + 'title' => $taskTemplate['title'], + 'money' => $taskTemplate['money'], + 'type' => $taskTemplate['type'], + 'content' => $taskTemplate['content'], + 'start_time' => $time, + 'end_time' => $time + 86399, + 'director_uid' => $directorUid, // 指派给 + 'create_time' => time(), + 'update_time' => time(), + ]; + $data = $arr; + + // 不同角色,计算任务金额有差异 + if($taskTemplate['extend']['task_role'] == 2) { + $data['money'] = self::countTownTaskMarketingMoney($taskTemplate); + } + if($taskTemplate['extend']['task_role'] == 3) { + $data['money'] = self::countTownTaskMoney($taskTemplate); + } + + + $extend = []; + // 任务类型code + $taskType = (new DictData())->getTownTaskType($taskTemplate['type']); + // 督促小组服务团队学习任务 扩展信息 + if ($taskType == 'town_task_type_4') { + $extend = ['town_task_type_4' => ['study_photo'=>[], 'sign_in_table'=>'', 'study_content'=> '']]; + } + $data['extend'] = json_encode($extend); + $task_id = (new Task())->insertGetId($data); + return $task_id; + } + + private static function countTownTaskMoney($template) + { + $v_day_count = $template['day_count']; $v_day_count = $v_day_count + 1; - $stageDayOneAccumulative = $tempalte['stage_day_one']; // 第一阶段天数 - $stageDayTwoAccumulative = bcadd($tempalte['stage_day_one'], $tempalte['stage_day_two']); // 第二阶段天数 第一+第二 - $stageDayThreeAccumulative = bcadd($stageDayTwoAccumulative, $tempalte['stage_day_three']); // 第二阶段天数 第二阶段累计值+第三 + $stageDayOneAccumulative = $template['stage_day_one']; // 第一阶段天数 + $stageDayTwoAccumulative = bcadd($template['stage_day_one'], $template['stage_day_two']); // 第二阶段天数 第一+第二 + $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) { // 第一阶段金额 - return $tempalte['money']; + return $template['money']; } 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) { // 第三阶段金额 - 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'); - 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) { // 第一阶段金额 - return $tempalte['money']; + return $template['money']; } elseif ( $v_day_count > $stageDayOneAccumulative) { // 长期金额 - return $tempalte['money_three']; + return $template['money_three']; } } if ($v_day_count<= $stageDayOneAccumulative) { // 第一阶段金额 - return $tempalte['money']; + return $template['money']; } 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) { // 第三阶段金额 - return $tempalte['new_money_three']; + return $template['new_money_three']; } 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']; } } }