where('admin_id', 0)->field('id,user_money')->select(); $yser_all_count = count($userAll); $member_maoney_user = bcdiv($master_maoney_user, $yser_all_count, 2); //负责人 $arr = [$company['user_id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $master_maoney_user, $data['sn'], $data['msg'] . '获得收益' . $master_maoney_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']]; $this->master($arr); $arr_two = [$company['user_id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $master_maoney_user, $data['sn'], $data['msg'] . '获得账户余额' . $master_maoney_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']]; $this->Account($arr_two); //成员 foreach ($userAll as $key => $value) { $arr = [$value['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $member_maoney_user, $data['sn'], $data['msg'] . '获得收益' . $member_maoney_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']]; $this->member($arr); $arr_two = [$value['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $member_maoney_user, $data['sn'], $data['msg'] . '获得账户余额' . $member_maoney_user . '元', ['company_id' => $data['company_id'], 'proportion' => $proportion], $data['status']]; $this->Account($arr_two); } //公司 if ($data['company_account_type'] == 1) { $deposit_count = bcadd($company['deposit'], $master_maoney, 2); $this->AccountLog($data['company_id'], $deposit_count, $master_maoney); $company_money_count = bcadd($company['company_money'], $master_maoney, 2); $this->AccountLog($data['company_id'], $company_money_count, $master_maoney); Company::where('id', $data['company_id'])->update(['deposit' => Db::raw('deposit+' . $master_maoney), 'company_money' => Db::raw('company_money+' . $master_maoney)]); } elseif ($data['company_account_type'] == 2) { $company_money_count = bcadd($company['shareholder_money'], $data['money'], 2); $this->AccountLog($data['company_id'], $company_money_count, $data['money'], 1, 2); Company::where('id', $data['company_id'])->update([ 'deposit' => Db::raw('deposit+' . $master_maoney), 'company_money' => Db::raw('company_money+' . $master_maoney), 'shareholder_money' => Db::raw('shareholder_money+' . $datas['template_info']['over_decimal']) ]); } if (isset($datas['template_info']['type']) && $datas['template_info']['type'] == 35) { if ($company['responsible_area']) { $responsible_area = explode(',', $company['responsible_area']); } else { Log::error('结算失败:没有区域' . json_encode($data)); return false; } $director_uid = Task::where('id', $datas['task_id'])->value('director_uid'); $shareholder_user = User::where('id', $director_uid)->field('id,nickname,brigade')->find(); $money = bcdiv($datas['template_info']['over_decimal'], count($responsible_area), 2); $left_amount = 0; foreach ($responsible_area as $kkk => $vvv) { $left_amount += bcadd($company['shareholder_money'], $money, 2); $company_log = [ 'sn' => generate_sn(UserAccountLog::class, 'sn', 20), 'company_id' => $datas['company_id'], 'change_object' => CompanyAccountLog::SHAREHOLDER, //变动对象 'change_type' => CompanyAccountLog::TASK_INC_SHAREHOLDER_MONEY, //变动类型 'action' => CompanyAccountLog::INC, //1-增加 2-减少 'left_amount' => $left_amount, //变动后数量 'change_amount' => $money, //变动数量 'remark' => $shareholder_user['nickname'] . '完成了' . $vvv . '队的股金:' . $money . '元', 'status' => 1, ]; CompanyAccountLog::create($company_log); } } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); Log::error('54-任务结算失败:' . $e->getMessage()); return false; } } public function AccountLog($companyId, $left_amount, $changeAmount, $change_object = 1, $change_type = 1, $action = 1) { $company_log = [ 'sn' => generate_sn(UserAccountLog::class, 'sn', 20), 'company_id' => $companyId, 'change_object' => $change_object, //变动对象 'change_type' => $change_type, //变动类型 'action' => $action, //1-增加 2-减少 'left_amount' => $left_amount, //变动后数量 'change_amount' => $changeAmount, //变动数量 'status' => 1, ]; CompanyAccountLog::create($company_log); } /**负责人的分润 * @param $data */ private function master($data) { User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('user_money+' . $data[3])]); return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]); } /**成员分润 * @param $data */ private function member($data) { User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('user_money+' . $data[3])]); return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]); } private function Account($data) { return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]); } }