diff --git a/app/adminapi/controller/approve/ApproveController.php b/app/adminapi/controller/approve/ApproveController.php index 51dc4b541..237fefdc6 100644 --- a/app/adminapi/controller/approve/ApproveController.php +++ b/app/adminapi/controller/approve/ApproveController.php @@ -4,6 +4,7 @@ namespace app\adminapi\controller\approve; use app\adminapi\controller\BaseAdminController; use app\adminapi\lists\approve\ApproveLists; +use app\common\logic\task\TaskLogic; use app\common\model\Approve; use app\common\model\task\Task; use app\common\model\task_scheduling_plan\TaskSchedulingPlan; @@ -43,11 +44,28 @@ class ApproveController extends BaseAdminController // 通过 private function pass($approve) { + Db::startTrans(); + $approve->check_status = 2; + $approve->update_time = time(); + $approve->save(); + // 任务 $task = Task::find($approve['task_id']); if ($task['status'] == 2) { $task->status = 3; $task->save(); } + Db::commit(); + + // 结算 + if ($approve->type == Approve::APPROVE_TYPE_4) { + $taskSchedulePlan = TaskSchedulingPlan::where(['id', $task['scheduling_plan_id']]) + ->withJoin(['scheduling'], 'left') + ->where('scheduling.company_type', 41) + ->where('is_pay',0) + ->with(['template_info']) + ->find(); + TaskLogic::dealTaskMarketingDirector10($taskSchedulePlan, $approve); + } } // 拒绝 diff --git a/app/api/controller/TaskController.php b/app/api/controller/TaskController.php index a6f7d8a31..8b160580c 100644 --- a/app/api/controller/TaskController.php +++ b/app/api/controller/TaskController.php @@ -405,6 +405,7 @@ class TaskController extends BaseApiController Db::startTrans(); $extend = []; $stage = $parmas['stage']; // 当前做的是任务第几阶段 + $extend['stage'] = $stage; if ($stage == 1) { $extend['stage1'] = $parmas['stage1']; } diff --git a/app/common/logic/finance/TownShareProfit.php b/app/common/logic/finance/TownShareProfit.php index 25cd156ff..f5c38592b 100644 --- a/app/common/logic/finance/TownShareProfit.php +++ b/app/common/logic/finance/TownShareProfit.php @@ -24,7 +24,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -45,7 +45,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); } Db::commit(); @@ -65,7 +65,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -82,7 +82,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -100,7 +100,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); // 更新镇交易池 (new TaskTemplate())->updateTransactionPool($taskSchedulePlan['template_info']['id'], $leftTransactionPool); Db::commit(); @@ -120,7 +120,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -137,7 +137,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -239,7 +239,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -257,7 +257,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -275,7 +275,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -293,7 +293,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -311,7 +311,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -329,7 +329,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -347,7 +347,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -365,7 +365,7 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { @@ -383,7 +383,25 @@ class TownShareProfit // 更改结算状态 (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); // 更改任务状态 - Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage()); + return false; + } + } + + public function dealTaskSettlementMarketingDirector10(Task $taskInfo, Company $townCompany, TaskSchedulingPlan $taskSchedulePlan) + { + try { + Db::startTrans(); + $this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan); + // 更改结算状态 + (new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']); + // 更改任务状态 + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]); Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index 2d866cfb6..347fdbcbe 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -1497,8 +1497,12 @@ class TaskLogic extends BaseLogic /** * @param $taskSchedulePlan * 数字农贸宣传业务、加工业务的建设和招商工作 后台审批通过时做结算 把凭证保存到任务的extend中 + * 第一阶段 审批通过,判断任务是否还在第一阶段,在就结算,不在则关闭任务 + * 第二阶段 审批通过,判断任务是否还在第一阶段,在就结算,不在则关闭任务 + * 第三阶段 审批通过,判断任务是否还在第一阶段,在就结算,不在则关闭任务 + * 第四阶段 审批通过,判断任务是否还在第一阶段,在就结算,不在则关闭任务 */ - private static function dealTaskMarketingDirector10($taskSchedulePlan) + public static function dealTaskMarketingDirector10($taskSchedulePlan, $approve) { $templateInfo = $taskSchedulePlan['template_info']; $dayCount = $templateInfo['day_count']; @@ -1507,32 +1511,59 @@ class TaskLogic extends BaseLogic $stageDayThreeCount = bcadd($templateInfo['stage_day_three'], $stageDayTwoCount); $townCompany = Company::where(['id' => $templateInfo['company_id']])->find(); $taskInfo = Task::where(['id' => $taskSchedulePlan['task_id']])->find(); + $approveExtend = json_decode($approve['extend'], true); - // 任务累计天数 < 第一阶段天数 关闭任务 - if ($dayCount < $stageDayOne) { - (new Task())->closeTask($taskSchedulePlan['task_id']); + // 第一阶段 审批通过,判断任务是否还在第一阶段,在就结算,不在则关闭任务 + if ($approveExtend['stage'] == 1) { + if ($dayCount <= $stageDayOne) { + // 结算 + $taskMoney = bcmul($templateInfo['money'], $stageDayOne, 2); + $taskInfo['money'] = $taskMoney; + (new TownShareProfit())->dealTaskSettlementMarketingDirector10($taskInfo, $townCompany, $taskSchedulePlan); + } else { + // 关闭任务 + (new Task())->closeTask($taskSchedulePlan['task_id']); + } } - // 任务累计天数 = 第一阶段 判定任务完成情况,计算任务金额,分润结算 - if ($dayCount == $stageDayOne) { - + // 第二阶段 审批通过,判断任务是否还在第二阶段,在就结算,不在则关闭任务 + if ($approveExtend['stage'] == 2) { + if ($stageDayOne < $dayCount && $dayCount <= $stageDayTwoCount) { + // 结算 + $taskMoney = bcmul($templateInfo['money_two'], $templateInfo['stage_day_two'], 2); + $taskInfo['money'] = $taskMoney; + (new TownShareProfit())->dealTaskSettlementMarketingDirector10($taskInfo, $townCompany, $taskSchedulePlan); + } else { + // 关闭任务 + (new Task())->closeTask($taskSchedulePlan['task_id']); + } } - // 第一阶段 < 任务累计天数 < 第一+第二阶段天数 关闭任务 - if ($dayCount < $stageDayTwoCount) { - + // 第三阶段 审批通过,判断任务是否还在第三阶段,在就结算,不在则关闭任务 + if ($approveExtend['stage'] == 3) { + if ($stageDayTwoCount < $dayCount && $dayCount <= $stageDayThreeCount) { + // 结算 + $taskMoney = bcmul($templateInfo['new_money_three'], $templateInfo['stage_day_three'], 2); + $taskInfo['money'] = $taskMoney; + (new TownShareProfit())->dealTaskSettlementMarketingDirector10($taskInfo, $townCompany, $taskSchedulePlan); + } else { + // 关闭任务 + (new Task())->closeTask($taskSchedulePlan['task_id']); + } } - // 任务累计天数 = 第一+第二阶段 判定任务完成情况,计算任务金额,分润结算 - - // 第一+第二阶段 < 任务累计天数 < 第一+第二+第三阶段天数 关闭任务 - - // 任务累计天数 = 第一+第二+第三阶段 判定任务完成情况,计算任务金额,分润结算 - - // 第一+第二+第三阶段天数 < 任务累计天数 且不能整除30 关闭任务 - - // 任务累计天数 > 第一+第二+第三阶段天数 且能整除30 判定任务完成情况,计算金额,分润 - + // 第四阶段 长期 审批通过,判断任务是否还在第四阶段,在就结算,不在则关闭任务 + if ($approveExtend['stage'] == 4) { + if ($dayCount > $stageDayThreeCount) { + // 结算 + $taskMoney = bcmul($templateInfo['money_three'], 30, 2); + $taskInfo['money'] = $taskMoney; + (new TownShareProfit())->dealTaskSettlementMarketingDirector10($taskInfo, $townCompany, $taskSchedulePlan); + } else { + // 关闭任务 + (new Task())->closeTask($taskSchedulePlan['task_id']); + } + } } /** * @param $taskSchedulePlan