#10 Promotion Modul, Kommentar 2

This commit is contained in:
Kevin Adametz 2021-11-09 18:40:18 +01:00
parent f0da981737
commit c9e1545693
128 changed files with 8194 additions and 637 deletions

View file

@ -4,7 +4,7 @@ namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

View file

@ -45,8 +45,8 @@ class MembershipController extends Controller
$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(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'upgrade' => Product::where('active', true)->whereJsonContains('show_on', '5')->where('identifier', 'upgrade')->get(),
'diff_months' => $diff_months,
'userHistoryPaymentOrder' => $userHistoryPaymentOrder,
'userHistoryUpgradeOrder' => $userHistoryUpgradeOrder,
@ -93,7 +93,7 @@ class MembershipController extends Controller
$user->abo_options = true;
$user->save();
}*/
if($product && $product->active && $product->show_at >= 3){
if($product && $product->active){
$image = "";
if($product->images->count()){
$image = $product->images->first()->slug;
@ -146,7 +146,7 @@ class MembershipController extends Controller
\Session()->flash('alert-success', "keine Änderung vorgenommen.");
return back();
}
if($product && $product->active && $product->show_at >= 3){
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]);

View file

@ -35,7 +35,7 @@ class PaymentMethodController extends Controller
'name' => $data['name'],
'short' => $data['short'],
'pos' => $data['pos'],
'show_at' => $data['show_at'],
'show_on' => isset($data['show_on']) ? $data['show_on'] : null,
'max_price' => $data['max_price'],
'default' => isset($data['default']) ? true : false,
'active' => isset($data['active']) ? true : false,
@ -46,7 +46,7 @@ class PaymentMethodController extends Controller
$model->short = $data['short'];
$model->pos = $data['pos'];
$model->max_price = $data['max_price'];
$model->show_at = $data['show_at'];
$model->show_on = isset($data['show_on']) ? $data['show_on'] : null;
$model->default = isset($data['default']) ? true : false;
$model->active = isset($data['active']) ? true : false;
$model->save();

View file

@ -20,7 +20,6 @@ class ProductController extends Controller
{
$this->middleware('admin');
$this->productRepo = $productRepo;
}
public function index()
@ -104,17 +103,11 @@ class ProductController extends Controller
\Session()->flash('alert-save', '1');
return redirect(route('admin_product_show'));
}
public function copy($id){
$model = Product::findOrFail($id);
$product = $this->productRepo->copy($model);
\Session()->flash('alert-success', 'Eintrag kopiert');
return redirect(route('admin_product_show'));
}
@ -140,9 +133,7 @@ class ProductController extends Controller
}
// Upload FILE -----------------------------------------------------------------------------------------------------------------------
public function imageUpload(){
$product_id = Request::get('product_id');
@ -191,7 +182,7 @@ class ProductController extends Controller
return redirect(route('admin_product_edit', [$product->id]));
}
catch (Exception $e) {
catch (\Exception $e) {
\Session()->flash('alert-danger', "Fehler".$e);
return redirect(route('admin_product_edit', [$product->id]));
}

View file

@ -308,14 +308,14 @@ class SalesController extends Controller
$shopping_order = ShoppingOrder::findOrFail($data['id']);
$shopping_payment = ShoppingPayment::findOrFail($data['payment_id']);
if($shopping_order->shopping_order_margin->from_payment_credit > 0){
if($shopping_order->shopping_order_margin && $shopping_order->shopping_order_margin->from_payment_credit > 0){
$last_UserPayCredit = UserPayCredit::where('shopping_order_id', $shopping_order->id)->whereIn('status', [2, 4])->orderBy('id', 'DESC')->first();
//Status Keine Zahlung, Guthaben zurückführen, wenn status 2 / deduction from payment
if($data['txaction'] === 'non' && $last_UserPayCredit->status === 2){
if($last_UserPayCredit && $data['txaction'] === 'non' && $last_UserPayCredit->status === 2){
Payment::handelUserPayCredits($shopping_order, 'return');
}
//Status Zahlung, voher gab es eine Storno, Guthaben abziehen wenn status 4 / return from order
if($last_UserPayCredit->status === 4 && ($data['txaction'] === 'open' || $data['txaction'] === 'paid')){
if($last_UserPayCredit && $last_UserPayCredit->status === 4 && ($data['txaction'] === 'open' || $data['txaction'] === 'paid')){
Payment::handelUserPayCredits($shopping_order, 'deduction');
}

View file

@ -105,6 +105,8 @@ class CheckoutController extends Controller
$shopping_user = ShoppingUser::findOrFail($this->getPayments('shopping_user_id'));
$shopping_user->billing_state = Shop::getCountryShippingCountryId($shopping_user->billing_country_id);
$shopping_user->shipping_state = Shop::getCountryShippingCountryId($shopping_user->shipping_country_id);
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; //reinvert
}
if($shopping_user->same_as_billing === NULL){
$shopping_user->same_as_billing = false;
@ -552,7 +554,7 @@ class CheckoutController extends Controller
$shopping_order->txaction = 'open';
$shopping_order->save();
if($shopping_payment){
Payment::handelUserPayCredits($shopping_order, 'deduction');

View file

@ -438,19 +438,16 @@ class HomepartyController extends Controller
abort(404);
}
private function getHomparty($id){
/*private function getHomparty($id){
$homeparty = Homeparty::findOrFail($id);
if($homeparty->auth_user_id !== \Auth::user()->id){
abort(404);
}
return $homeparty;
}
}*/
public function datatable(){
$query = Product::select('products.*')->where('active', true)->where(function ($q) {
$q->where('show_at', '=', 0)
->orWhere('show_at', '=', 1);
});
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '3');
return \DataTables::eloquent($query)

View file

@ -278,33 +278,17 @@ class OrderController extends Controller
public function datatable(){
$show_at = 1;
$not_show_pids = ProductBuy::getNotShowProductIDs(Auth::user()->id);
if(Request::get('shipping_is_for') === 'me'){
$query = Product::with('categories')->select('products.*')->where('active', true)->where(function ($q) {
$q->where('show_at', '=', 1)
->orWhere('show_at', '=', 2)
->orWhere('show_at', '=', 6);
});
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '2');
}else{
$query = Product::with('categories')->select('products.*')->where('active', true)->where(function ($q) {
$q->where('show_at', '=', 0)
->orWhere('show_at', '=', 1);
});
$query = Product::select('products.*')->where('active', true)->whereJsonContains('show_on', '1');
}
foreach($not_show_pids as $not_show_pid){
$query->where('id', '!=', $not_show_pid);
}
//Kunden und Vertriebspartner
//->orWhere('show_at', '=', 2); // Nur Vertriebspartner
//->orderBy('pos', 'DESC')
//->orderBy('id', 'DESC');
return \DataTables::eloquent($query)
->addColumn('product', function (Product $product) {
@ -540,10 +524,10 @@ class OrderController extends Controller
private function getCompProducts($for){
if($for === 'me' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_me')){
return Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
return Product::whereActive(true)->whereJsonContains('show_on', ['2'])->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
}
if($for === 'ot' && \App\Models\Setting::getContentBySlug('order_partner_is_comp_ot')){
return Product::whereActive(true)->where('show_at', '=', 1)->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
return Product::whereActive(true)->whereJsonContains('show_on', ['1'])->where('shipping_addon', true)->orderBy('pos', 'DESC')->get();
}
return null;
}

View file

@ -34,11 +34,11 @@ class PromotionController extends Controller
public function detail($id){
$user_promotion = PromotionUser::findOrFail($id);
if($user_promotion->user_id != Auth::user()->id){
abort(404);
}
$user_promotion->about_you = !$user_promotion->about_you ? $user_promotion->user->account->about_you : $user_promotion->about_you;
$data = [
'checkPaymentCredit' => $user_promotion->checkPaymentCredit(),
'user_promotion_cart' => PromotionUser::preCalculateCart($user_promotion, 'user_promotion'),
@ -59,7 +59,7 @@ class PromotionController extends Controller
if(isset($data['action']) && $data['action'] === 'save-user-promotion'){
$rules = array(
'name' => 'required',
'user_promotion_url' => ' required|alpha_dash|profanity|unique:promotion_users,url,'.\Auth::user()->id.'|min:4|max:20',
'user_promotion_url' => ' required|alpha_dash|profanity|unique:promotion_users,url,'.\Auth::user()->id.',user_id|min:4|max:20',
);
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
@ -96,7 +96,7 @@ class PromotionController extends Controller
if(isset($data['action']) && $data['action'] === 'validate_url'){
$rules = array(
//'user_promotion_url' => ' required|alpha_dash|profanity|unique:user_shops,name|min:4|max:20|full_word_check',
'user_promotion_url' => ' required|alpha_dash|profanity|unique:promotion_users,url,'.\Auth::user()->id.'|min:4|max:20',
'user_promotion_url' => ' required|alpha_dash|profanity|unique:promotion_users,url,'.\Auth::user()->id.',user_id|min:4|max:20',
);
/*Validator::extend('full_word_check', function ($attribute, $value, $parameters, $validator) {
if(in_array($value, config('profanity.full_word_check'))){
@ -119,7 +119,7 @@ class PromotionController extends Controller
return Response::json(array(
'success' => true,
'preview_user_promotion_url' => config('app.promo_url').$name,
'preview_user_promotion_url' => config('app.promo_url')."/".$name,
));
}
if(isset($data['action']) && $data['action'] === 'updateCart'){
@ -130,7 +130,7 @@ class PromotionController extends Controller
if(isset($data['products'])){
$fill['user_promotion_cart'] = PromotionUser::preCalculateCart($data['products'], 'products');
$fill['checkPaymentCredit'] = PromotionUser::preCheckPaymentCredit($fill['user_promotion_cart']);
$fill['checkPaymentCredit'] = PromotionUser::preCheckPaymentCredit($fill['user_promotion_cart'], Auth::user());
}
/*if(isset($data['user_promotion_id']) && $user_promotion = PromotionUser::find($data['user_promotion_id'])){

View file

@ -21,7 +21,6 @@ class UserDataController extends Controller
$this->userRepo = $userRepo;
}
public function userEdit(){
$user = Auth::user();
@ -34,7 +33,6 @@ class UserDataController extends Controller
return view('user.edit', $data);
}
public function userEditStore(){
$user = Auth::user();
@ -86,10 +84,7 @@ class UserDataController extends Controller
}
/**
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function userDataStore(){
$user = User::findOrFail(Auth::user()->id);
@ -150,10 +145,7 @@ class UserDataController extends Controller
return redirect('/home');
}
}
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function userDataAcceptedForm(){
$user = Auth::user();
@ -168,10 +160,6 @@ class UserDataController extends Controller
return redirect('/home');
}
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function userDataFree(){
$user = Auth::user();
$user->active = 1;
@ -181,9 +169,6 @@ class UserDataController extends Controller
}
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function userDataFreeForm(){
$user = Auth::user();
@ -220,7 +205,76 @@ class UserDataController extends Controller
}
return redirect('/home');
}
public function userProfile(){
$user = Auth::user();
$data = [
'user' => $user,
];
return view('user.profile', $data);
}
public function userProfileStore(){
$user = Auth::user();
$data = Request::all();
if($account = $user->account){
$account->about_you = $data['about_you'] ? $data['about_you'] : null;
$account->save();
}
\Session()->flash('alert-save', true);
return redirect(route('user_profile'));
}
// Upload FILE -----------------------------------------------------------------------------------------------------------------------
public function imageUpload(){
$user = Auth::user();
try {
$image = \App\Services\Slim::getImages('avatar')[0];
if ( isset($image['output']['data']) )
{
// Original file name
$name = $image['output']['name'];
// Base64 of the image
$data = $image['output']['data'];
$file_ex = array( 'image/jpeg' => 'jpg', 'image/png' => 'png');
if (!isset($file_ex[$image['output']['type']])) {
\Session()->flash('alert-danger', 'File is not jpg or png!');
return redirect()->back();
}
$ext = $file_ex[$image['output']['type']];
$data = \Storage::disk('user')->put(
$user->id.'/avatar.'.$ext,
$data
);
\Session()->flash('alert-success', "Datei hochgeladen");
return redirect()->back();
}
\Session()->flash('alert-danger', "Datei leer");
return redirect()->back();
}
catch (\Exception $e) {
\Session()->flash('alert-danger', "Fehler".$e);
return redirect()->back();
}
}
public function imageDelete($delete){
$user = Auth::user();
if($delete === 'avatar'){
if($user->hasProfileImage()){
\Storage::disk('user')->delete(str_replace('_', '/', $user->getProfileImage()));
\Session()->flash('alert-success', "Datei gelöscht");
return redirect()->back();
}
}
}
}

View file

@ -0,0 +1,99 @@
<?php
namespace App\Http\Controllers\Web;
use Request;
use Response;
use Validator;
use App\Services\Util;
use App\Models\Product;
use App\Models\PaymentMethod;
use App\Models\PromotionUser;
use App\Http\Controllers\Controller;
class PromotionController extends Controller
{
public function __construct()
{
}
public function serve($path = null)
{
if(!isset($path)){
abort(402);
}
//search for promo
$PromotionUser = PromotionUser::where('url', trim($path))->whereNull('user_deleted_at')->first();
if(!$PromotionUser){
abort(402);
}
if($PromotionUser->checkOutOfStock()){
$data = [
'promotion_user' => $PromotionUser,
];
return view('web.promotion.outofstock', $data);
}
$data = [
'promotion_user' => $PromotionUser,
'shop_products' => Product::where('active', true)->whereJsonContains('show_on', ['1', '2', '3'])->orderBy('pos', 'ASC')->get(),
'user_payment_methods' => PaymentMethod::getDefaultAsArray()->toArray(),
];
return view('web.promotion.index', $data);
}
public function goto($load, $id){
$PromotionUser = PromotionUser::findOrFail($id);
$data = [
'promotion_user' => $PromotionUser,
];
if($load === 'thanksreminder'){
return view('web.promotion.thanksreminder', $data);
}
if($load === 'thanksorder'){
return view('web.promotion.thanksorder', $data);
}
if($load === 'notactive'){
return view('web.promotion.notactive', $data);
}
}
public function store($id){
$PromotionUser = PromotionUser::findOrFail($id);
$data = Request::all();
if(!isset($data['action'])){
abort(402);
}
if($data['action'] === 'submit-reminder-service'){
return redirect(route('web_promotion_goto', ['thanksreminder', $PromotionUser->id]));
}
if($data['action'] === 'submit-promotion-order'){
return redirect(route('web_promotion_goto', ['thanksorder', $PromotionUser->id]));
}
dd($PromotionUser);
}
public function load(){
$data = Request::all();
$ret = "";
$status = false;
if(Request::ajax()){
if($data['action'] === 'web-show-product'){
$product = Product::find($data['id']); //current user form order
$ret = view("web.promotion.show_product", compact('product', 'data'))->render();
}
return response()->json(['response' => $data, 'html'=>$ret, 'status'=>$status]);
}
}
}

View file

@ -60,8 +60,8 @@ class WizardController extends Controller
$data = [
'user' => Auth::user(),
'step' => $step,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
'userHistoryWizardPayment' => $userHistoryWizardPayment,
];
@ -96,8 +96,9 @@ class WizardController extends Controller
'user' => Auth::user(),
'step' => $step,
'user_levels' => UserLevel::where('active', true)->get(),
//'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
//'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
//'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
//'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
];
if($step == 5){
return view('user.wizard.register_release', $data);
@ -125,8 +126,8 @@ class WizardController extends Controller
$data = [
'user' => Auth::user(),
'step' => 0,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
'userHistoryWizardPayment' => $userHistoryWizardPayment,
];
@ -161,8 +162,8 @@ class WizardController extends Controller
'user' => Auth::user(),
'step' => $step,
'user_levels' => UserLevel::where('active', true)->get(),
//'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
//'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
//'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
//'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),,
];
$user->wizard = 0;
$user->save();
@ -342,8 +343,8 @@ class WizardController extends Controller
$data = [
'user' => Auth::user(),
'step' => $step,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
];
$user->wizard = 10;
$user->save();
@ -381,8 +382,8 @@ class WizardController extends Controller
$data = [
'user' => Auth::user(),
'step' => $step,
'products' => Product::where('active', true)->where('show_at', '=', 3)->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->where('show_at', '=', 5)->orderBy('pos', 'ASC')->get(),
'products' => Product::where('active', true)->whereJsonContains('show_on', ['4', '5'])->orderBy('pos', 'ASC')->get(),
'products_on_board' => Product::where('active', true)->whereJsonContains('show_on', '6')->orderBy('pos', 'ASC')->get(),
];
return view('user.wizard.create', $data)->withErrors($validator);
}
@ -457,7 +458,7 @@ class WizardController extends Controller
$user->abo_options = true;
$user->save();
}*/
if($product && $product->active && $product->show_at == 3){
if($product && $product->active){
//set membership product
$image = "";
if($product->images->count()){