diff --git a/app/common/logic/finance/TownShareProfit.php b/app/common/logic/finance/TownShareProfit.php index 9ed1c6b8f..934a92a8a 100644 --- a/app/common/logic/finance/TownShareProfit.php +++ b/app/common/logic/finance/TownShareProfit.php @@ -7,6 +7,7 @@ use app\common\logic\AccountLogLogic; use app\common\model\Company; use app\common\model\company\CompanyAccountLog; use app\common\model\task\Task; +use app\common\model\task_scheduling_plan\TaskSchedulingPlan; use app\common\model\user\UserAccountLog; use app\common\model\user\User; use think\facade\Db; @@ -14,77 +15,28 @@ use think\facade\Log; class TownShareProfit { - public function townTaskType1($taskInfo, $company, $taskSchedulePlan) + public function townTaskType1($taskInfo, $townCompany, $taskSchedulePlan) { try { Db::startTrans(); - - $proportion = 0; - //总金额除以2等于不可提现账号金额和收益 - $masterMoney = bcdiv($taskInfo['money'], 2, 2); - - $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,'; - //服务部长收益 任务金额的50%为服务部长的收益 - $serviceManagerUser = User::where(['company_id' => $company['id'], 'group_id' => 14])->find(); - Log::info([$taskSchedulePlan['template_info']['title'].'结算-服务部长用户信息', $serviceManagerUser]); - // 用户收益变动 - $arr = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark.'任务结算获得收益' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; - $this->master($arr); - // 用户余额变动 - $arr_two = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark . '获得账户余额' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; - $this->Account($arr_two); - - // 公司 - $deposit_count = bcadd($company['deposit'], $masterMoney, 2); - // 公司收益变动记录 - $this->AccountLog($company['id'], $deposit_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_DEPOSIT); - $company_money_count = bcadd($company['company_money'], $masterMoney, 2); - //公司余额变动记录 - $this->AccountLog($company['id'], $company_money_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_COMPANY_MONEY); - // 变更公司收益和余额 - Company::where('id', $company['id'])->update(['deposit' => Db::raw('deposit+' . $masterMoney), 'company_money' => Db::raw('company_money+' . $masterMoney)]); - + $this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan); // 更改任务状态 Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); - Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); - Log::error('54-任务结算失败:' . $e->getMessage()); + Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage()); return false; } } - public function townTaskType2($taskInfo, $company, $taskSchedulePlan, $step, $contractCount) + public function townTaskType2($taskInfo, $townCompany, $taskSchedulePlan, $step, $contractCount) { try { Db::startTrans(); - $proportion = 0; - //总金额除以2等于不可提现账号金额和收益 - $masterMoney = bcdiv($taskInfo['money'], 2, 2); - - $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,'; - //服务部长收益 任务金额的50%为服务部长的收益 - $serviceManagerUser = User::where(['company_id' => $company['id'], 'group_id' => 14])->find(); - Log::info([$taskSchedulePlan['template_info']['title'].'结算-服务部长用户信息', $serviceManagerUser]); - // 用户收益变动 - $arr = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark.'任务结算获得收益' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; - $this->master($arr); - // 用户余额变动 - $arr_two = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark . '获得账户余额' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; - $this->Account($arr_two); - - // 公司 - $deposit_count = bcadd($company['deposit'], $masterMoney, 2); - // 公司收益变动记录 - $this->AccountLog($company['id'], $deposit_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_DEPOSIT); - $company_money_count = bcadd($company['company_money'], $masterMoney, 2); - //公司余额变动记录 - $this->AccountLog($company['id'], $company_money_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_COMPANY_MONEY); - // 变更公司收益和余额 - Company::where('id', $company['id'])->update(['deposit' => Db::raw('deposit+' . $masterMoney), 'company_money' => Db::raw('company_money+' . $masterMoney)]); + $this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan); if ($step == 2 && $contractCount >= 15) { // 更改任务状态 @@ -95,11 +47,74 @@ class TownShareProfit return true; } catch (\Exception $e) { Db::rollback(); - Log::error('54-任务结算失败:' . $e->getMessage()); + Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage()); return false; } } + public function townTaskType3($taskInfo, $townCompany, $taskSchedulePlan) + { + try { + Db::startTrans(); + $this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan); + // 更改任务状态 + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage()); + return false; + } + } + public function townTaskType4($taskInfo, $townCompany, $taskSchedulePlan) + { + try { + Db::startTrans(); + $this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan); + // 更改结算状态 + (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); + // 更改任务状态 + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage()); + return false; + } + } + /** + * 分润 + */ + public function shareProfit($taskInfo, $company, $taskSchedulePlan) + { + $proportion = 0; + //总金额除以2等于不可提现账号金额和收益 + $masterMoney = bcdiv($taskInfo['money'], 2, 2); + + $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,'; + //服务部长收益 任务金额的50%为服务部长的收益 + $serviceManagerUser = User::where(['company_id' => $company['id'], 'group_id' => 14])->find(); + Log::info([$taskSchedulePlan['template_info']['title'].'结算-服务部长用户信息', $serviceManagerUser]); + // 用户收益变动 + $arr = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark.'任务结算获得收益' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + $this->master($arr); + // 用户余额变动 + $arr_two = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark . '获得账户余额' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + $this->Account($arr_two); + + // 公司收益 + $deposit_count = bcadd($company['deposit'], $masterMoney, 2); + // 公司收益变动记录 + $this->AccountLog($company['id'], $deposit_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_DEPOSIT); + $company_money_count = bcadd($company['company_money'], $masterMoney, 2); + //公司余额变动记录 + $this->AccountLog($company['id'], $company_money_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_COMPANY_MONEY); + // 变更公司收益和余额 + Company::where('id', $company['id'])->update(['deposit' => Db::raw('deposit+' . $masterMoney), 'company_money' => Db::raw('company_money+' . $masterMoney)]); + } + public function AccountLog($companyId, $left_amount, $changeAmount, $change_object = 1, $change_type = 1, $action = 1) { $company_log = [ diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index cebb44b3c..8c3a3643b 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -206,16 +206,18 @@ class TaskLogic extends BaseLogic { $v_day_count=$v['day_count']; $v_day_count=$v_day_count+1; + $stageDayOneAccumulative = $v['stage_day_one']; // 第一阶段天数 + $stageDayTwoAccumulative = bcadd($v['stage_day_one'], $v['stage_day_two']); // 第二阶段天数 第一+第二 if ($v['types'] == 1 || $v['types'] == 3) { - if ($v_day_count <= $v['stage_day_one']) { + if ($v_day_count <= $stageDayOneAccumulative) { return $v['money']; } else { return $v['money_two']; } } elseif ($v['types'] == 2) { - if ($v_day_count<= $v['stage_day_one']) { + if ($v_day_count<= $stageDayOneAccumulative) { return $v['money']; - } elseif ($v_day_count <= $v['stage_day_two']) { + } elseif ($stageDayOneAccumulative < $v_day_count && $v_day_count <= $stageDayTwoAccumulative) { return $v['money_two']; } else { return $v['money_three']; @@ -304,7 +306,8 @@ class TaskLogic extends BaseLogic } } $time = strtotime(date('Y-m-d')); - + // 任务类型code + $taskType = (new DictData())->getTownTaskType($taskTemplate['type']); $TaskSchedulingPlan_data = [ 'create_user_id' => 0, 'company_id' => $taskTemplate['company_id'], @@ -336,10 +339,16 @@ class TaskLogic extends BaseLogic ]; $data = $arr; $data['money'] = self::countTownTaskMoney($taskTemplate); - $data['extend'] = json_encode($taskTemplate['extend']); + $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); 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(); } catch (\Exception $e) { Log::error('定时任务添加失败'.$e->getMessage().'。line:'.$e->getLine()); @@ -350,26 +359,30 @@ class TaskLogic extends BaseLogic { $v_day_count = $tempalte['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']); // 第二阶段天数 第二阶段累计值+第三 + // 单次和循环任务 if ($tempalte['types'] == 1 || $tempalte['types'] == 3) { - if ($v_day_count <= $tempalte['stage_day_one']) { + if ($v_day_count <= $stageDayOneAccumulative) { // 第一阶段金额 return $tempalte['money']; - } else if ($v_day_count <= $tempalte['stage_day_two']) { + } else if ($stageDayOneAccumulative < $v_day_count && $v_day_count<= $stageDayTwoAccumulative) { // 第二阶段金额 return $tempalte['money_two']; - } else if ($v_day_count <= $tempalte['stage_day_three']) { + } else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <= $stageDayThreeAccumulative) { // 第三阶段金额 return $tempalte['new_money_three']; } } elseif ($tempalte['types'] == 2) { // 长期任务 - if ($v_day_count<= $tempalte['stage_day_one']) { + if ($v_day_count<= $stageDayOneAccumulative) { // 第一阶段金额 return $tempalte['money']; - } elseif ($v_day_count <= $tempalte['stage_day_two']) { + } elseif ( $stageDayOneAccumulative < $v_day_count && $v_day_count <= $stageDayTwoAccumulative) { // 第二阶段金额 return $tempalte['money_two']; - } else if ($v_day_count <= $tempalte['stage_day_three']) { + } else if ( $stageDayTwoAccumulative < $v_day_count && $v_day_count <=$stageDayThreeAccumulative) { // 第三阶段金额 return $tempalte['new_money_three']; } else { @@ -470,7 +483,7 @@ class TaskLogic extends BaseLogic (new TownShareProfit())->townTaskType1($taskInfo, $townCompany, $taskSchedulePlan); } else { // 关闭任务 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 5]); + (new Task())->closeTask($taskSchedulePlan['task_id']); Log::info('协助总负责人开展工作任务,结算失败:' . $taskTemplateInfo['title'] . '未完成。任务:' . json_encode($taskInfo)); } } @@ -503,33 +516,33 @@ class TaskLogic extends BaseLogic self::flushTaskTime($taskSchedulePlan); return false; } - $totolMoney = bcmul($taskTemplateInfo['stage_day_one'], $taskTemplateInfo['money_one'], 2); + $totalMoney = bcmul($taskTemplateInfo['stage_day_one'], $taskTemplateInfo['money'], 2); $taskMoney = 0; switch ($contractCount) { case 9: - $taskMoney = bcmul($totolMoney, 0.4, 2); + $taskMoney = bcmul($totalMoney, 0.4, 2); break; case 10: - $taskMoney = bcmul($totolMoney, 0.4, 2); + $taskMoney = bcmul($totalMoney, 0.4, 2); break; case 11: - $taskMoney = bcmul($totolMoney, 0.5, 2); + $taskMoney = bcmul($totalMoney, 0.5, 2); break; case 12: - $taskMoney = bcmul($totolMoney, 0.6, 2); + $taskMoney = bcmul($totalMoney, 0.6, 2); break; case 13: - $taskMoney = bcmul($totolMoney, 0.6, 2); + $taskMoney = bcmul($totalMoney, 0.6, 2); break; case 14: - $taskMoney = bcmul($totolMoney, 0.7, 2); + $taskMoney = bcmul($totalMoney, 0.7, 2); break; case 15: - $taskMoney = bcmul($totolMoney, 1, 2); + $taskMoney = bcmul($totalMoney, 1, 2); break; } if ($contractCount > 15) { - $taskMoney = bcmul($totolMoney, 1, 2); + $taskMoney = bcmul($totalMoney, 1, 2); } $task['money'] = $taskMoney; // 任务金额 (new TownShareProfit())->townTaskType2($task, $townCompany, $taskSchedulePlan, 1, $contractCount); @@ -547,7 +560,7 @@ class TaskLogic extends BaseLogic // 第二阶段未完成 if ($contractCount < 15) { // 关闭任务,并且没有奖励 - Task::where('id', $taskSchedulePlan['task_id'])->update(['status' => 5]); + (new Task())->closeTask($taskSchedulePlan['task_id']); return false; } @@ -584,13 +597,141 @@ class TaskLogic extends BaseLogic private static function dealTownTask3($taskSchedulePlan) { $taskTemplateInfo = $taskSchedulePlan['template_info']; - $taskScheduleInfo = $taskSchedulePlan['scheduling']; + $townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find(); + $groupServiceCompanyList = Company::where(['street' => $townCompany['street'], 'company_type' => 18])->select()->toArray(); + $task = Task::where('id', $taskSchedulePlan['task_id'])->with('director_info')->find(); + // 完成任务情况 + list($groupServiceCompanyCount, $doneTaskGroupServiceCompanyCount) = self::taskType3DoneInfo($groupServiceCompanyList); + $doneRate = bcdiv($doneTaskGroupServiceCompanyCount, $groupServiceCompanyCount,2); + // <80% 未完成任务 关闭本次任务 + if (bccomp($doneRate, 0.8, 2) == -1) { + (new Task())->closeTask($taskSchedulePlan['task_id']); + return true; + } else { + // 结算 分润 + (new TownShareProfit())->townTaskType3($task, $townCompany, $taskSchedulePlan); + } } + public static function taskType3DoneInfo($groupServiceCompanyList) + { + $groupServiceCompanyCount = count($groupServiceCompanyList); // 团队总数 + $doneTaskGroupServiceCompanyCount = 0; // 完成任务团队总数 + // 判定完成条件 组建成功的小组服务团队 每日完成档案更新任务和三轮车任务 的团队数量 >= 80% 小于80%则视为未完成 + foreach ($groupServiceCompanyList as $groupServiceCompany) { + // 档案更新任务 + $taskType31 = Task::where(['company_id' => $groupServiceCompany['id'], 'type' => 31, 'status' => 3])->find(); + // 三轮车任务 + $taskType32 = Task::where(['company_id' => $groupServiceCompany['id'], 'type' => 32, 'status' => 3])->find(); + if (!empty($taskType31) && !empty($taskType32)) { + $doneTaskGroupServiceCompanyCount++; + } + } + return [$groupServiceCompanyCount, $doneTaskGroupServiceCompanyCount]; + } + + /** + * 督促小组服务团队学习任务 长期任务 前置操作:每天要从APP端提交资料上来,根据提交资料来判定当天任务有没有完成 + * 任务完成条件:(学习照片5张,签到表一份,培训内容大纲 >= 50个字),每月提交>=4次 + * 1 当前任务进行天数 < 第一阶段天数 只判断当天是否完成 状态未完成则关闭任务 + * 2 当前任务进行天数 = 第一阶段天数 做第一阶段结算 且更改 task_schedule_plan 状态为已结算,后续将会根据这个时间来统计、判断各阶段的周期内是否达成完成条件(*) + * 3 第一阶段天数 < 当前任务进行天数 < (第一 + 第二) 只判断当天是否完成 状态未完成则关闭任务 + * 4 当前任务进行天数 = (第一阶段+第二阶段)天数 第二阶段结算 且更改 task_schedule_plan 状态为已结算 + * 5 第一阶段+第二阶段 < 当前任务进行天数 < (第一 + 第二 + 第三阶段天数) 只判断当天是否完成 状态未完成则关闭任务 + * 6 当前任务进行天数 = (第一 + 第二 + 第三阶段天数) 第三阶段结算 且更改 task_schedule_plan 状态为已结算 + * 7 当前任务进行天数 > (第一 + 第二 + 第三阶段天数) 但 当前任务进行天数/30 != 0 只判断当天是否完成 状态未完成则关闭任务 + * 8 当前任务进行天数/30 = 0, 长期阶段结算 且更改 task_schedule_plan 状态为已结算 + */ private static function dealTownTask4($taskSchedulePlan) { $taskTemplateInfo = $taskSchedulePlan['template_info']; - $taskScheduleInfo = $taskSchedulePlan['scheduling']; + $townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find(); + $taskDayCount = $taskTemplateInfo['day_count']; // 任务累计进行天数 + $task = Task::where(['id', $taskSchedulePlan['task_id']])->find(); + $stageDayOneAccumulative = $taskTemplateInfo['stage_day_one']; // 第一阶段累计天数 + $stageDayTwoAccumulative = bcadd($taskTemplateInfo['stage_day_one'], $taskTemplateInfo['stage_day_two']); // 第二阶段累计天数 第一+第二 + $stageDayThreeAccumulative = bcadd($stageDayTwoAccumulative, $taskTemplateInfo['stage_day_three']); // 第三阶段累计天数 第二阶段累计值+第三阶段天数 + + // 1 当前任务进行天数 < 第一阶段天数 只判断当天是否完成 状态未完成则关闭任务 + if ($taskDayCount < $stageDayOneAccumulative) { + if ($task['status'] != 3) { + (new Task())->closeTask($task['id']); + } + return false; + } + + // 2 当前任务进行天数 = 第一阶段天数 做第一阶段结算 且更改 task_schedule_plan 状态为已结算,后续将会根据这个时间来筛选、统计、判断各阶段周期内是否达成完成条件 + if($taskDayCount == $stageDayOneAccumulative){ + $doneTaskCount = Task::where(['template_id'=>$taskTemplateInfo['id'], 'status'=>3])->count(); + if ($doneTaskCount >= 4) { + $task['money'] = bcmul($taskTemplateInfo['stage_day_one'], $taskTemplateInfo['money'], 2); + (new TownShareProfit())->townTaskType4($task, $townCompany, $taskSchedulePlan); + } + return false; + } + + // 3 第一阶段天数 < 当前任务进行天数 < (第一 + 第二) 只判断当天是否完成 状态未完成则关闭任务 + if ($stageDayOneAccumulative < $taskDayCount && $taskDayCount < $stageDayTwoAccumulative) { + if ($task['status'] != 3) { + (new Task())->closeTask($task['id']); + } + return false; + } + + // 4 当前任务进行天数 = (第一阶段+第二阶段)天数 第二阶段结算 且更改 task_schedule_plan 状态为已结算 + if ($taskDayCount == $stageDayTwoAccumulative) { + // 上一次做了结算的任务计划 + $lastTaskSchedulePlan = TaskSchedulingPlan::where(['template_id'=>$taskTemplateInfo['id'], 'is_pay'=>1])->order('start_time', 'desc')->find(); + // 上一次结算后到现在,完成的任务次数 + $doneTaskCount = Task::where(['template_id'=>$taskTemplateInfo['id'], 'status'=>3])->whereBetween('start_time', [$lastTaskSchedulePlan['start_time'], time()])->count(); + if ($doneTaskCount >= 4) { + $task['money'] = bcmul($taskTemplateInfo['stage_day_two'], $taskTemplateInfo['money_two'], 2); + (new TownShareProfit())->townTaskType4($task, $townCompany, $taskSchedulePlan); + } + return false; + } + + // 5 第一阶段+第二阶段 < 当前任务进行天数 < (第一 + 第二 + 第三阶段天数) 只判断当天是否完成 状态未完成则关闭任务 + if ($stageDayTwoAccumulative < $taskDayCount && $taskDayCount < $stageDayThreeAccumulative) { + if ($task['status'] != 3) { + (new Task())->closeTask($task['id']); + } + return false; + } + + // 6 当前任务进行天数 = (第一 + 第二 + 第三阶段天数) 第三阶段结算 且更改 task_schedule_plan 状态为已结算 + if ($taskDayCount == $stageDayThreeAccumulative) { + // 上一次做了结算的任务计划 + $lastTaskSchedulePlan = TaskSchedulingPlan::where(['template_id'=>$taskTemplateInfo['id'], 'is_pay'=>1])->order('start_time', 'desc')->find(); + // 上一次结算后到现在,完成的任务次数 + $doneTaskCount = Task::where(['template_id'=>$taskTemplateInfo['id'], 'status'=>3])->whereBetween('start_time', [$lastTaskSchedulePlan['start_time'], time()])->count(); + if ($doneTaskCount >= 4) { + $task['money'] = bcmul($taskTemplateInfo['stage_day_three'], $taskTemplateInfo['new_money_three'], 2); + (new TownShareProfit())->townTaskType4($task, $townCompany, $taskSchedulePlan); + } + return false; + } + + // 7 当前任务进行天数 > (第一 + 第二 + 第三阶段天数) 但 当前任务进行天数/30 != 0 只判断当天是否完成 状态未完成则关闭任务 + if($taskDayCount > $stageDayThreeAccumulative && $taskDayCount%30 != 0) { + if ($task['status'] != 3) { + (new Task())->closeTask($task['id']); + } + return false; + } + + // 8 当前任务进行天数/30 = 0, 长期阶段结算 且更改 task_schedule_plan 状态为已结算 + if ($taskDayCount > $stageDayThreeAccumulative && $taskDayCount%30 == 0) { + // 上一次做了结算的任务计划 + $lastTaskSchedulePlan = TaskSchedulingPlan::where(['template_id'=>$taskTemplateInfo['id'], 'is_pay'=>1])->order('start_time', 'desc')->find(); + // 上一次结算后到现在,完成的任务次数 + $doneTaskCount = Task::where(['template_id'=>$taskTemplateInfo['id'], 'status'=>3])->whereBetween('start_time', [$lastTaskSchedulePlan['start_time'], time()])->count(); + if ($doneTaskCount >= 4) { + $task['money'] = bcmul(30, $taskTemplateInfo['money_three'], 2); + (new TownShareProfit())->townTaskType4($task, $townCompany, $taskSchedulePlan); + } + return false; + } } private static function dealTownTask5($taskSchedulePlan) diff --git a/app/common/model/dict/DictData.php b/app/common/model/dict/DictData.php index 3b4f9847f..6e69145ca 100755 --- a/app/common/model/dict/DictData.php +++ b/app/common/model/dict/DictData.php @@ -44,4 +44,13 @@ class DictData extends BaseModel return $data['status'] ? '正常' : '停用'; } + // 根据镇管理公司任务类型,获取code + public function getTownTaskType($typeId){ + $townTaskTypeList = DictData::where(['type_value' => 'town_task_type', 'status' => 1])->column('value', 'id'); + if(isset($townTaskTypeList[$typeId])) { + return $townTaskTypeList[$typeId]; + } + return ''; + } + } \ No newline at end of file diff --git a/app/common/model/task/Task.php b/app/common/model/task/Task.php index 67c4d2680..172e01443 100644 --- a/app/common/model/task/Task.php +++ b/app/common/model/task/Task.php @@ -48,4 +48,9 @@ class Task extends BaseModel return $this->hasOne(User::class, 'id', 'director_uid')->field(['id', 'nickname', 'avatar']); } + // 关闭任务 + public function closeTask($id) { + return Task::where(['id'=>$id])->save(['status'=>5]); + } + } \ No newline at end of file diff --git a/app/common/model/task_scheduling_plan/TaskSchedulingPlan.php b/app/common/model/task_scheduling_plan/TaskSchedulingPlan.php index 6c34cb626..77a87f014 100644 --- a/app/common/model/task_scheduling_plan/TaskSchedulingPlan.php +++ b/app/common/model/task_scheduling_plan/TaskSchedulingPlan.php @@ -57,4 +57,7 @@ class TaskSchedulingPlan extends BaseModel public function scheduling(){ return $this->hasOne(TaskScheduling::class,'id','scheduling_id'); } + public function settlement($id=0){ + TaskSchedulingPlan::where('id', $id)->update(['is_pay' => 1]); + } } \ No newline at end of file