HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot//www.shooperm.com/app/Http/Controllers/Frontend/NewUserZoneController.php
<?php

namespace App\Http\Controllers\Frontend;

use App\Http\Controllers\Controller;
use App\Services\NewUserZoneService;
use Illuminate\Http\Request;
use Modules\Marketing\Entities\Coupon;
use Modules\Marketing\Entities\CustomerCouponStore;
use Modules\Marketing\Entities\NewUserZoneCoupon;
use Modules\UserActivityLog\Traits\LogActivity;

class NewUserZoneController extends Controller
{
    protected $newUserZoneService;

    public function __construct(NewUserZoneService $newUserZoneService)
    {
        $this->newUserZoneService = $newUserZoneService;
        $this->middleware('maintenance_mode');
    }

    public function show($slug)
    {
        $new_user_zone = $this->newUserZoneService->getById($slug);

        if(!auth()->check() && $new_user_zone->status == 0){
            return abort(404);
        }
        elseif(auth()->check() && $new_user_zone->status == 0){

            if(auth()->user()->role->type != 'superadmin' && auth()->user()->role->type != 'admin' && auth()->user()->role->type != 'staff'){
                return abort(404);
            }
        }

        $data['new_user_zone'] = $new_user_zone;
        $products = $new_user_zone->products()->whereHas('product', function($query){
            $query->where('status', 1)->whereHas('product', function($query){
                $query->where('status', 1);
            });
        })->paginate(12);
        $products->appends([
            'item' => 'product'
        ]);
        $data['products'] = $products;

        $data['allCategoryProducts'] = $this->newUserZoneService->getAllProductsForCategories($slug);
        $data['allCouponCategoryProducts'] = $this->newUserZoneService->getAllProductsForCouponCategories($slug);


        $data['coupon'] = $new_user_zone->coupon;

        $coupon_store_check = 0;
        if(auth()->check()){
            $is_coupon = CustomerCouponStore::where('coupon_id', $new_user_zone->coupon->coupon->id ?? '')->first();
            if(isset($is_coupon)){
                $coupon_store_check = 1;
            }else{
                $coupon_store_check = 0;
            }
        }
        $newUserZoneCoupon = NewUserZoneCoupon::where('new_user_zone_id',$new_user_zone->id)->first();
        $couponShow = 0;
        if($newUserZoneCoupon){
            $couponShow = 1;
        }
        $data['coupon_store_check'] = $coupon_store_check;
        $data['couponShow'] = $couponShow;

        return view(theme('pages.new_user_zone'),$data);
    }

    public function fetchProductData($slug){

        $new_user_zone = $this->newUserZoneService->getById($slug);
        $data['new_user_zone'] = $new_user_zone;
        $products = $new_user_zone->products()->whereHas('product', function($query){
            $query->where('status', 1)->whereHas('product', function($query){
                $query->where('status', 1);
            });
        })->paginate(12);
        $products->appends([
            'item' => 'product'
        ]);
        $data['products'] = $products;

        return view(theme('partials.new_user_zone_paginate_data._new_user_zone_product_paginate'),$data);

    }

    public function fetchCategoryData(Request $request, $slug){

        $category = $this->newUserZoneService->getCategoryById($request->parent_data);

        return view(theme('partials.new_user_zone_paginate_data._category_product_with_paginate'),compact('category'));
    }

    public function fetchAllCategoryData($slug){
        $allCategoryProducts = $this->newUserZoneService->getAllProductsForCategories($slug);
        return view(theme('partials.new_user_zone_paginate_data._category_all_product_with_paginate'),compact('allCategoryProducts'));
    }

    public function fetchAllCouponCategoryData($slug){
        $allCouponCategoryProducts = $this->newUserZoneService->getAllProductsForCouponCategories($slug);
        return view(theme('partials.new_user_zone_paginate_data._coupon_category_all_product_with_paginate'),compact('allCouponCategoryProducts'));
    }

    public function fetchCouponCategoryData(Request $request, $slug){
        $category = $this->newUserZoneService->getCouponCategoryById($request->parent_data);

        return view(theme('partials.new_user_zone_paginate_data._coupon_category_product_with_paginate'),compact('category'));
    }

    public function couponStore(Request $request, $slug){

        $coupon = Coupon::findOrFail($request->coupon_id);

        if(isset($coupon)){

            if(date('Y-m-d')>=$coupon->start_date && date('Y-m-d')<=$coupon->end_date){
                $this->newUserZoneService->couponStore($request->except('_token'));
                LogActivity::successLog('coupon store successful.');
                $new_user_zone = $this->newUserZoneService->getById($slug);
                $coupon = $new_user_zone->coupon;
                $coupon_store_check = 0;
                if(auth()->check()){
                    $is_coupon = CustomerCouponStore::where('coupon_id', $new_user_zone->coupon->coupon->id)->first();
                    if(isset($is_coupon)){
                        $coupon_store_check = 1;
                    }else{
                        $coupon_store_check == 0;
                    }
                }
                return view(theme('partials.new_user_zone_paginate_data._coupon_code'),compact('coupon', 'coupon_store_check'));
            }else{
                return response()->json([
                    'error' => 'Coupon Is Expired.'
                ]);
            }
        }else{
            return response()->json([
                'error' => 'Coupon Is Invalid.'
            ]);
        }

    }
}