283 lines
No EOL
10 KiB
PHP
Executable file
283 lines
No EOL
10 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Mail\MailVerifyContact;
|
|
use App\Models\UserAccount;
|
|
use App\Repositories\UserRepository;
|
|
use App\User;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Input;
|
|
use Illuminate\Http\Request;
|
|
use Validator;
|
|
|
|
|
|
|
|
class LeadController extends Controller
|
|
{
|
|
protected $userRepo;
|
|
|
|
public function __construct(UserRepository $userRepo)
|
|
{
|
|
$this->middleware('admin');
|
|
$this->userRepo = $userRepo;
|
|
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function index()
|
|
{
|
|
$data = [
|
|
'values' => User::where('admin', '=', 0)->where('confirmation_code_remider', '!=', 2)->get(),
|
|
];
|
|
return view('admin.lead.index', $data);
|
|
}
|
|
|
|
|
|
/**
|
|
* @param $id
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\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 = [
|
|
'user' => $user,
|
|
'can_change_mail' => true,
|
|
'm_data_load' => false,
|
|
'm_data_error' => false,
|
|
];
|
|
return view('admin.lead.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* @param $id
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function editPost($id)
|
|
{
|
|
$m_data_load = false;
|
|
$m_data_error = false;
|
|
$data = Input::all();
|
|
if(!isset($data['edit_m_data_key']) && $data['edit_m_data_key'] !== "mivita"){
|
|
$m_data_error = "Der Key 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();
|
|
}
|
|
}
|
|
$data = [
|
|
'user' => $user,
|
|
'm_data_load' => $m_data_load,
|
|
'm_data_error' => $m_data_error,
|
|
'can_change_mail' => true,
|
|
];
|
|
return view('admin.lead.edit', $data);
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
|
|
$data = Input::all();
|
|
if ($data['user_id'] === "new" || $data['user_id'] == 0) {
|
|
$rules = array(
|
|
'salutation' => 'required',
|
|
'first_name'=>'required',
|
|
'last_name'=>'required',
|
|
'email' => 'required|string|email|max:255|unique:users',
|
|
'email-confirm' => 'required|same:email',
|
|
);
|
|
}else{
|
|
$rules = array(
|
|
'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(!Input::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'
|
|
|
|
]);
|
|
}
|
|
|
|
}
|
|
|
|
$validator = Validator::make(Input::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]))->withErrors($validator)->withInput(Input::all());
|
|
}else{
|
|
|
|
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->m_sponsor = isset($data['m_sponsor']) ? $data['m_sponsor'] : NULL;
|
|
$user->save();
|
|
}
|
|
|
|
if(isset($data['contact_verify'])){
|
|
|
|
$user = $this->userRepo->getModel();
|
|
|
|
$unique = false;
|
|
do{
|
|
$confirmation_code = str_random(30);
|
|
if( User::where('confirmation_code', '=', $confirmation_code)->count() == 0){
|
|
$unique = true;
|
|
}
|
|
}
|
|
while(!$unique);
|
|
|
|
$user->lang = $user->getLandByCountry();
|
|
$user->confirmation_code = $confirmation_code;
|
|
$user->save();
|
|
|
|
|
|
Mail::to($user->email)->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]));
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
/* @if($user->payment_account )
|
|
<p><span class="ion ion-md-checkmark-circle-outline text-primary"></span>
|
|
<strong>{{__('Account aktiv')}}</strong> {{__('bis zum:')}} {{ $user->getPaymentAccountDateFormat() }}</p>
|
|
@else
|
|
<p><span class="ion ion-md-close-circle-outline text-danger"></span>
|
|
<strong>{{__('Account inaktiv')}}</strong></p>
|
|
@endif
|
|
|
|
@if($user->payment_shop)
|
|
<p><span class="ion ion-md-checkmark-circle-outline text-primary"></span>
|
|
<strong>{{__('Shop aktiv')}}</strong> {{__('bis zum')}}: {{ $user->getPaymentShopDateFormat() }}</p>
|
|
@else
|
|
<p><span class="ion ion-md-close-circle-outline text-danger"></span>
|
|
<strong>{{__('Shop inaktiv')}}</strong></p>
|
|
@endif*/
|
|
public function getLeads()
|
|
{
|
|
|
|
$query = User::with('account')->where('users.deleted_at', '=', null);
|
|
|
|
return \DataTables::eloquent($query)
|
|
->addColumn('first_name', function (User $user) {
|
|
return $user->account ? $user->account->first_name : '';
|
|
})
|
|
->addColumn('last_name', function (User $user) {
|
|
return $user->account ? $user->account->last_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="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
|
})
|
|
->addColumn('active', function (User $user) {
|
|
return $user->active ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
|
})
|
|
->addColumn('agreement', function (User $user) {
|
|
return $user->agreement ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far fa-times"></i></span>';
|
|
})
|
|
->addColumn('payment_account', function (User $user) {
|
|
return $user->payment_account ? ' <span class="badge badge-pill badge-success"><i class="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far 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="far fa-check"></i></span>' : '<span class="badge badge-pill badge-danger"><i class="far 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('agreement', 'agreement $1')
|
|
->orderColumn('payment_account', 'payment_account $1')
|
|
->orderColumn('payment_shop', 'payment_shop $1')
|
|
->rawColumns(['id', 'confirmed', 'active', 'agreement', 'payment_account', 'payment_shop'])
|
|
->make(true);
|
|
}
|
|
} |