- products.whitelabel_variant_id, product_images.position/size_cm mit Backfill aus Produktnamen - WhiteLabelResolver: Farbe vom Produkt, Kundenlogo je Position, Fehler statt stillem Rückfall; Altlogik für Produkte ohne Variante - Attribute: Variantenwert-Parsing und Farbname ohne Größe - Produkt- und Kundenformular um Variante, Position und Größe ergänzt - Lieferschein noch nicht umgestellt (WL-03, wartet auf K6/K7) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
652 lines
26 KiB
PHP
Executable file
652 lines
26 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Exports\ExcelExport;
|
|
use App\Mail\MailAccountActive;
|
|
use App\Mail\MailCustomMessage;
|
|
use App\Mail\MailVerifyAccount;
|
|
use App\Mail\MailVerifyContact;
|
|
use App\Models\UserAccount;
|
|
use App\Models\UserHistory;
|
|
use App\Models\UserWhitelabelProduct;
|
|
use App\Repositories\ContractPDFRepository;
|
|
use App\Repositories\UserRepository;
|
|
use App\Services\ProductImage;
|
|
use App\Services\SysLog;
|
|
use App\Services\UserService;
|
|
use App\User;
|
|
use Illuminate\Contracts\View\Factory;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Routing\Redirector;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\View\View;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Request;
|
|
use Validator;
|
|
|
|
class LeadController extends Controller
|
|
{
|
|
protected $userRepo;
|
|
|
|
public function __construct(UserRepository $userRepo)
|
|
{
|
|
$this->middleware('admin');
|
|
$this->userRepo = $userRepo;
|
|
|
|
}
|
|
|
|
/**
|
|
* @return Factory|View
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->setFilterVars();
|
|
$data = [
|
|
'values' => User::where('admin', '=', 0)->where('confirmation_code_remider', '!=', 2)->get(),
|
|
|
|
];
|
|
|
|
return view('admin.lead.index', $data);
|
|
}
|
|
|
|
/**
|
|
* @return Factory|View
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
if ($id === 'new') {
|
|
$user = new User;
|
|
$user->account = new UserAccount;
|
|
$user->account->same_as_billing = 1;
|
|
$user->account->country_id = 1;
|
|
$user->account->shipping_country_id = 1;
|
|
$user->id = 'new';
|
|
} else {
|
|
$user = User::findOrFail($id);
|
|
if (! $user->account) {
|
|
$user->account = new UserAccount;
|
|
}
|
|
}
|
|
$data = [
|
|
'show' => Request::get('show'),
|
|
'user' => $user,
|
|
'can_change_mail' => true,
|
|
'm_data_load' => false,
|
|
'm_data_error' => false,
|
|
];
|
|
|
|
return view('admin.lead.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* @return Factory|View
|
|
*/
|
|
public function editPost($id)
|
|
{
|
|
$m_data_load = false;
|
|
$m_data_error = false;
|
|
$data = Request::all();
|
|
if (! isset($data['edit_m_data_key']) || $data['edit_m_data_key'] !== config('main.edit_data_pass')) {
|
|
$m_data_error = 'Das Passwort ist falsch.';
|
|
} else {
|
|
$m_data_load = true;
|
|
}
|
|
|
|
if ($id === 'new') {
|
|
$user = new User;
|
|
$user->account = new UserAccount;
|
|
$user->account->same_as_billing = 1;
|
|
$user->account->country_id = 1;
|
|
$user->account->shipping_country_id = 1;
|
|
$user->id = 'new';
|
|
} else {
|
|
$user = User::findOrFail($id);
|
|
if (! $user->account) {
|
|
$user->account = new UserAccount;
|
|
}
|
|
}
|
|
$next_account_id = UserAccount::withTrashed()->max('m_account') + 1;
|
|
if ($user->account->m_account === null) {
|
|
$user->account->m_account = $next_account_id;
|
|
}
|
|
|
|
$data = [
|
|
'show' => 'check_lead',
|
|
'user' => $user,
|
|
'm_data_load' => $m_data_load,
|
|
'm_data_error' => $m_data_error,
|
|
'can_change_mail' => true,
|
|
'next_account_id' => $next_account_id,
|
|
];
|
|
|
|
return view('admin.lead.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* @return Factory|RedirectResponse|Redirector|View
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
|
|
$data = Request::all();
|
|
$show = Request::get('show');
|
|
|
|
if (isset($data['action']) && $data['action'] == 'reverse_charge_validate' && isset($data['user_id'])) {
|
|
$user = User::findOrFail($data['user_id']);
|
|
|
|
return $this->userRepo->reverse_charge_validate($data, $user, route('admin_lead_edit', [$user->id]));
|
|
}
|
|
|
|
if (isset($data['action']) && $data['action'] == 'reverse_charge_delete' && isset($data['user_id'])) {
|
|
$user = User::findOrFail($data['user_id']);
|
|
|
|
return $this->userRepo->reverse_charge_delete($data, $user, route('admin_lead_edit', [$user->id]));
|
|
}
|
|
|
|
if ($data['user_id'] === 'new' || $data['user_id'] == 0) {
|
|
$rules = [
|
|
'salutation' => 'required',
|
|
'first_name' => 'required',
|
|
'last_name' => 'required',
|
|
'email' => 'required|string|email|max:255|unique:users',
|
|
'email-confirm' => 'required|same:email',
|
|
];
|
|
} else {
|
|
$rules = [
|
|
'salutation' => 'required',
|
|
'first_name' => 'required',
|
|
'last_name' => 'required',
|
|
'address' => 'required',
|
|
'zipcode' => 'required',
|
|
'city' => 'required',
|
|
'email' => 'required|string|email|max:255|exists:users,email',
|
|
'email-confirm' => 'required|same:email',
|
|
];
|
|
if (! Request::get('same_as_billing')) {
|
|
$rules = array_merge($rules, [
|
|
'shipping_firstname' => 'required',
|
|
'shipping_lastname' => 'required',
|
|
'shipping_address' => 'required',
|
|
'shipping_zipcode' => 'required',
|
|
'shipping_city' => 'required',
|
|
'shipping_salutation' => 'required',
|
|
|
|
]);
|
|
}
|
|
}
|
|
|
|
if (isset($data['m_account']) && $data['m_account']) {
|
|
$user = User::findOrFail($data['user_id']);
|
|
$rules['m_account'] = 'unique:user_accounts,m_account,'.$user->account->id.',id';
|
|
}
|
|
$validator = Validator::make(Request::all(), $rules);
|
|
if ($validator->fails()) {
|
|
|
|
if ($data['user_id'] === 'new' || $data['user_id'] == 0) {
|
|
$user_id = 'new';
|
|
} else {
|
|
$user = User::findOrFail($data['user_id']);
|
|
$user_id = $user->id;
|
|
}
|
|
|
|
return redirect(route('admin_lead_edit', [$user_id]).'?show='.$show)->withErrors($validator)->withRequest(Request::all());
|
|
}
|
|
|
|
if ($data['user_id'] === 'new' || $data['user_id'] == 0) {
|
|
$user = new User;
|
|
$user->id = 'new';
|
|
$user->account = new UserAccount;
|
|
|
|
} else {
|
|
$user = User::findOrFail($data['user_id']);
|
|
if (! $user->account) {
|
|
$user->account = new UserAccount;
|
|
}
|
|
}
|
|
|
|
$this->userRepo->update($data);
|
|
|
|
if (isset($data['m_data_edit']) && $data['m_data_edit'] === 'TSOK') {
|
|
$user = $this->userRepo->getModel();
|
|
$user->m_level = isset($data['m_level']) ? $data['m_level'] : null;
|
|
$user->lead_type_id = isset($data['lead_type_id']) ? $data['lead_type_id'] : null;
|
|
$user->m_sponsor = isset($data['m_sponsor']) ? $data['m_sponsor'] : null;
|
|
$user->save();
|
|
}
|
|
|
|
if (isset($data['contact_verify'])) {
|
|
|
|
$user = $this->userRepo->getModel();
|
|
|
|
$confirmation_code = UserService::createConfirmationCode();
|
|
|
|
$user->lang = $user->getLandByCountry();
|
|
$user->confirmation_code = $confirmation_code;
|
|
// 10 == start wizard form create Lead
|
|
$user->wizard = 10;
|
|
$user->save();
|
|
Mail::to($user->email)->bcc(config('app.info_mail'))->send(new MailVerifyContact($confirmation_code, $user));
|
|
|
|
\Session()->flash('alert-save', true);
|
|
|
|
return redirect(route('admin_leads'));
|
|
}
|
|
|
|
\Session()->flash('alert-save', true);
|
|
|
|
return redirect(route('admin_lead_edit', [$user->id]).'?show='.$show);
|
|
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$data = Request::all();
|
|
$show = Request::get('show');
|
|
if (! isset($data['user_id']) || $data['user_id'] === 'new' || $data['user_id'] == 0) {
|
|
abort(404, 'User not found');
|
|
}
|
|
$user = User::findOrFail($data['user_id']);
|
|
|
|
if (isset($data['action'])) {
|
|
|
|
// add whitelabel products
|
|
if ($data['action'] === 'add_whitelabel_products') {
|
|
if (isset($data['whitelabel_products']) && is_array($data['whitelabel_products'])) {
|
|
foreach ($data['whitelabel_products'] as $product_id) {
|
|
$user->whitelabel_products()->create(['product_id' => $product_id]);
|
|
}
|
|
}
|
|
\Session()->flash('alert-save', true);
|
|
}
|
|
// remove whitelabel products
|
|
if ($data['action'] === 'remove_whitelabel_products') {
|
|
if (isset($data['whitelabel_products']) && is_array($data['whitelabel_products'])) {
|
|
$user->whitelabel_products()->whereIn('product_id', $data['whitelabel_products'])->delete();
|
|
}
|
|
\Session()->flash('alert-success', 'Produkt gelöscht');
|
|
}
|
|
if ($data['action'] === 'upload_white_label_image') {
|
|
// id == user_whitelabel_product_id
|
|
$whitelabel_product = UserWhitelabelProduct::findOrFail($data['id']);
|
|
if ($whitelabel_product && $user->id == $whitelabel_product->user_id) {
|
|
return ProductImage::imageUpload('user_wl_product', $whitelabel_product, Request::get('upload_type'));
|
|
}
|
|
}
|
|
// update whitelabel products
|
|
if ($data['action'] === 'update_whitelabel_products') {
|
|
$positions = isset($data['image_wl_position']) && is_array($data['image_wl_position']) ? $data['image_wl_position'] : [];
|
|
if (isset($data['image_wl_attributes']) && is_array($data['image_wl_attributes'])) {
|
|
foreach ($user->whitelabel_products as $wl_product) {
|
|
foreach ($wl_product->whitelabel_images as $wl_image) {
|
|
$position = $positions[$wl_image->id] ?? null;
|
|
$wl_image->update([
|
|
'attributes' => isset($data['image_wl_attributes'][$wl_image->id]) ? $data['image_wl_attributes'][$wl_image->id] : null,
|
|
'position' => array_key_exists($position, \App\Models\ProductImage::POSITIONS) ? $position : ($wl_image->position ?: 'deckel'),
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
\Session()->flash('alert-save', true);
|
|
}
|
|
}
|
|
|
|
return redirect(route('admin_lead_edit', [$user->id]).'?show='.$show);
|
|
}
|
|
|
|
public function remove($action, $user_id, $id, $mid = null)
|
|
{
|
|
$show = Request::get('show');
|
|
$user = User::findOrFail($user_id);
|
|
|
|
if ($action === 'remove_whitelabel_label') {
|
|
$model = $user->whitelabel_products()->where('id', $id)->first();
|
|
|
|
return ProductImage::imageDelete('user_wl_image', $model, $mid);
|
|
}
|
|
|
|
if ($action === 'remove_whitelabel_product') {
|
|
|
|
$model = $user->whitelabel_products()->where('id', $id)->first();
|
|
// remove images
|
|
foreach ($model->whitelabel_images as $image) {
|
|
ProductImage::imageDelete('user_wl_image', $model, $image->id);
|
|
|
|
}
|
|
$model->delete();
|
|
\Session()->flash('alert-success', 'White Label Produkt entfernt');
|
|
|
|
return redirect(route('admin_lead_edit', [$user->id])."?show=$show");
|
|
}
|
|
|
|
}
|
|
|
|
public function download()
|
|
{
|
|
|
|
if (Request::get('action') === 'export') {
|
|
$query = $this->initSearch();
|
|
$columns = [];
|
|
$filename = 'GS-VP-export-'.date('d-m-Y');
|
|
$headers = [
|
|
'ID',
|
|
'Email',
|
|
'Firma',
|
|
'Anrede',
|
|
'Vorname',
|
|
'Nachname',
|
|
'Mitglied',
|
|
'Bis',
|
|
'Art',
|
|
|
|
];
|
|
$objects = $query->get();
|
|
if ($objects) {
|
|
foreach ($objects as $obj) {
|
|
$columns[] = [
|
|
'ID' => $obj->id,
|
|
'Email' => $obj->email,
|
|
'Firma' => $obj->account ? $obj->account->company : '',
|
|
'Anrede' => $obj->account ? ($obj->account->salutation == 'mr' ? 'Herr' : 'Frau') : '-',
|
|
'Vorname' => $obj->account ? $obj->account->first_name : '',
|
|
'Nachname' => $obj->account ? $obj->account->last_name : '',
|
|
'Mitglied' => $obj->payment_account ? ($obj->isActiveAccount() ? 'JA' : 'Abgelaufen') : 'Nein',
|
|
'Bis' => $obj->payment_account ? $obj->getPaymentAccountDateFormat(false) : '-',
|
|
'Art' => $obj->lead_type ? $obj->lead_type->name : '-',
|
|
];
|
|
}
|
|
}
|
|
|
|
return Excel::download(new ExcelExport($columns, $headers), $filename.'.xls');
|
|
}
|
|
}
|
|
|
|
private function setFilterVars()
|
|
{
|
|
if (! session('filter_lead_type_id')) {
|
|
session(['filter_lead_type_id' => 'all']);
|
|
}
|
|
if (Request::get('filter_lead_type_id')) {
|
|
session(['filter_lead_type_id' => Request::get('filter_lead_type_id')]);
|
|
}
|
|
}
|
|
|
|
private function initSearch()
|
|
{
|
|
$this->setFilterVars();
|
|
$query = User::with('account')->select('users.*')->where('users.deleted_at', '=', null)->where('users.admin', '<', 4);
|
|
if (session('filter_lead_type_id') && session('filter_lead_type_id') !== null && session('filter_lead_type_id') !== 'all') {
|
|
$query->where('lead_type_id', session('filter_lead_type_id'));
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function getLeads()
|
|
{
|
|
$query = $this->initSearch();
|
|
|
|
return \DataTables::eloquent($query)
|
|
->addColumn('first_name', function (User $user) {
|
|
return $user->account ? $user->account->first_name : '';
|
|
})
|
|
->addColumn('company', function (User $user) {
|
|
return $user->account ? $user->account->company : '';
|
|
})
|
|
->addColumn('last_name', function (User $user) {
|
|
return $user->account ? $user->account->last_name : '';
|
|
})
|
|
->addColumn('user_level', function (User $user) {
|
|
return $user->user_level ? $user->user_level->name : '';
|
|
})
|
|
->addColumn('lead_type', function (User $user) {
|
|
return $user->lead_type ? $user->lead_type->name : '';
|
|
})
|
|
->addColumn('id', function (User $user) {
|
|
return '<a href="'.route('admin_lead_edit', [$user->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="far fa-edit"></span></a>';
|
|
})
|
|
->addColumn('confirmed', function (User $user) {
|
|
return $user->confirmed ? '<span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
})
|
|
->addColumn('active', function (User $user) {
|
|
return $user->active ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
})
|
|
->addColumn('agreement', function (User $user) {
|
|
return $user->agreement ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
})
|
|
->addColumn('payment_account', function (User $user) {
|
|
return $user->payment_account ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
})
|
|
->addColumn('payment_account_date', function (User $user) {
|
|
return $user->payment_account ? $user->getPaymentAccountDateFormat(false) : '-';
|
|
})
|
|
/*->addColumn('payment_shop', function (User $user) {
|
|
return $user->payment_shop ? ' <span class="badge badge-pill badge-success"><i class="fa fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times"></i></span>';
|
|
})
|
|
->addColumn('payment_shop_date', function (User $user) {
|
|
return $user->payment_shop ? $user->getPaymentShopDateFormat(false) : "-";
|
|
})*/
|
|
->addColumn('turnover', function (User $user) {
|
|
return '-';
|
|
})
|
|
->addColumn('sales_total', function (User $user) {
|
|
return '-';
|
|
})
|
|
|
|
->orderColumn('id', 'id $1')
|
|
->orderColumn('confirmed', 'confirmed $1')
|
|
->orderColumn('active', 'active $1')
|
|
->orderColumn('lead_type', 'lead_type_id $1')
|
|
->orderColumn('agreement', 'agreement $1')
|
|
->orderColumn('payment_account', 'payment_account $1')
|
|
// ->orderColumn('payment_shop', 'payment_shop $1')
|
|
->rawColumns(['id', 'confirmed', 'active', 'agreement', 'payment_account'])
|
|
->make(true);
|
|
}
|
|
|
|
private function activeAccountPayment($user)
|
|
{
|
|
|
|
if ($user->user_level) {
|
|
if ($user->user_level->payment_year) {
|
|
// if true = payments
|
|
$user->wizard = 20;
|
|
$user->active = 1;
|
|
$user->active_date = now();
|
|
$user->confirmation_code = null;
|
|
$user->confirmation_code_to = null;
|
|
$user->confirmation_code_remider = 0;
|
|
$user->save();
|
|
} else {
|
|
// if false = no payments for 1 year
|
|
$user->wizard = 100;
|
|
$user->payment_account = \Carbon::now()->modify('1 year');
|
|
$user->active = 1;
|
|
$user->active_date = now();
|
|
$user->confirmation_code = null;
|
|
$user->confirmation_code_to = null;
|
|
$user->confirmation_code_remider = 0;
|
|
$user->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
// user released when register is complete
|
|
public function released($action, $id)
|
|
{
|
|
|
|
$user = User::findOrFail($id);
|
|
if ($action === 'completed') {
|
|
$validator = Validator::make(Request::all(), []);
|
|
/*if(!$user->m_sponsor){
|
|
$validator->errors()->add('m_sponsor', __('Vertriebspartner hat keinen Sponsor.'));
|
|
}*/
|
|
if (! $user->account->m_first_name) {
|
|
$validator->errors()->add('m_first_name', __('Vertriebspartner hat keinen Vornamen.'));
|
|
}
|
|
if (! $user->account->m_last_name) {
|
|
$validator->errors()->add('m_last_name', __('Vertriebspartner hat keinen Nachnamen.'));
|
|
}
|
|
if (! $user->m_level) {
|
|
$validator->errors()->add('m_level', __('Vertriebspartner hat keine Rolle'));
|
|
}
|
|
if ($validator->errors()->count()) {
|
|
return back()->withErrors($validator)->withRequest(Request::all());
|
|
}
|
|
|
|
if (! $user->account->m_account) {
|
|
$user->account->m_account = UserAccount::withTrashed()->max('m_account') + 1;
|
|
$user->account->save();
|
|
}
|
|
|
|
// create PDF
|
|
$pdf = new ContractPDFRepository($user);
|
|
$pdf->_set('disk', 'user');
|
|
$pdf->_set('dir', '/'.$user->id.'/documents/');
|
|
$pdf->_set('user_id', $user->id);
|
|
$pdf->_set('identifier', 'contract');
|
|
$pdf->createContractPDF();
|
|
|
|
// set wizard to payments / activate
|
|
$this->activeAccountPayment($user);
|
|
|
|
// mail with code to user?
|
|
try {
|
|
Mail::to($user->email)->bcc(config('app.info_mail'))->send(new MailAccountActive($user));
|
|
} catch (\Exception $e) {
|
|
SysLog::action('released', 'admin_lead', 5)
|
|
->setUserId($user->id)
|
|
->setModel($user->id, User::class)
|
|
->setMessage('Error send released E-Mail: '.$e->getMessage())
|
|
->save();
|
|
}
|
|
|
|
UserHistory::create(['user_id' => $user->id, 'action' => 'released_completed', 'status' => 0]);
|
|
\Session()->flash('alert-success', 'Vertriebspartner freigeschaltet!');
|
|
}
|
|
|
|
if ($action === 'incomplete') {
|
|
// reset release
|
|
$confirmation_code = UserService::createConfirmationCode();
|
|
$user->confirmation_code = $confirmation_code;
|
|
$user->confirmation_code_to = date('Y-m-d H:i:s', strtotime('+1 week'));
|
|
$user->confirmation_code_remider = 0;
|
|
$user->wizard = 1;
|
|
$user->release_account = null;
|
|
$user->save();
|
|
|
|
$input = Request::all();
|
|
$data = [
|
|
'subject' => $input['account_incomplete_subject'],
|
|
'message' => $input['account_incomplete_message'],
|
|
'confirmation_code' => $confirmation_code,
|
|
];
|
|
try {
|
|
Mail::to($user->email)->bcc(config('app.info_mail'))->send(new MailCustomMessage($user, $data, \Auth::user(), true));
|
|
} catch (\Exception $e) {
|
|
SysLog::action('released_incomplete', 'admin_lead', 5)
|
|
->setUserId($user->id)
|
|
->setModel($user->id, User::class)
|
|
->setMessage('Error send released_incomplete E-Mail: '.$e->getMessage())
|
|
->save();
|
|
}
|
|
UserHistory::create(['user_id' => $user->id, 'action' => 'released_incomplete', 'status' => 0]);
|
|
\Session()->flash('alert-success', 'E-Mail an Vertriebspartner gesendet.');
|
|
}
|
|
if ($action === 'reset_switch') {
|
|
$user->wizard = 3;
|
|
$user->save();
|
|
UserHistory::create(['user_id' => $user->id, 'action' => 'reset_switch', 'status' => 0]);
|
|
\Session()->flash('alert-success', 'Vertriebspartner zurückgesetzt!');
|
|
}
|
|
if ($action === 'unlock') {
|
|
$validator = Validator::make(Request::all(), []);
|
|
/*if(!$user->m_sponsor){
|
|
$validator->errors()->add('m_sponsor', __('Vertriebspartner hat keinen Sponsor.'));
|
|
}*/
|
|
if (! $user->account->m_first_name) {
|
|
$validator->errors()->add('m_first_name', __('Vertriebspartner hat keinen Vornamen.'));
|
|
}
|
|
if (! $user->account->m_last_name) {
|
|
$validator->errors()->add('m_last_name', __('Vertriebspartner hat keinen Nachnamen.'));
|
|
}
|
|
if (! $user->m_level) {
|
|
$validator->errors()->add('m_level', __('Vertriebspartner hat keine Rolle'));
|
|
}
|
|
|
|
if ($validator->errors()->count()) {
|
|
return back()->withErrors($validator)->withRequest(Request::all());
|
|
}
|
|
|
|
if (! $user->account->m_account) {
|
|
$user->account->m_account = UserAccount::withTrashed()->max('m_account') + 1;
|
|
$user->account->save();
|
|
}
|
|
|
|
// set wizard to payments / activate
|
|
$this->activeAccountPayment($user);
|
|
|
|
// mail with code to user?
|
|
try {
|
|
Mail::to($user->email)->bcc(config('app.info_mail'))->send(new MailAccountActive($user));
|
|
} catch (\Exception $e) {
|
|
SysLog::action('unlock', 'admin_lead', 5)
|
|
->setUserId($user->id)
|
|
->setModel($user->id, User::class)
|
|
->setMessage('Error send released E-Mail: '.$e->getMessage())
|
|
->save();
|
|
}
|
|
|
|
UserHistory::create(['user_id' => $user->id, 'action' => 'unlock_completed', 'status' => 0]);
|
|
\Session()->flash('alert-success', 'Vertriebspartner erneut freigeschaltet!');
|
|
}
|
|
|
|
return redirect(route('admin_lead_edit', [$user->id]));
|
|
|
|
}
|
|
|
|
// send new verfified mail to user
|
|
/* public function newMailVerified($id){
|
|
|
|
User Register sind in der DB UserRegister, erst bei bestätigung wird es in die User DB übertragen
|
|
|
|
$user = User::findOrFail($id);
|
|
|
|
$confirmation_code = UserService::createConfirmationCode();
|
|
$user->confirmation_code = $confirmation_code;
|
|
$user->confirmation_code_to = date('Y-m-d H:i:s', strtotime('+1 week'));
|
|
$user->confirmation_code_remider = 0;
|
|
$user->save();
|
|
|
|
try {
|
|
Mail::to($user->email)->bcc(config('app.info_mail'))->send(new MailVerifyAccount($confirmation_code, $user));
|
|
}
|
|
catch(\Exception $e){
|
|
SysLog::action('new_mail_verified', 'admin_lead', 5)
|
|
->setUserId($user->id)
|
|
->setModel($user->id, User::class)
|
|
->setMessage('Error send new_mail_verified E-Mail: '.$e->getMessage())
|
|
->save();
|
|
}
|
|
UserHistory::create(['user_id' => $user->id, 'action'=>'new_mail_verified', 'status'=>0]);
|
|
|
|
\Session()->flash('alert-success', "E-Mail erneut gesendet");
|
|
return redirect(route('admin_lead_edit', [$user->id]));
|
|
|
|
}*/
|
|
|
|
public function deleteFile($user_id, $file_id, $relation)
|
|
{
|
|
|
|
if ($relation === 'upload') {
|
|
$user = User::findOrFail($user_id);
|
|
$file = $user->files()->findOrFail($file_id);
|
|
// remove file
|
|
\Storage::disk('user')->delete($file->dir.$file->filename);
|
|
$file->delete();
|
|
\Session()->flash('alert-success', 'Datei gelöscht');
|
|
}
|
|
|
|
return back();
|
|
}
|
|
}
|