diff --git a/app/common/logic/finance/TownShareProfit.php b/app/common/logic/finance/TownShareProfit.php index 50906c256..98cef9598 100644 --- a/app/common/logic/finance/TownShareProfit.php +++ b/app/common/logic/finance/TownShareProfit.php @@ -16,50 +16,37 @@ class TownShareProfit { public function townTaskType1($taskInfo, $company, $taskSchedulePlan) { - // if ($company['day_count'] <= $data['proportion_one']) { - // $proportion = $data['proportion_one']; - // } else { - // $proportion = $data['proportion_two']; - // } - Db::startTrans(); try { + Db::startTrans(); + $proportion = 0; //总金额除以2等于不可提现账号金额和收益 $masterMoney = bcdiv($taskInfo['money'], 2, 2); - //收益的25%为负责人的收益 其余为成员的平分收益 - $masterUserMoney = bcdiv($masterMoney, 2, 2); - - //成员数量 - $userAll = User::where('company_id', $company['company_id'])->where('admin_id', 0)->field('id,user_money')->select(); - $userAllCount = count($userAll); - // 每个成员的收益 - $perUserMoney = bcdiv($masterUserMoney, $userAllCount, 2); - - $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,完成方:服务部长。'; - // 服务部长 + $remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,'; + //服务部长收益 任务金额的50%为服务部长的收益 $serviceManagerUser = User::where(['company_id' => $company['id'], 'group_id' => 14])->find(); - $arr = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $masterUserMoney, $taskSchedulePlan['sn'], $remark.'任务结算获得收益' . $masterUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + 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, $masterUserMoney, $taskSchedulePlan['sn'], $remark . '获得账户余额' . $masterUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; + // 用户余额变动 + $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); - // 成员 - foreach ($userAll as $value) { - $arr = [$value['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $perUserMoney, $taskSchedulePlan['sn'], $remark. '获得收益' . $perUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; - $this->member($arr); - $arr_two = [$value['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $perUserMoney, $taskSchedulePlan['sn'], $remark. '获得账户余额' . $perUserMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1]; - $this->Account($arr_two); - } - // 公司 - if ($taskSchedulePlan['company_account_type'] == 1) { - $deposit_count = bcadd($company['deposit'], $masterMoney, 2); - $this->AccountLog($company['id'], $deposit_count, $masterMoney); - $company_money_count = bcadd($company['company_money'], $masterMoney, 2); - $this->AccountLog($company['id'], $company_money_count, $masterMoney); - Company::where('id', $company['id'])->update(['deposit' => Db::raw('deposit+' . $masterMoney), 'company_money' => Db::raw('company_money+' . $masterMoney)]); - } + $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)]); + + // 更改任务状态 + Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3]); + Db::commit(); return true; } catch (\Exception $e) { diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php index 256750118..b983cedf2 100644 --- a/app/common/logic/task/TaskLogic.php +++ b/app/common/logic/task/TaskLogic.php @@ -459,9 +459,9 @@ class TaskLogic extends BaseLogic continue; } } - + // 下属小组服务公司有任务安排,也完成了任务 if ($isDone === 1 && $isTaskSchedule === 1) { - // 下属小组服务公司有任务安排,也完成了任务 做任务结算,分润 + // 做任务结算,分润 (new TownShareProfit())->townTaskType1($taskInfo, $townCompany, $taskSchedulePlan); } else { // 关闭任务 diff --git a/app/common/model/company/CompanyAccountLog.php b/app/common/model/company/CompanyAccountLog.php index 378ae3c45..476ccd4d2 100644 --- a/app/common/model/company/CompanyAccountLog.php +++ b/app/common/model/company/CompanyAccountLog.php @@ -76,11 +76,11 @@ class CompanyAccountLog extends BaseModel */ /** - * 保证金 + * 任务收益 */ const TASK_INC_DEPOSIT = 200; /** - * 收益 + * 公司余额 */ const TASK_INC_COMPANY_MONEY = 201; /**