20-02-2026

This commit is contained in:
Kevin Adametz 2026-02-20 17:55:06 +01:00
parent a8b395e20d
commit a00c42e770
252 changed files with 28785 additions and 8907 deletions

View file

@ -2,23 +2,22 @@
namespace App\Http\Controllers\User;
use Auth;
use Util;
use Yard;
use Carbon;
use Request;
use App\User;
use App\Http\Controllers\Controller;
use App\Mail\MailInfo;
use App\Models\Product;
use App\Services\Payment;
use App\Models\UserHistory;
use App\Models\ShoppingOrder;
use App\Services\UserService;
use App\Models\ShippingCountry;
use App\Models\ShoppingInstance;
use App\Http\Controllers\Controller;
use App\Models\ShoppingOrder;
use App\Models\UserHistory;
use App\Services\Payment;
use App\Services\UserService;
use App\User;
use Auth;
use Carbon;
use Illuminate\Support\Facades\Mail;
use Request;
use Util;
use Yard;
class MembershipController extends Controller
{
@ -32,19 +31,18 @@ class MembershipController extends Controller
$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;
if ($user->payment_account) {
$diff_months = Carbon::now()->diffInMonths(Carbon::parse($user->payment_account)) + 1;
}
$userShoppingOrders = ShoppingOrder::with('shopping_user', 'shopping_payments')->select('shopping_orders.*')
->where('auth_user_id', '=', $user->id)
->where('txaction', '!=', NULL)
->where('txaction', '!=', null)
->whereIn('payment_for', [1, 2])
->orderBy('created_at', 'DESC')
->get();
@ -52,34 +50,33 @@ class MembershipController extends Controller
$userHistoryPaymentOrder = null;
$userHistoryUpgradeOrder = null;
/* Bezhalung ist nur 29 Tage vor ablauf möglich */
/* Bezhalung ist nur 29 Tage vor ablauf möglich */
/* isRenewalAccount payment_account date - config('mivita.renewal_days') Vertragsverlängerung */
if($user->isRenewalAccount()){
//Acount ist noch nicht verlängert / bezahlt
if ($user->isRenewalAccount()) {
// Acount ist noch nicht verlängert / bezahlt
if ($user->payment_account) {
//Die Order muss größer als das Datum sein.
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
// Die Order muss größer als das Datum sein.
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days') + 1).' days');
$userHistoryPaymentOrder = UserHistory::whereUserId($user->id)->whereAction('payment_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
}
}
if($user->isActiveAccount() && !$user->isActiveShop()){
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days')+1).' days');
if ($user->isActiveAccount() && ! $user->isActiveShop()) {
$payment_greaterThan = Carbon::parse($user->payment_account)->modify('-'.(config('mivita.renewal_days') + 1).' days');
$userHistoryUpgradeOrder = UserHistory::whereUserId($user->id)->whereAction('upgrade_order')->where('created_at', '>=', $payment_greaterThan)->get()->last();
}
$userHistoryDeleteMembership = UserHistory::whereUserId($user->id)->whereAction('delete_membership')->whereStatus(50)->get()->last();
$shipping_country_id = $this->checkShoppingCountry($user);
if(!$shipping_country_id){
if (! $shipping_country_id) {
abort(403, __('validation.custom.shipping_not_found'));
}
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
$data = [
'user' => $user,
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['7', '8'])->orderBy('pos', 'ASC')->get(),
'upgrade' => Product::where('active', true)->whereJsonContains('show_on', '8')->where('identifier', 'upgrade')->get(),
'diff_months' => $diff_months,
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
@ -88,86 +85,90 @@ class MembershipController extends Controller
'yard_info' => UserService::getYardInfo(),
'userShoppingOrders' => $userShoppingOrders,
];
return view('user.membership.index', $data);
}
private function checkShoppingCountry($user ){
private function checkShoppingCountry($user)
{
$country_id = null;
if($user->account->same_as_billing){
if ($user->account->same_as_billing) {
$country_id = $user->account->country_id;
}else{
} else {
$country_id = $user->account->shipping_country_id;
}
if($country_id){
if($shipping_country = ShippingCountry::whereCountryId($country_id)->first()){
if ($country_id) {
if ($shipping_country = ShippingCountry::whereCountryId($country_id)->first()) {
return $shipping_country->id;
}
}
return false;
}
public function storePayment($action){
public function storePayment($action)
{
$data = Request::all();
//#### remove_abo
if($action === "remove_abo"){
if(Request::get('abo_options_remove')){
// #### remove_abo
if ($action === 'remove_abo') {
if (Request::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]);
UserHistory::create(['user_id' => $user->id, 'action' => 'abo_options_remove', 'status' => 10]);
\Session()->flash('alert-success', __('msg.abo_deaktivert'));
return back();
}
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
return back();
}
//#### payment order
//#### shop upgrade
if($action === "upgrade_order" || $action === "payment_order"){
if(Request::get('switchers-package-wizard')){
// #### payment order
// #### shop upgrade
if ($action === 'upgrade_order' || $action === 'payment_order') {
if (Request::get('switchers-package-wizard')) {
$user = User::find(Auth::user()->id);
Yard::instance('shopping')->destroy();
$product = Product::find(Request::get('switchers-package-wizard'));
$showAboOptions = false;
if(Request::get('abo_options')){
$showAboOptions = false; //true Abo Option deaktivert
$user->abo_options = false; //true Abo Option deaktivert
if (Request::get('abo_options')) {
$showAboOptions = false; // true Abo Option deaktivert
$user->abo_options = false; // true Abo Option deaktivert
$user->save();
}
$shipping_country_id = $this->checkShoppingCountry($user);
if(!$shipping_country_id){
if (! $shipping_country_id) {
abort(403, __('validation.custom.shipping_not_found'));
}
UserService::checkUserTaxShippingCountry($user, $shipping_country_id);
Yard::instance('shopping')->setUserPriceInfos(UserService::getYardInfo());
Yard::instance('shopping')->setShippingCountryWithPrice($shipping_country_id);
if($product && $product->active){
$image = "";
if($product->images->count()){
if ($product && $product->active) {
$image = '';
if ($product->images->count()) {
$image = $product->images->first()->slug;
}
$qty = Request::get('qty') ? Request::get('qty') : 1;
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'show_on' => $product->show_on]);
if(\App\Services\UserService::getTaxFree()){
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $qty, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'show_on' => $product->show_on]);
if (\App\Services\UserService::getTaxFree()) {
Yard::setTax($cartItem->rowId, 0);
}else{
} else {
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
}
do {
$identifier = Util::getToken();
} while( ShoppingInstance::where('identifier', $identifier)->count() );
} while (ShoppingInstance::where('identifier', $identifier)->count());
$data = [];
$data['is_from'] = 'membership';
@ -176,9 +177,9 @@ class MembershipController extends Controller
ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => 1, //is first faker shop for nuy intern
'user_shop_id' => 1, // is first faker shop for nuy intern
'auth_user_id' => Auth::user()->id,
'payment' => 3, //Berater Membership
'payment' => 3, // Berater Membership
'subdomain' => url('/'),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
@ -187,54 +188,59 @@ class MembershipController extends Controller
]);
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);
// 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(Request::get('switchers-package-wizard')){
if ($action === 'change_order') {
if (Request::get('switchers-package-wizard')) {
$user = User::find(Auth::user()->id);
$product = Product::find(Request::get('switchers-package-wizard'));
if($user->payment_order_id == $product->id){
if ($user->payment_order_id == $product->id) {
\Session()->flash('alert-success', __('msg.no_change_made'));
return back();
}
if($product && $product->active){
if ($product && $product->active) {
$user->payment_order_id = $product->id;
$user->save();
UserHistory::create(['user_id' => $user->id, 'action'=>$action, 'status'=>10, 'product_id'=>$product->id]);
UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 10, 'product_id' => $product->id]);
\Session()->flash('alert-success', __('msg.booked_package_has_been_changed'));
return back();
}
}
}
if($action === "delete_membership"){
if(Request::get('delete_membership_mivita')){
//TODO
if ($action === 'delete_membership') {
if (Request::get('delete_membership_mivita')) {
// TODO
$user = User::find(Auth::user()->id);
if($user->isTestMode()){
if ($user->isTestMode()) {
$mail = config('app.info_test_mail');
}else{
} 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]);
UserHistory::create(['user_id' => $user->id, 'action' => $action, 'status' => 50]);
\Session()->flash('alert-success', __('msg.cancel_membership_is_requested'));
return back();
}
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
return back();
}
\Session()->flash('alert-error', __('msg.error_checkbox_not_confirm'));
return back();
}
}
}