Kundenhoheit
This commit is contained in:
parent
d8b5206031
commit
dc63fa9fb2
52 changed files with 2436 additions and 557 deletions
135
app/Http/Controllers/CustomerController.php
Executable file
135
app/Http/Controllers/CustomerController.php
Executable file
|
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ShoppingUser;
|
||||
use App\Repositories\CustomerRepository;
|
||||
use App\Services\CustomerPriority;
|
||||
use App\Services\HTMLHelper;
|
||||
use Request;
|
||||
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
protected $customerRepository;
|
||||
|
||||
public function __construct(CustomerRepository $customerRepository)
|
||||
{
|
||||
$this->middleware('admin');
|
||||
$this->customerRepository = $customerRepository;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if(Request::get('reset') === 'filter'){
|
||||
set_user_attr('filter_member_id', null);
|
||||
set_user_attr('filter_customer_member', null);
|
||||
return redirect(route('admin_customers'));
|
||||
}
|
||||
$filter_members = ShoppingUser::join('users', 'member_id', '=', 'users.id')->groupBy('member_id')->join('user_accounts', 'account_id', '=', 'user_accounts.id')->select('users.id', 'users.email', 'user_accounts.first_name', 'user_accounts.last_name')->get(); //->pluck('email', 'id')->unique()->toArray();
|
||||
$data = [
|
||||
'filter_members' => $filter_members,
|
||||
];
|
||||
return view('admin.customer.index', $data);
|
||||
}
|
||||
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
if($id === "new"){
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_user->id = "new";
|
||||
}else{
|
||||
$shopping_user = ShoppingUser::findOrFail($id);
|
||||
}
|
||||
$data = [
|
||||
'shopping_user' => $shopping_user,
|
||||
'isAdmin' => true,
|
||||
'isView' => 'customer',
|
||||
|
||||
];
|
||||
return view('admin.customer.detail', $data);
|
||||
}
|
||||
|
||||
public function store($id)
|
||||
{
|
||||
$data = Request::all();
|
||||
$change_member_error = false;
|
||||
if($data['action']==='shopping-user-change-member'){
|
||||
if(!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')){
|
||||
$change_member_error = "Das Passwort ist falsch.";
|
||||
}else{
|
||||
//change
|
||||
$shopping_user = ShoppingUser::findOrFail($data['id']);
|
||||
CustomerPriority::newMemberForCustomer($shopping_user, $data['change_member_id'], $data['customer_set_member_for']);
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('admin_customer_edit', [$shopping_user->id]));
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'change_member_error' => $change_member_error,
|
||||
'shopping_user' => ShoppingUser::find($id),
|
||||
'isAdmin' => true,
|
||||
'isView' => 'customer',
|
||||
];
|
||||
return view('admin.customer.detail', $data);
|
||||
}
|
||||
|
||||
public function getCustomers()
|
||||
{
|
||||
$query = ShoppingUser::select('shopping_users.*')->where('auth_user_id', '=', NULL);
|
||||
|
||||
set_user_attr('filter_member_id', Request::get('filter_member_id'));
|
||||
if(Request::get('filter_member_id') != ""){
|
||||
$query->where('member_id', '=', Request::get('filter_member_id'));
|
||||
}
|
||||
/* set_user_attr('filter_customer_member', Request::get('filter_customer_member'));
|
||||
if(Request::get('filter_customer_member') != ""){
|
||||
if(Request::get('filter_customer_member') === 'customers'){
|
||||
$query->where('auth_user_id', '=', NULL);
|
||||
}
|
||||
if(Request::get('filter_customer_member') === 'members'){
|
||||
$query->where('auth_user_id', '!=', NULL);
|
||||
}
|
||||
}*/
|
||||
return \DataTables::eloquent($query)
|
||||
->addColumn('id', function (ShoppingUser $ShoppingUser) {
|
||||
return '<a href="' . route('admin_customer_edit', [$ShoppingUser->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="far fa-edit"></span></a>';
|
||||
})
|
||||
->addColumn('billing_salutation', function (ShoppingUser $ShoppingUser) {
|
||||
return HTMLHelper::getSalutationLang($ShoppingUser->billing_salutation);
|
||||
})
|
||||
->addColumn('billing_country_id', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->billing_country ? $ShoppingUser->billing_country->getLocated() : '';
|
||||
})
|
||||
->addColumn('isMember', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->auth_user_id ? '<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('member_id', function (ShoppingUser $ShoppingUser) {
|
||||
if($ShoppingUser->member_id){
|
||||
return '<a href="'.route('admin_lead_edit', [$ShoppingUser->member_id]).'">'.$ShoppingUser->member->getFullName().'</a>';
|
||||
}
|
||||
if($ShoppingUser->is_like){
|
||||
return '<button type="button" class="btn btn-xs btn-outline-info" data-toggle="modal" data-target="#modals-load-content"
|
||||
data-id="'.$ShoppingUser->id.'"
|
||||
data-action="shopping-user-is-like-member"
|
||||
data-back="'.route('admin_customers').'"
|
||||
data-modal="modal-xl"
|
||||
data-route="'.route('modal_load').'"><span class="fa fa-edit"></span> Berater zuordnen</button>';
|
||||
}
|
||||
return '';
|
||||
})
|
||||
->addColumn('created_at', function (ShoppingUser $ShoppingUser) {
|
||||
return $ShoppingUser->created_at->format('d.m.Y');
|
||||
})
|
||||
->orderColumn('id', 'id $1')
|
||||
->orderColumn('billing_country_id', 'billing_country_id $1')
|
||||
->orderColumn('billing_salutation', 'billing_salutation $1')
|
||||
->orderColumn('created_at', 'created_at $1')
|
||||
->orderColumn('isMember', 'auth_user_id $1')
|
||||
->orderColumn('member_id', 'member_id $1')
|
||||
->rawColumns(['id', 'isMember', 'member_id'])
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue