Kundenhoheit

This commit is contained in:
Kevin Adametz 2020-05-06 15:43:53 +02:00
parent d8b5206031
commit dc63fa9fb2
52 changed files with 2436 additions and 557 deletions

View file

@ -8,6 +8,7 @@ use App\Mail\MailCheckout;
use App\Models\PaymentTransaction;
use App\Models\ShoppingOrder;
use App\Models\ShoppingPayment;
use App\Services\Shop;
use App\Services\Util;
use App\User;
use Illuminate\Support\Facades\Mail;
@ -129,10 +130,12 @@ class PayoneController extends Controller
}
if($data['txaction'] === 'appointed'){
$shopping_order->setUserHistoryValue(['status' => 7]);
Shop::userOrders();
}
if($data['txaction'] === 'paid'){
$shopping_order->setUserHistoryValue(['status' => 8]);
Shop::userOrders();
$shopping_order->paid = true;
$shopping_order->save();
@ -150,7 +153,6 @@ class PayoneController extends Controller
if($user->payment_account && $user->daysActiveAccount()>0){
$date = \Carbon::parse($user->payment_account)->modify('1 year');
}
foreach ($shopping_order_item->product->action as $do){
if($shopping_order_item->product->getActionName($do) === 'payment_for_account'){
$user->payment_order_id = $shopping_order_item->product->id; //34
@ -183,9 +185,8 @@ class PayoneController extends Controller
}
}
}
$bcc = [];
$billing_email = $shopping_order->shopping_user->billing_email;
$user_shop_email = $shopping_order->user_shop->user->email;
if(!$billing_email){
if($data['mode'] === 'test'){
$billing_email = config('app.checkout_test_mail');
@ -194,17 +195,15 @@ class PayoneController extends Controller
}
}
if($data['mode'] === 'test'){
$checkout_mail = config('app.checkout_test_mail');
$bcc[] = config('app.checkout_test_mail');
}else{
$checkout_mail = config('app.checkout_mail');
$bcc[] = config('app.checkout_mail');
}
if($user_shop_email){
Mail::to($billing_email)->bcc([$user_shop_email, $checkout_mail])->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment, $send_link, $data['mode']));
}else{
Mail::to($billing_email)->bcc($checkout_mail)->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment, $send_link, $data['mode']));
if(!$shopping_order->shopping_user->is_like && $shopping_order->shopping_user->member){
$bcc[] = $shopping_order->shopping_user->member->email;
}
Mail::to($billing_email)->bcc($bcc)->send(new MailCheckout($data['txaction'], $shopping_order, $shopping_payment, $send_link, $data['mode']));
print("TSOK");
exit;
}

View 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);
}
}

View file

@ -15,7 +15,7 @@ class DataTableController extends Controller
public function getUsers()
{
$query = User::with('account')->where('users.deleted_at', '=', null);
$query = User::with('account')->select('users.*')->where('users.deleted_at', '=', null);
return \DataTables::eloquent($query)
->addColumn('first_name', function (User $user) {

View file

@ -81,8 +81,8 @@ class LeadController extends Controller
{
$m_data_load = false;
$m_data_error = false;
$data = Input::all();
if(!isset($data['edit_m_data_key']) && $data['edit_m_data_key'] !== config('mivita.edit_data_pass')){
$data = Request::all();
if(!isset($data['edit_m_data_key']) || $data['edit_m_data_key'] !== config('mivita.edit_data_pass')){
$m_data_error = "Das Passwort ist falsch.";
}else{
$m_data_load = true;
@ -340,7 +340,7 @@ class LeadController extends Controller
public function getLeads()
{
$query = User::with('account')->where('users.deleted_at', '=', null);
$query = User::with('account')->select('users.*')->where('users.deleted_at', '=', null);
return \DataTables::eloquent($query)
->addColumn('first_name', function (User $user) {

View file

@ -0,0 +1,63 @@
<?php
namespace App\Http\Controllers;
use App\Models\ShoppingOrder;
use App\Models\ShoppingUser;
use App\User;
use Request;
class ModalController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function load(){
$data = Request::all();
$ret = "";
$status = false;
if(Request::ajax()){
if($data['action'] === 'shopping-order-change-member'){
$value = ShoppingOrder::find($data['id']);
$route = route('admin_sales_customers_detail', [$value->id]);
$ret = view("admin.modal.member", compact('value', 'data', 'route'))->render();
}
if($data['action'] === 'shopping-user-change-member'){
$value = ShoppingUser::find($data['id']);
$route = route('admin_customer_edit', [$value->id]);
$ret = view("admin.modal.member", compact('value', 'data', 'route'))->render();
}
if($data['action'] === 'shopping-user-is-like-member'){
$current = ShoppingUser::find($data['id']); //current user form order
$possibles = [];
if($current->is_like){
$likes = $current->getNotice('like');
foreach ($likes as $like_id=>$number){
$possibles[] = ShoppingUser::find($like_id);
}
}
$ret = view("admin.modal.is_like_member", compact('current', 'possibles', 'data'))->render();
}
}
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
}
}
/* <button type="button" class="btn btn-sm btn-primary" data-toggle="modal"
data-target="#modals-load-content"
data-id="{{ $value->id }}"
data-model="emailTemplate"
data-action="modal-email-template"
data-url=""
data-redirect="back"
data-route="{{ route('modal_load') }}"><span class="fa fa-edit"></span></button>*/

View file

@ -25,11 +25,10 @@ class ProductController extends Controller
public function index()
{
if(Request::get('show_active_products')){
\Auth::user()->setSetting(['show_active_products' => Request::get('show_active_products')]);
set_user_attr('show_active_products', Request::get('show_active_products'));
}
if(\Auth::user()->getSetting('show_active_products') === "true"){
if(get_user_attr('show_active_products') === "true"){
$values = Product::where('active', true)->orderBy('pos', 'DESC')->orderBy('id', 'DESC')->get();
}else{
$values = Product::orderBy('pos', 'DESC')->orderBy('id', 'DESC')->get();

View file

@ -2,61 +2,68 @@
namespace App\Http\Controllers;
use App\Models\Country;
use App\Models\ShoppingOrder;
use App\Models\ShoppingUser;
use App\Models\UserShop;
use App\Services\CustomerPriority;
use App\Services\Payment;
use App\User;
use Input;
use Request;
class SalesController extends Controller
{
public function __construct()
{
public function __construct(){
$this->middleware('admin');
}
public function users()
{
public function users(){
if(Request::get('reset') === 'filter'){
return redirect(route('admin_sales_users'));
}
$data = [
//'values' => ShoppingOrder::all(),
];
return view('admin.sales.users', $data);
}
public function usersDetail()
public function usersDetail($id)
{
$data = [
// 'values' => Country::all(),
'shopping_order' => ShoppingOrder::find($id),
'isAdmin' => true,
'isView' => 'sales_user',
];
return view('admin.sales.user_detail', $data);
}
public function usersStore($id)
{
die("keine funktion");
$data = [
'shopping_order' => ShoppingOrder::find($id),
'isAdmin' => true,
];
return view('admin.sales.user_detail', $data);
}
public function usersDatatable(){
$query = ShoppingOrder::with('shopping_user', 'user_shop')->where('shopping_orders.auth_user_id', '!=', NULL);
$query = ShoppingOrder::with('shopping_user', 'user_shop')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', '!=', NULL);
return \DataTables::eloquent($query)
->addColumn('billing_firstname', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_firstname : '';
})
->addColumn('billing_lastname', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_lastname : '';
})
->addColumn('billing_email', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_email : '';
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
return '<a href="' . route('admin_sales_users_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
})
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->created_at->format("d.m.Y");
})
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
if($ShoppingOrder->mode === 'test'){
return '<span class="badge badge-pill badge-default">TEST - '.$ShoppingOrder->getFormattedTxaction().'</span>';
}
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getFormattedTxactionColor().'">'.$ShoppingOrder->getFormattedTxaction().'</span>';
return Payment::getShoppingOrderBadge($ShoppingOrder);
})
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->getFormattedTotalShipping();
@ -69,26 +76,8 @@ class SalesController extends Controller
})
->addColumn('auth_user_shop', function (ShoppingOrder $ShoppingOrder) {
$auth_user_shop = UserShop::whereUserId($ShoppingOrder->auth_user_id)->first();
return $auth_user_shop ? '<a href="'.$auth_user_shop->getSubdomain(false).'" target="_blank">'.$auth_user_shop->getSubdomain(false).'</span>' : '-';
})
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
return '<a href="' . route('admin_sales_users_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa 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>';
})
->orderColumn('confirmed', 'confirmed $1')
->orderColumn('active', 'active $1')
->orderColumn('agreement', 'agreement $1')
*/
->orderColumn('id', 'id $1')
->orderColumn('txaction', 'txaction $1')
->orderColumn('user_shop_id', 'user_shop_id $1')
@ -99,72 +88,132 @@ class SalesController extends Controller
public function customers()
{
if(Request::get('reset') === 'filter'){
set_user_attr('filter_user_shop_id', null);
set_user_attr('filter_txaction', null);
set_user_attr('filter_member_id', null);
return redirect(route('admin_sales_customers'));
}
$filter_user_shops = ShoppingOrder::join('user_shops', 'user_shop_id', '=', 'user_shops.id')->get()->pluck('slug', 'id')->unique()->toArray();
$filter_members = ShoppingOrder::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 = [
// 'values' => ShoppingOrder::all(),
'filter_user_shops' => $filter_user_shops,
'filter_members' => $filter_members,
];
return view('admin.sales.customers', $data);
}
public function customersDetail()
public function customersDetail($id)
{
$data = [
// 'values' => Country::all(),
'shopping_order' => ShoppingOrder::find($id),
'isAdmin' => true,
'isView' => 'sales_customer',
];
return view('admin.sales.customer_detail', $data);
}
public function customersStore($id)
{
$data = Request::all();
$change_member_error = false;
if($data['action']==='shopping-order-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_order = ShoppingOrder::findOrFail($data['id']);
CustomerPriority::newMemberForOrder($shopping_order, $data['change_member_id'], $data['customer_set_member_for']);
\Session()->flash('alert-save', true);
return redirect(route('admin_sales_customers_detail', [$shopping_order->id]));
}
}
if($data['action']==='shopping-user-is-like-member'){
if(!isset($data['change_member_key']) || $data['change_member_key'] !== config('mivita.edit_data_pass')){
\Session()->flash('alert-error', 'Das Passwort ist falsch.');
return redirect($data['back']);
}else{
if(!isset($data['is_like_shopping_user_id'])){
\Session()->flash('alert-error', 'Keine Änderung ausgewählt');
return redirect($data['back']);
}
$shopping_user = ShoppingUser::findOrFail($data['id']);
$set_like_shopping_user = ShoppingUser::findOrFail($data['is_like_shopping_user_id']);
$send_member_mail = isset($data['send_member_mail']) ? true : false;
//Mail send in setIsLike
CustomerPriority::setIsLike($shopping_user, $set_like_shopping_user, $send_member_mail);
\Session()->flash('alert-save', true);
return redirect($data['back']);
}
}
$data = [
'change_member_error' => $change_member_error,
'shopping_order' => ShoppingOrder::find($id),
'isAdmin' => true,
'isView' => 'sales_customer',
];
return view('admin.sales.customer_detail', $data);
}
public function customersDatatable(){
$query = ShoppingOrder::with('shopping_user')->where('shopping_orders.auth_user_id', NULL);
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('shopping_orders.auth_user_id', NULL);
set_user_attr('filter_user_shop_id', Request::get('filter_user_shop_id'));
if(Request::get('filter_user_shop_id') != ""){
$query->where('user_shop_id', '=', Request::get('filter_user_shop_id'));
}
set_user_attr('filter_txaction', Request::get('filter_txaction'));
if(Request::get('filter_txaction') != ""){
if(Request::get('filter_txaction') === 'NULL'){
$query->where('txaction', '=', NULL);
}else{
$query->where('txaction', '=', Request::get('filter_txaction'));
}
}
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'));
}
return \DataTables::eloquent($query)
->addColumn('billing_firstname', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_firstname : '';
})
->addColumn('billing_lastname', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_lastname : '';
})
->addColumn('billing_email', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_email : '';
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
return '<a href="' . route('admin_sales_customers_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
})
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->created_at->format("d.m.Y");
})
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
if($ShoppingOrder->mode === 'test'){
return '<span class="badge badge-pill badge-default">TEST - '.$ShoppingOrder->getFormattedTxaction().'</span>';
}
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getFormattedTxactionColor().'">'.$ShoppingOrder->getFormattedTxaction().'</span>';
return Payment::getShoppingOrderBadge($ShoppingOrder);
})
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->getFormattedTotalShipping();
})
->addColumn('orders', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->orders : '';
->addColumn('member_id', function (ShoppingOrder $ShoppingOrder) {
if($ShoppingOrder->member_id) {
return $ShoppingOrder->member_id ? '<a href="' . route('admin_lead_edit', [$ShoppingOrder->member_id]) . '">' . $ShoppingOrder->member->getFullName() . '</a>' : '';
}
if($ShoppingOrder->shopping_user && $ShoppingOrder->shopping_user->is_like){
return '<button type="button" class="btn btn-xs btn-outline-info" data-toggle="modal" data-target="#modals-load-content"
data-id="'.$ShoppingOrder->shopping_user->id.'"
data-action="shopping-user-is-like-member"
data-back="'.route('admin_sales_customers').'"
data-modal="modal-xl"
data-route="'.route('modal_load').'"><span class="fa fa-edit"></span> Berater zuordnen</button>';
}
return '';
})
->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
})
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
return '<a href="' . route('admin_sales_users_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa 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>';
})
->orderColumn('confirmed', 'confirmed $1')
->orderColumn('active', 'active $1')
->orderColumn('agreement', 'agreement $1')
*/
->orderColumn('id', 'id $1')
->orderColumn('id', 'id $1')
->orderColumn('txaction', 'txaction $1')
->orderColumn('user_shop_id', 'user_shop_id $1')
->rawColumns(['id', 'txaction', 'user_shop_id'])
->orderColumn('member_id', 'member_id $1')
->rawColumns(['id', 'member_id', 'txaction', 'user_shop_id'])
->make(true);
}

View file

@ -7,9 +7,13 @@ namespace App\Http\Controllers\Sys;
use App\Http\Controllers\Api\KasController;
use App\Http\Controllers\Api\KasSLLController;
use App\Http\Controllers\Controller;
use App\Mail\MailInfo;
use App\Models\ShoppingUser;
use App\Models\UserShop;
use App\Services\CustomerPriority;
use App\Services\Shop;
use Auth;
use Illuminate\Support\Facades\Mail;
use Input;
use Illuminate\Http\Request;
@ -32,9 +36,27 @@ class AdminToolsController extends Controller
dd('index');
}
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function customers()
{
$shopping_users = CustomerPriority::checkForAll();
$data = [
'values' => $shopping_users,
'text' => '',
];
return view('sys.admin.customers', $data);
}
public function customerStore()
{
$data = Input::all();
\Session()->flash('alert-save', true);
return back();
}
public function cronjobs()
{
//$user_shops = UserShop::all();
@ -48,25 +70,15 @@ class AdminToolsController extends Controller
];
return view('sys.admin.cronjobs', $data);
}
/**
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
*/
public function cronjobsStore()
{
$data = Input::all();
\Session()->flash('alert-save', true);
return back();
}
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function domainSSL()
{
$user_shops = UserShop::all();
@ -100,10 +112,6 @@ class AdminToolsController extends Controller
}
/**
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
*/
public function domainSSLStore()
{
$data = Input::all();
@ -111,10 +119,6 @@ class AdminToolsController extends Controller
return back();
}
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function shoppingOrders()
{
$shopping_users = ShoppingUser::all();
@ -125,34 +129,37 @@ class AdminToolsController extends Controller
return view('sys.admin.shopping-orders', $data);
}
/**
* @return \Illuminate\Http\RedirectResponse
*/
public function shoppingOrdersStore()
{
//first run
$data = Input::all();
$orders = [];
$shopping_users = ShoppingUser::all();
foreach ($shopping_users as $shopping_user){
if(!isset($shopping_user->shopping_order)){
$shopping_user->orders = NULL;
if($data['action'] === 'first_run'){
$shopping_users = ShoppingUser::whereHas('shopping_order', function($q) {
$q->where('txaction', 'paid')->OrWhere('txaction', 'appointed');
})->get();
}else{
if($shopping_user->shopping_order->txaction === "paid" || $shopping_user->shopping_order->txaction === "appointed") {
$orders[$shopping_user->billing_email] = isset($orders[$shopping_user->billing_email]) ? $orders[$shopping_user->billing_email] + 1 : 1;
$shopping_user->orders = $orders[$shopping_user->billing_email];
}else{
$shopping_user->orders = NULL;
$order_email = [];
$order_number = [];
foreach ($shopping_users as $shopping_user){
$order_email[$shopping_user->billing_email] = isset($order_email[$shopping_user->billing_email]) ? $order_email[$shopping_user->billing_email] + 1 : 1;
if($shopping_user->number) {
$order_number[$shopping_user->number] = isset($order_number[$shopping_user->number]) ? $order_number[$shopping_user->number] + 1 : 1;
$shopping_user->orders = $order_number[$shopping_user->number];
}else {
$shopping_user->orders = $order_email[$shopping_user->billing_email];
}
}
$shopping_user->save();
$shopping_user->save();
}
\Session()->flash('alert-save', true);
}
\Session()->flash('alert-save', true);
if($data['action'] === 'next_run'){
Shop::userOrders();
\Session()->flash('alert-save', true);
}
return back();
}

View file

@ -4,6 +4,7 @@
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use App\Models\ShoppingOrder;
use App\Services\Payment;
use App\User;
@ -22,37 +23,37 @@ class ShopSalesController extends Controller
return view('user.shop.sales.orders', $data);
}
public function orderDetail()
public function orderDetail($id)
{
$user = User::find(\Auth::user()->id);
$shopping_order = ShoppingOrder::find($id);
if(!$shopping_order){
abort(404);
}
if($shopping_order->user_shop_id !== $user->shop->id){
abort(404);
}
$data = [
// 'values' => Country::all(),
'shopping_order' => $shopping_order,
'isAdmin' => false,
];
return view('admin.sales.customer_detail', $data);
return view('user.shop.sales.order_detail', $data);
}
public function ordersDatatable(){
$user = User::find(\Auth::user()->id);
$query = ShoppingOrder::with('shopping_user')->where('user_shop_id', $user->shop->id);
$query = ShoppingOrder::with('shopping_user')->select('shopping_orders.*')->where('user_shop_id', $user->shop->id);
return \DataTables::eloquent($query)
->addColumn('billing_firstname', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_firstname : '';
})
->addColumn('billing_lastname', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_lastname : '';
})
->addColumn('billing_email', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->shopping_user ? $ShoppingOrder->shopping_user->billing_email : '';
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
return '<a href="' . route('user_shop_order_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
})
->addColumn('created_at', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->created_at->format("d.m.Y");
})
->addColumn('txaction', function (ShoppingOrder $ShoppingOrder) {
if($ShoppingOrder->mode === 'test'){
return '<span class="badge badge-pill badge-default">TEST - '.$ShoppingOrder->getFormattedTxaction().'</span>';
}
return '<span class="badge badge-pill badge-'.$ShoppingOrder->getFormattedTxactionColor().'">'.$ShoppingOrder->getFormattedTxaction().'</span>';
return Payment::getShoppingOrderBadge($ShoppingOrder);
})
->addColumn('total_shipping', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->getFormattedTotalShipping();
@ -63,22 +64,7 @@ class ShopSalesController extends Controller
->addColumn('user_shop_id', function (ShoppingOrder $ShoppingOrder) {
return $ShoppingOrder->user_shop ? '<a href="'.$ShoppingOrder->user_shop->getSubdomain(false).'" target="_blank">'.$ShoppingOrder->user_shop->getSubdomain(false).'</span>' : '';
})
->addColumn('id', function (ShoppingOrder $ShoppingOrder) {
return '<a href="' . route('admin_sales_users_detail', [$ShoppingOrder->id]) . '" class="btn icon-btn btn-sm btn-primary"><span class="fa 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>';
})
->orderColumn('confirmed', 'confirmed $1')
->orderColumn('active', 'active $1')
->orderColumn('agreement', 'agreement $1')
*/
->orderColumn('id', 'id $1')
->orderColumn('txaction', 'txaction $1')
->orderColumn('user_shop_id', 'user_shop_id $1')

View file

@ -11,7 +11,7 @@ class TeamController extends Controller
public function __construct()
{
$this->middleware('active.shop');
$this->middleware('active.account');
}
public function members()

View file

@ -10,6 +10,7 @@ use App\Models\ShoppingOrder;
use App\Models\ShoppingOrderItem;
use App\Models\ShoppingPayment;
use App\Models\ShoppingUser;
use App\Services\CustomerPriority;
use App\User;
use Illuminate\Session\SessionManager;
use Illuminate\Support\Collection;
@ -310,6 +311,8 @@ class CheckoutController extends Controller
if(!$shopping_user){
$shopping_user = ShoppingUser::create($data);
}
//CustomerPriority
CustomerPriority::checkOne($shopping_user, true);
$this->putPayments('shopping_user_id', $shopping_user->id);
return $shopping_user;

View file

@ -52,10 +52,6 @@ class MailCheckout extends Mailable
//make Adresse
}
if($this->txaction === 'paid'){
if($this->send_link){
}
return $this->view('emails.checkout')->with([
'salutation' => $salutation,
'copy1line' => __('email.checkout_copy1line'),

View file

@ -16,46 +16,66 @@ class MailInfo extends Mailable
public $subject;
public function __construct(User $user, $action)
public function __construct($user, $action)
{
$this->user = $user;
$this->action = $action;
if($action === "delete_membership"){
if($this->action === "delete_membership"){
$this->subject = 'Mitgliedschaft beenden - beantragt';
}
if($this->action === "check_is_like_customer"){
$this->subject = 'Kunden überprüfen - Kundenhoheit';
}
}
public function build()
{
$content = __(strtoupper($this->user->account->salutation))." ";
$content .= $this->user->account->first_name." ".$this->user->account->last_name."\n";
$content .= $this->user->account->address."\n";
$content .= $this->user->account->zipcode." ".$this->user->account->city."\n";
$content .= $this->user->account->country_id ? $this->user->account->country->de."\n\n" : "\n\n";
if($this->user->account->phone){
$content .= "Telefon: ";
$content .= $this->user->account->pre_phone_id ? $this->user->account->pre_phone->phone." " : " ";
$content .= $this->user->account->phone;
}
if($this->user->account->mobil){
$content .= "Mobil: ";
$content .= $this->user->account->pre_mobil_id ? $this->user->account->pre_mobil->phone." " : " ";
$content .= $this->user->account->mobil;
}
$content .= "E-Mail: ".$this->user->email;
$content = "";
if($this->action === "delete_membership"){
$content .= __(strtoupper($this->user->account->salutation))." ";
$content .= $this->user->account->first_name." ".$this->user->account->last_name."\n";
$content .= $this->user->account->address."\n";
$content .= $this->user->account->zipcode." ".$this->user->account->city."\n";
$content .= $this->user->account->country_id ? $this->user->account->country->de."\n\n" : "\n\n";
if($this->user->account->phone){
$content .= "Telefon: ";
$content .= $this->user->account->pre_phone_id ? $this->user->account->pre_phone->phone." " : " ";
$content .= $this->user->account->phone;
}
if($this->user->account->mobil){
$content .= "Mobil: ";
$content .= $this->user->account->pre_mobil_id ? $this->user->account->pre_mobil->phone." " : " ";
$content .= $this->user->account->mobil;
}
$content .= "E-Mail: ".$this->user->email;
$copy1line = "Infos zum Berater:"."\n";
$button = "zum Berater";
$title = "Ein Berater möchte seine Mitgliedschaft beenden.";
$url = route('admin_lead_edit', $this->user->id).'?show=check_lead';
}
if($this->action === "check_is_like_customer") {
$copy1line = "Hier geht es zum Kunden:"."\n";
$button = "zum Kunden";
$title = "Ein Kunden muss überprüfen werden und einem Berater zugeordnet werden, da die Adresse nicht eindeutig ist.";
$url = route('admin_customer_edit', $this->user->id);
$content .= $this->user ? 'Firma: '.$this->user->billing_company."\n" : '';
$content .= \App\Services\HTMLHelper::getSalutationLang($this->user->billing_salutation)." ";
$content .= $this->user->billing_firstname." ";
$content .= $this->user->billing_lastname."\n";
$content .= $this->user->billing_address;
$content .= $this->user->billing_address_2 ? '/ '.$this->user->billing_address_2."\n" : "\n";
$content .= $this->user->billing_zipcode." ";
$content .= $this->user->billing_city."\n";
$content .= $this->user->billing_email."\n";
$content .= $this->user->billing_phone."\n";
$content .= $this->user->billing_country->getLocated();
}
return $this->view('emails.info')->with([
'url' => route('admin_lead_edit', $this->user->id).'?show=check_lead',
'url' => $url,
'title' => $title,
'button' => $button,
'copy1line' => $copy1line,

View file

@ -61,6 +61,7 @@ class ShoppingOrder extends Model
protected $fillable = [
'shopping_user_id',
'auth_user_id',
'member_id',
'country_id',
'user_shop_id',
'total',
@ -73,18 +74,6 @@ class ShoppingOrder extends Model
'mode',
];
protected $txaction_text = [
'paid' => "bezahlt",
'appointed' => "offen",
'failed' => "abbruch",
];
protected $txaction_color = [
'paid' => "success",
'appointed' => "warning",
'failed' => "danger",
];
public function shopping_user()
{
@ -101,6 +90,11 @@ class ShoppingOrder extends Model
return $this->belongsTo('App\Models\UserShop','user_shop_id');
}
//can null
public function member()
{
return $this->belongsTo('App\User','member_id');
}
//can null
public function auth_user()
{
@ -162,18 +156,15 @@ class ShoppingOrder extends Model
}
public function getFormattedTxaction(){
if($this->txaction && isset($this->txaction_text[$this->txaction])){
return $this->txaction_text[$this->txaction];
public function getItemsCount(){
$count = 0;
if($this->shopping_order_items){
foreach ($this->shopping_order_items as $shopping_order_item){
$count += $shopping_order_item->qty;
}
}
return "not";
}
public function getFormattedTxactionColor(){
if($this->txaction && isset($this->txaction_color[$this->txaction])){
return $this->txaction_color[$this->txaction];
}
return "danger";
return $count;
}

View file

@ -2,6 +2,7 @@
namespace App\Models;
use App\Services\Util;
use Illuminate\Database\Eloquent\Model;
/**
@ -88,4 +89,7 @@ class ShoppingPayment extends Model
}
}
public function getPaymentAmount(){
return Util::formatNumber($this->amount/100)." ".$this->currency;
}
}

View file

@ -80,7 +80,13 @@ class ShoppingUser extends Model
{
protected $table = 'shopping_users';
protected $fillable = [
'auth_user_id',
'member_id',
'number',
'is_like',
'billing_salutation',
'billing_company',
'billing_firstname',
@ -104,10 +110,25 @@ class ShoppingUser extends Model
'shipping_city',
'shipping_country_id',
'shipping_phone',
'notice',
];
protected $casts = [
'notice' => 'array',
'is_like' => 'bool',
'accepted_data_checkbox' => 'bool',
'same_as_billing' => 'bool',
];
//can null
public function member()
{
return $this->belongsTo('App\User','member_id');
}
public function auth_user()
{
return $this->belongsTo('App\User','auth_user_id');
}
public function billing_country()
{
return $this->belongsTo('App\Models\Country','billing_country_id');
@ -128,4 +149,23 @@ class ShoppingUser extends Model
return $this->hasOne('App\Models\ShoppingOrder','shopping_user_id');
}
public function setNotice($key, $value){
$notice = $this->notice;
$notice[$key] = $value;
$this->notice = $notice;
$this->save();
}
public function getNotice($key){
return isset($this->notice[$key]) ? $this->notice[$key] : false;
}
public function removeNotice($key){
$notice = $this->notice;
if(isset($notice[$key])){
unset($notice[$key]);
}
$this->notice = $notice;
$this->save();
}
}

View file

@ -129,7 +129,6 @@ class UserAccount extends Model
protected $casts = [
'payment_data' => 'array',
'notice' => 'array',
];
use SoftDeletes;

View file

@ -0,0 +1,71 @@
<?php
namespace App\Repositories;
class CustomerRepository extends BaseRepository {
public function __construct()
{
//$this->model = $model;
}
public function update($data)
{
/*if($data['user_id'] === "new" || $data['user_id'] == 0){
$this->model = User::create([
'email' => $data['email'],
'password' => env('APP_KEY'),
]);
}
else{
$this->model = $this->getById($data['user_id']);
}
if(!$this->model->account_id){
$account = new UserAccount();
}else{
$account = $this->model->account;
}
$data['same_as_billing'] = !isset($data['same_as_billing']) ? 0 : 1;
$account->fill($data)->save();
if(!$this->model->account_id){
$this->model->account_id = $account->id;
$this->model->save();
}*/
return true;
}
public function create($data){
/* $this->model = User::create([
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$account = UserAccount::create([
'm_salutation' => $data['salutation'],
'm_first_name' => $data['first_name'],
'm_last_name' => $data['last_name'],
'salutation' => $data['salutation'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
]);
$this->model->account_id = $account->id;
$this->model->save();
return $this->model;*/
}
}

View file

@ -0,0 +1,201 @@
<?php
namespace App\Services;
use App\Mail\MailCheckout;
use App\Mail\MailInfo;
use App\Models\ShoppingUser;
use App\Services\Shop;
use App\User;
use Auth;
use Illuminate\Support\Facades\Mail;
class CustomerPriority
{
protected static $start_number = 1000;
protected static $user_notice_key = 'like';
public static function checkForAll(){
//only extern no members with no numbers
$shopping_users = ShoppingUser::where('auth_user_id', '=', NULL)->where('number', '=', NULL)->orderBy('created_at', 'ASC')->get();
foreach ($shopping_users as $shopping_user){
if($shopping_user->shopping_order && $shopping_user->shopping_order->user_shop){
self::checkOne($shopping_user);
}
}
return $shopping_users;
}
public static function checkOne($shopping_user, $mail=false){
//look for entry
if(self::entryExists($shopping_user)){
return 'exists';
}
if(self::entryLike($shopping_user)){
if($mail){ //send mail
Mail::to(config('app.info_mail'))->send(new MailInfo($shopping_user, 'check_is_like_customer'));
}
return 'like';
}
self::newCustomer($shopping_user);
return 'update';
}
public static function setIsLike($shopping_user, $set_like_shopping_user, $send_member_mail)
{
if ($shopping_user->id === $set_like_shopping_user->id) {
//set new customer for shopping_user
self::newCustomer($shopping_user);
} else {
//set existing customer for shopping_user
self::existingCustomer($shopping_user, $set_like_shopping_user);
}
self::clearIsLike($shopping_user);
//SEND MAIL TO MEMBER
if ($send_member_mail){
if ($shopping_user->shopping_order && $shopping_user->shopping_order->shopping_payments) {
Mail::to($shopping_user->member->email)->send(new MailCheckout($shopping_user->shopping_order->txaction, $shopping_user->shopping_order, $shopping_user->shopping_order->shopping_payments->last(), false, $shopping_user->shopping_order->mode));
}
}
return true;
}
public static function newMemberForOrder($shopping_order, $member_id, Bool $all = false){
if($all){
if($shopping_order->shopping_user && $shopping_order->shopping_user->number){
$shopping_users = ShoppingUser::where('number', '=', $shopping_order->shopping_user->number)->get();
$new_number = self::nextNumber();
foreach ($shopping_users as $shopping_user) {
self::changeCustomer($shopping_user, $member_id, $new_number);
}
}
}else{
$shopping_order->member_id = $member_id;
$shopping_order->save();
if($shopping_order->shopping_user){
$shopping_order->shopping_user->member_id = $member_id;
$shopping_order->shopping_user->number = self::nextNumber();
$shopping_order->shopping_user->save();
}
}
}
public static function newMemberForCustomer($shopping_user, $member_id, Bool $all = false){
if($all){
if($shopping_user && $shopping_user->number){
$shopping_users = ShoppingUser::where('number', '=', $shopping_user->number)->get();
$new_number = self::nextNumber();
foreach ($shopping_users as $s_user) {
self::changeCustomer($s_user, $member_id, $new_number);
}
}
}else{
$shopping_user->member_id = $member_id;
$shopping_user->number = self::nextNumber();
$shopping_user->save();
if($shopping_user->shopping_order){
$shopping_user->shopping_order->member_id = $member_id;
$shopping_user->shopping_order->save();
}
}
}
private static function entryExists($shopping_user){
//check same email
$matches = ShoppingUser::where('auth_user_id', '=', NULL)
->where('number', '!=', NULL) //has number
->where('id', '!=', $shopping_user->id)
->where('billing_email', '=', $shopping_user->billing_email)->get();
if($matches && count($matches)){
$match = $matches->last();
$shopping_user->member_id = $match->member_id;
$shopping_user->number = $match->number;
$shopping_user->save();
//has order
if($shopping_user->shopping_order){
$shopping_user->shopping_order->member_id = $match->member_id;
$shopping_user->shopping_order->save();
}
return true;
}
return false;
}
private static function entryLike($shopping_user){
//check same last name und PLZ
$matches = ShoppingUser::select('*')
->where('auth_user_id', '=', NULL)
->where('number', '!=', NULL) //has number
->where('id', '!=', $shopping_user->id)
->where('billing_lastname', '=', $shopping_user->billing_lastname)
->where('billing_zipcode', '=', $shopping_user->billing_zipcode)
->get()->pluck('number', 'id')->unique()->toArray();
if($matches && count($matches)){
$shopping_user->is_like = true;
$shopping_user->setNotice(self::$user_notice_key, $matches);
$shopping_user->save();
return true;
}
return false;
}
private static function newCustomer($shopping_user){
if($shopping_user->shopping_order && $shopping_user->shopping_order->user_shop) {
$member_id = $shopping_user->shopping_order->user_shop->user_id;
$shopping_user->member_id = $member_id;
$shopping_user->number = self::nextNumber();
$shopping_user->save();
$shopping_user->shopping_order->member_id = $member_id;
$shopping_user->shopping_order->save();
}
}
private static function changeCustomer($shopping_user, $member_id, $number){
$old_number = $shopping_user->number;
$shopping_user->member_id = $member_id;
$shopping_user->number = $number;
$shopping_user->save();
if($shopping_user->shopping_order) {
$shopping_user->shopping_order->member_id = $member_id;
$shopping_user->shopping_order->save();
}
\App\Services\Shop::newUserOrder($old_number);
\App\Services\Shop::newUserOrder($number);
}
private static function existingCustomer($shopping_user, $set_like_shopping_user){
$old_number = $shopping_user->number;
$shopping_user->member_id = $set_like_shopping_user->member_id;
$shopping_user->number = $set_like_shopping_user->number;
$shopping_user->save();
if($shopping_user->shopping_order) {
$shopping_user->shopping_order->member_id = $set_like_shopping_user->member_id;
$shopping_user->shopping_order->save();
}
\App\Services\Shop::newUserOrder($old_number);
\App\Services\Shop::newUserOrder($set_like_shopping_user->number);
}
private static function clearIsLike($shopping_user){
$shopping_user->is_like = false;
$shopping_user->removeNotice(self::$user_notice_key);
$shopping_user->save();
}
private static function nextNumber (){
if(!$number = ShoppingUser::max('number')){
$number = self::$start_number;
}
return $number+1;
}
}

View file

@ -282,8 +282,8 @@ class HTMLHelper
return $ret;
}
public static function getSponsorOptions($id, $all=false){
$values = User::all();
public static function getMembersOptions($id, $all=false){
$values = User::where('active', '=', true)->where('blocked', '=', false)->where('payment_account', '>=', now())->get();
$ret = "";
if($all){
$ret .= '<option value="">'.__('please select').'</option>\n';
@ -294,36 +294,9 @@ class HTMLHelper
if($value->account){
$to = $value->account->first_name." ".$value->account->last_name." | ";
}
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$to.$value->email.'</option>\n';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$to.$value->email.' #'.$value->number.'</option>\n';
}
return $ret;
}
/*public static function getIndustrySectorsWithoutParents($id = false, $sameId = false, $all = true){
$values = IndustrySector::where('parent_id', null)->get();
$ret = "";
if($all){
$ret .= '<option value="">'.__('no').'</option>\n';
}
foreach ($values as $value){
if($sameId == $value->id){
continue;
}
$attr = ($value->id == $id) ? 'selected="selected"' : '';
$ret .= '<option value="'.$value->id.'" '.$attr.'>'.$value->name.'</option>\n';
}
return $ret;
}
*/
}

55
app/Services/Payment.php Normal file
View file

@ -0,0 +1,55 @@
<?php
namespace App\Services;
use App\Models\ShoppingOrder;
use App\Models\ShoppingPayment;
use App\User;
class Payment
{
public static $txaction_text = [
'paid' => "bezahlt",
'appointed' => "offen",
'failed' => "abbruch",
'NULL' => 'keine Zahlung',
];
public static $txaction_color = [
'paid' => "success",
'appointed' => "warning",
'failed' => "danger",
];
public static function getFormattedTxaction($txaction){
if($txaction && isset(self::$txaction_text[$txaction])){
return self::$txaction_text[$txaction];
}
return self::$txaction_text['NULL'];
}
public static function getFormattedTxactionColor($txaction){
if($txaction && isset(self::$txaction_color[$txaction])){
return self::$txaction_color[$txaction];
}
return "warning";
}
public static function getShoppingOrderBadge(ShoppingOrder $shopping_order){
if($shopping_order->mode === 'test'){
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_order->mode).' - '.self::getFormattedTxaction($shopping_order->txaction).'</span>';
}
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_order->txaction).'">'.self::getFormattedTxaction($shopping_order->txaction).'</span>';
}
public static function getShoppingPaymentBadge(ShoppingPayment $shopping_payment){
if($shopping_payment->mode === 'test'){
return '<span class="badge badge-pill badge-default">'.strtoupper($shopping_payment->mode).' - '.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
}
return '<span class="badge badge-pill badge-'.self::getFormattedTxactionColor($shopping_payment->txaction).'">'.self::getFormattedTxaction($shopping_payment->txaction).'</span>';
}
}

40
app/Services/Shop.php Normal file
View file

@ -0,0 +1,40 @@
<?php
namespace App\Services;
use App\Models\ShoppingUser;
class Shop
{
public static function userOrders() {
$shopping_users = ShoppingUser::whereHas('shopping_order', function($q) {
$q->where('txaction', 'paid')->OrWhere('txaction', 'appointed');
})->where('orders', '=', NULL)->get();
foreach ($shopping_users as $shopping_user) {
if ($shopping_user->number) {
$orders = ShoppingUser::where('number', '=', $shopping_user->number)->max('orders');
$orders = $orders + 1;
} else {
$orders = ShoppingUser::where('billing_email', '=', $shopping_user->billing_email)->max('orders');
$orders = $orders + 1;
}
$shopping_user->orders = $orders;
$shopping_user->save();
}
}
public static function newUserOrder($number){
$shopping_users = ShoppingUser::where('number', '=', $number)->get();
$orders = 1;
foreach ($shopping_users as $shopping_user) {
if($shopping_user->shopping_order && ($shopping_user->shopping_order->txaction === 'paid' || $shopping_user->shopping_order->txaction === 'appointed')){
$shopping_user->orders = $orders++;
}else{
$shopping_user->orders = NULL;
}
$shopping_user->save();
}
}
}

View file

@ -6,7 +6,6 @@ use App\User;
class UserService
{
public static function createConfirmationCode() {
$unique = false;
do{

View file

@ -167,18 +167,38 @@ class User extends Authenticatable
return $this->hasOne('App\Models\UserShop', 'user_id', 'id');
}
public function user_update_email()
{
return $this->hasMany('App\Models\UserUpdateEmail', 'user_id', 'id');
}
public function member_shopping_orders()
{
return $this->hasMany('App\Models\ShoppingOrder', 'member_id', 'id');
}
public function member_shopping_users()
{
return $this->hasMany('App\Models\ShoppingUser', 'member_id', 'id');
}
public function getMUserSponsor(){
if($this->user_sponsor && $this->user_sponsor->account){
return $this->user_sponsor->account->first_name." ".$this->user_sponsor->account->last_name." | ".$this->user_sponsor->email;
}
}
public function getFullName($email=true){
$ret = "";
if($this->account){
$ret = $this->account->first_name." ".$this->account->last_name;
}
if($email && $this->id > 1){
$ret .= " | ".$this->email;
}
return $ret;
}
/**
* @return bool
*/
@ -259,8 +279,7 @@ class User extends Authenticatable
return $this->payment_shop ? Carbon::parse($this->payment_shop)->gt(Carbon::now()) : false;
}
public function isRenewalAccount()
{
public function isRenewalAccount(){
if ($this->payment_account) {
return Carbon::parse($this->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days')->lt(Carbon::now());
}

View file

@ -14,3 +14,31 @@ if (! function_exists('make_old_url')) {
return config('app.old_url').$path;
}
}
if (! function_exists('get_file_last_time')) {
function get_file_last_time($value)
{
if (file_exists($value)) {
return filemtime($value);
}
return date("Ymd-i", time());
}
}
if (! function_exists('get_user_attr')) {
function get_user_attr($key){
if ($user = Auth::user()) {
return $user->getSetting($key);
}
return null;
}
}
if (! function_exists('set_user_attr')) {
function set_user_attr($key, $value){
if ($user = Auth::user()) {
return $user->setSetting([$key => $value]);
}
return null;
}
}