165 lines
No EOL
6.4 KiB
PHP
Executable file
165 lines
No EOL
6.4 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Mail\MailInfo;
|
|
use App\Models\Product;
|
|
use App\Models\ShoppingInstance;
|
|
use App\Models\UserHistory;
|
|
use App\User;
|
|
use Auth;
|
|
use Carbon;
|
|
use Config;
|
|
use Illuminate\Validation\Rules\In;
|
|
use Request;
|
|
use Input;
|
|
use Util;
|
|
use Yard;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
|
class MembershipController extends Controller
|
|
{
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
|
|
public function index()
|
|
{
|
|
$user = User::find(Auth::user()->id);
|
|
$diff_months = 0;
|
|
|
|
if($user->payment_account){
|
|
$diff_months = Carbon::now()->diffInMonths(Carbon::parse($user->payment_account)) +1;
|
|
}
|
|
|
|
$userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_order')->get()->last();
|
|
$userHistoryUpgradeOrder = UserHistory::whereUserId($user->id)->whereAction('upgrade_order')->get()->last();
|
|
$userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last();
|
|
|
|
|
|
$data = [
|
|
'user' => $user,
|
|
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
|
|
'upgrade' => Product::where('active', true)->where('show_at', '=', 4)->where('identifier', 'upgrade')->get(),
|
|
'diff_months' => $diff_months,
|
|
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
|
|
'userHistoryUpgradeOrder' => $userHistoryUpgradeOrder,
|
|
'userHistoryDeleteMembership' => $userHistoryDeleteMembership,
|
|
];
|
|
return view('user.membership.index', $data);
|
|
|
|
}
|
|
|
|
|
|
public function storePayment($action){
|
|
|
|
|
|
$data = Input::all();
|
|
|
|
//#### remove_abo
|
|
if($action === "remove_abo"){
|
|
if(Input::get('abo_options_remove')){
|
|
$user = User::find(Auth::user()->id);
|
|
$user->abo_options = false;
|
|
$user->save();
|
|
$user->account->payment_data = null;
|
|
$user->account->save();
|
|
UserHistory::create(['user_id' => $user->id, 'action'=>'abo_options_remove', 'status'=>10]);
|
|
\Session()->flash('alert-success', "Abo-Option deaktiviert");
|
|
return back();
|
|
}
|
|
\Session()->flash('alert-error', "Fehler, Checkbox nicht bestätigt.");
|
|
return back();
|
|
}
|
|
//#### payment order
|
|
//#### shop upgrade
|
|
if($action === "upgrade_order" || $action === "payment_order"){
|
|
if(Input::get('switchers-package-wizard')){
|
|
$user = User::find(Auth::user()->id);
|
|
Yard::instance('shopping')->destroy();
|
|
$product = Product::find(Input::get('switchers-package-wizard'));
|
|
$showAboOptions = false;
|
|
if(Input::get('abo_options')){
|
|
$showAboOptions = true;
|
|
$user->abo_options = true;
|
|
$user->save();
|
|
}
|
|
if($product && $product->active && $product->show_at >= 3){
|
|
$image = "";
|
|
if($product->images->count()){
|
|
$image = $product->images->first()->slug;
|
|
}
|
|
$qty = Input::get('qty') ? Input::get('qty') : 1;
|
|
Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
|
|
|
|
do {
|
|
$identifier = Util::getToken();
|
|
} while( ShoppingInstance::where('identifier', $identifier)->count() );
|
|
|
|
ShoppingInstance::create([
|
|
'identifier' => $identifier,
|
|
'user_shop_id' => 1, //is first faker shop for nuy intern
|
|
'auth_user_id' => Auth::user()->id,
|
|
'payment' => 3, //Berater Membership
|
|
'subdomain' => url('/'),
|
|
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
|
|
|
|
]);
|
|
Yard::instance('shopping')->store($identifier);
|
|
//add to DB
|
|
$path = route('checkout.checkout_card', ['identifier'=>$identifier]);
|
|
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>1, 'product_id'=>$product->id, 'identifier'=>$identifier, 'abo_options'=>$showAboOptions]);
|
|
//$path = str_replace('http', 'https', $path);
|
|
return redirect()->secure($path);
|
|
}
|
|
}
|
|
}
|
|
|
|
if($action === "change_order"){
|
|
if(Input::get('switchers-package-wizard')){
|
|
$user = User::find(Auth::user()->id);
|
|
$product = Product::find(Input::get('switchers-package-wizard'));
|
|
if($user->payment_order_id == $product->id){
|
|
\Session()->flash('alert-success', "keine Änderung vorgenommen.");
|
|
return back();
|
|
}
|
|
if($product && $product->active && $product->show_at >= 3){
|
|
$user->payment_order_id = $product->id;
|
|
$user->save();
|
|
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>10, 'product_id'=>$product->id]);
|
|
\Session()->flash('alert-success', "gebuchtes Paket wurde geändert.");
|
|
return back();
|
|
|
|
}
|
|
}
|
|
}
|
|
if($action === "delete_membership"){
|
|
if(Input::get('delete_membership_mivita')){
|
|
//TODO
|
|
$user = User::find(Auth::user()->id);
|
|
if($user->isTestMode()){
|
|
$mail = config('app.info_test_mail');
|
|
}else{
|
|
$mail = config('app.info_mail');
|
|
}
|
|
Mail::to($mail)->send(new MailInfo($user, 'delete_membership'));
|
|
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>50]);
|
|
\Session()->flash('alert-success', "Mitgliedschaft beenden ist beantragt");
|
|
return back();
|
|
}
|
|
\Session()->flash('alert-error', "Fehler, Checkbox nicht bestätigt.");
|
|
return back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |