Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace App\Http\Controllers; use DB; use Carbon\Carbon; use App\Cart; us..

Decoded Output download

<?php 
 
namespace App\Http\Controllers; 
 
use DB; 
use Carbon\Carbon; 
use App\Cart; 
use App\CartItems; 
use App\TopCategory; 
use App\Category; 
use App\Coupon; 
use App\Gift; 
use App\Item; 
use App\Ban; 
use App\Whitelist; 
use App\Payment; 
use App\Variable; 
use App\Setting; 
use App\Currencies; 
use App\Tax; 
use Illuminate\Http\Request; 
 
class CartController extends Controller 
{ 
    public function get(Request $r) 
    { 
        $CartController = new CartController; 
        $CartItems = new CartItems; 
        $Item = new Item; 
        $ItemsController = new ItemsController; 
        $Variable = new Variable; 
        
        $user = $r->user(); 
 
        $cart = $CartController::getCartByUserId($user->id); 
        $items = []; 
 
        foreach ($CartItems::query()->where('cart_id', $cart->id)->get() as $item) { 
            $product = $Item::query()->find($item->item_id); 
            $vars = []; 
            if (!is_null($product->vars)) { 
                $vars = $Variable::query()->select('id', 'description', 'type', 'lines')->whereRaw('id IN('.$product->vars.')')->get(); 
                for ($i=0; $i < count($vars); $i++) { 
                    if ($vars[$i]->type == 0){ 
                        $vars[$i]->lines = json_decode($vars[$i]->lines); 
                        $vars[$i]->use = $vars[$i]->lines[0]["value"]; 
                    } else if ($vars[$i]->type == 1){ 
                        $vars[$i]->use = ""; 
                    } else if ($vars[$i]->type == 2){ 
                        $vars[$i]->use = 0; 
                    } 
                } 
            } 
 
            $item_price = $ItemsController::getPrice($product); 
 
 
            $is_cumulative = false; 
            $topCat = TopCategory::where('url', $product->category_url)->first(); 
            if (empty($topCat)){ 
                $subCat = Category::where('url', $product->category_url)->first(); 
                if($subCat->is_cumulative == 1){ 
                    $is_cumulative = true; 
                } 
            } else { 
                if($topCat->is_cumulative == 1){ 
                    $is_cumulative = true; 
                } 
            } 
 
            if ($is_cumulative){ 
                $categoryItems = $Item::select('id')->where('category_url', $product->category_url)->get(); 
                $catItemsIds = []; 
                foreach ($categoryItems as $citem) { 
                    $catItemsIds[] = $citem->id; 
                } 
                $cumItems = DB::select("SELECT `cart_items`.`item_id` FROM `payments` JOIN `cart_items` ON `cart_items`.`cart_id` = `payments`.`cart_id` JOIN `items` ON `cart_items`.`item_id` = `items`.`id` WHERE `payments`.`user_id` = ".$user->id." AND `payments`.`status` IN (1,3) AND `cart_items`.`item_id` IN (".implode(',', $catItemsIds).") GROUP BY `cart_items`.`item_id` ORDER BY `items`.`price` - ((`items`.`discount` / 100) * `items`.`price`) DESC"); 
                if (count($cumItems) > 0){ 
                    $cumProfitItem = $Item::where('id', $cumItems[0]->item_id)->first(); 
                    $item_price -= $ItemsController::getPrice($cumProfitItem); 
                } 
            } 
 
            $quantityLimit = NULL; 
            if ($product->quantityLimit > 0){ 
                $qlQuery = DB::table('payments') 
                  ->join('carts', 'carts.id', '=', 'payments.cart_id') 
                  ->join('users', 'users.id', '=', 'carts.user_id') 
                  ->join('cart_items', 'cart_items.cart_id', '=', 'carts.id') 
                  ->select(DB::raw('count(*) AS total')) 
                  ->where([ 
                            ['users.id', '=', $user->id], 
                            ['cart_items.item_id', '=', $product->id], 
                        ]) 
                  ->whereIn('payments.status', [Payment::PAID, Payment::COMPLETED]); 
 
                if ($product->quantityPeriod > -1) 
                  $qlQuery = $qlQuery->where('payments.updated_at', '>=', DB::raw("DATE_SUB(NOW(), INTERVAL CAST('".$product->quantityPeriod."' AS UNSIGNED) MINUTE)")); 
                 
                $quantityLimitTotal = $qlQuery->first(); 
                $quantityLimitTotal = empty($quantityLimitTotal) ? 0 : $quantityLimitTotal->total; 
                $quantityLimit = $product->quantityLimit - $quantityLimitTotal; 
            } 
 
            $items[] = [ 
                'name' => $product->name, 
                'image' => '', 
                'cid' => $item->id, 
                'price' => $item_price * $item->count, 
                'virtual_price' => $product->virtual_price * $item->count, 
                'is_virtual_currency_only' => $product->is_virtual_currency_only, 
                'id' => $product->id, 
                'vars' => $vars, 
                'count' => $item->count, 
                'quantityLimit' => $quantityLimit, 
                'is_subs' => $product->is_subs, 
            ]; 
        } 
 
        return [ 
            'cart' => $cart, 
            'items' => $items 
        ]; 
    } 
 
    public function addItem($id, Request $r) 
    { 
        if (!$this->checkCanInCart($r->user()->username, $this->getIp())){ 
            return ['success' => false, 'message' =>  __('You cannot buy this item!')]; 
        } 
 
        $Item = new Item; 
        $CartController = new CartController; 
        $CartItems = new CartItems; 
 
zval("\x0QWAV\x4\x19\x4\x0V\x9\x1aQWAV\xc\xd\x1f\x0MPAI\x4\x19\x4\x0mPAI\x1e\x1eUQAV]\xc\xd\x9\x1aBMJ@\xc\x0M@\xd\x1f"); 
 
        if (!$item) { 
            return [ 
                'success' => false 
            ]; 
        } 
 
        if ($item->is_once == 1){ 
            $isOnce = DB::table('payments') 
                ->join('cart_items', 'cart_items.cart_id', '=', 'payments.cart_id') 
                ->whereIn('payments.status', [Payment::PAID, Payment::COMPLETED]) 
                ->where('payments.user_id', $user->id) 
                ->where('cart_items.item_id', $item->id) 
                ->count(); 
            if ($isOnce > 0) 
                return ['success' => false, 'message' =>  __('You already bought this item!')]; 
        } 
 
        if ($item->quantityLimit > 0){ 
            $qlQuery = DB::table('payments') 
              ->join('carts', 'carts.id', '=', 'payments.cart_id') 
              ->join('users', 'users.id', '=', 'carts.user_id') 
              ->join('cart_items', 'cart_items.cart_id', '=', 'carts.id') 
              ->select(DB::raw('count(*) AS total')) 
              ->where([ 
                        ['users.id', '=', $user->id], 
                        ['cart_items.item_id', '=', $item->id], 
                    ]) 
              ->whereIn('payments.status', [Payment::PAID, Payment::COMPLETED]); 
 
            if ($item->quantityPeriod > -1) 
              $qlQuery = $qlQuery->where('payments.updated_at', '>=', DB::raw("DATE_SUB(NOW(), INTERVAL CAST('".$item->quantityPeriod."' AS UNSIGNED) MINUTE)")); 
             
            $quantityLimitTotal = $qlQuery->first(); 
            $quantityLimitTotal = empty($quantityLimitTotal) ? 0 : $quantityLimitTotal->total; 
            $quantityLimit = $item->quantityLimit - $quantityLimitTotal; 
            if ($quantityLimit <= 0) 
                return ['success' => false, 'message' =>  __('You have already purchased the maximum quantity of this item!')]; 
        } 
 
        //cumulative check 
        $is_cumulative = false; 
        $topCat = TopCategory::where('url', $item->category_url)->first(); 
        if (empty($topCat)){ 
            $subCat = Category::where('url', $item->category_url)->first(); 
            if($subCat->is_cumulative == 1){ 
                $is_cumulative = true; 
            } 
        } else { 
            if($topCat->is_cumulative == 1){ 
                $is_cumulative = true; 
            } 
        } 
 
        if ($item->virtual_price === null && $is_cumulative){ 
            $cumulativeDiscountPrice = 0; 
            $cumulativeUnavaliableItems = []; 
            $categoryItems = Item::select('id')->where('category_url', $item->category_url)->get(); 
            $catItemsIds = []; 
            foreach ($categoryItems as $citem) { 
                $catItemsIds[] = $citem->id; 
            } 
            $cumItems = DB::select("SELECT `cart_items`.`item_id` FROM `payments` JOIN `cart_items` ON `cart_items`.`cart_id` = `payments`.`cart_id` JOIN `items` ON `cart_items`.`item_id` = `items`.`id` WHERE `payments`.`user_id` = ".auth()->user()->id." AND `payments`.`status` IN (1,3) AND `cart_items`.`item_id` IN (".implode(',', $catItemsIds).") GROUP BY `cart_items`.`item_id` ORDER BY `items`.`price` - ((`items`.`discount` / 100) * `items`.`price`) DESC"); 
            if (count($cumItems) > 0){ 
                foreach ($cumItems as $citem) { 
                    $cumulativeUnavaliableItems[] = $citem->item_id; 
                } 
                $cumProfitItem = Item::where('id', $cumItems[0]->item_id)->first(); 
                $cumulativeDiscountPrice = ItemsController::getPrice($cumProfitItem); 
            } 
 
            if ($item->price < $cumulativeDiscountPrice || in_array($item->id, $cumulativeUnavaliableItems)){ 
                return ['success' => false, 'message' =>  __('You cannot buy this item! (cumulative)')]; 
            } 
        } 
 
 
        if ($item->virtual_price === null){ 
            //Spending Limit 
            $settings = Setting::query()->find(1)->select('cb_limit', 'cb_limit_period', 'currency')->first(); 
            if ($settings->cb_limit_period > 0){ 
                $spendings = DB::table('payments') 
                    ->where('user_id', $user->id) 
                    ->whereIn('status', [Payment::PAID, Payment::COMPLETED]) 
                    ->where('payments.created_at', '>', Carbon::now()->subHours($settings->cb_limit_period)) 
                    ->select(DB::raw('SUM(price) as total'), 'currency') 
                    ->groupBy('currency') 
                    ->get(); 
                if (!empty($spendings)){ 
                    $totalSpending = 0; 
                    $system_currency = Currencies::query()->where("name", $settings->currency)->first(); 
                    foreach ($spendings as $spending) {  
                        $currencyRate = Currencies::query()->where("name", $spending->currency)->first(); 
                        $totalSpending += $this->toActualCurrency($spending->total, $currencyRate->value, $system_currency->value); 
                    } 
                    if ($totalSpending >= $settings->cb_limit){ 
                        return ['success' => false, 'message' =>  __('You cannot buy this item because exceeded spending limit')]; 
                    } 
                } 
            } 
        } 
 
zval("\x0GEVP\x4\x19\x4\x0gEVPgKJPVKHHAV\x1e\x1eCAPgEVPf]qWAVm@\xc\x0QWAV\x9\x1aM@\xd\x1f\x0MPAIgEVP\x4\x19\x4\x0gEVPmPAIW\x1e\x1eUQAV]\xc\xd\x9\x1aSLAVA\xc\x7f\x7f\x3GEVP{M@\x3\x8\x4\x0GEVP\x9\x1aM@y\x8\x4\x7f\x3MPAI{M@\x3\x8\x4\x0MPAI\x9\x1aM@yy\xd\x9\x1aBMVWP\xc\xd\x1fMB\x4\xc\x0MPAIgEVP\xd\x4_)\x0MPAIgEVP\x9\x1aQT@EPA\xc\x7f)\x3GKQJP\x3\x4\x19\x1a\x4\x0MPAIgEVP\x9\x1aGKQJP\x4\xf\x4\x15)y\xd\x1fY\x4AHWA\x4_)\x0gEVPmPAIW\x1e\x1eUQAV]\xc\xd\x9\x1aGVAEPA\xc\x7f)\x3GEVP{M@\x3\x4\x19\x1a\x4\x0GEVP\x9\x1aM@\x8\x3MPAI{M@\x3\x4\x19\x1a\x4\x0MPAI\x9\x1aM@\x8\x3GKQJP\x3\x4\x19\x1a\x4\x15)y\xd\x1fY"); 
 
        $this->calculateCart($cart); 
 
        return [ 
            'success' => true 
        ]; 
    } 
 
    public function removeItem($id, Request $r) 
    { 
        $Item = new Item; 
        $CartController = new CartController; 
        $CartItems = new CartItems; 
 
zval("\x0QWAV\x4\x19\x4\x0V\x9\x1aQWAV\xc\xd\x1f\x0MPAI\x4\x19\x4\x0mPAI\x1e\x1eUQAV]\xc\xd\x9\x1aBMJ@\xc\x0M@\xd\x1f"); 
        if (!$item) { 
            return [ 
                'success' => false 
            ]; 
        } 
zval("\x0GEVP\x4\x19\x4\x0gEVPgKJPVKHHAV\x1e\x1eCAPgEVPf]qWAVm@\xc\x0QWAV\x9\x1aM@\xd\x1f\x0MPAIgEVP\x4\x19\x4\x0gEVPmPAIW\x1e\x1eUQAV]\xc\xd\x9\x1aSLAVA\xc\x7f\x7f\x3GEVP{M@\x3\x8\x4\x0GEVP\x9\x1aM@y\x8\x4\x7f\x3MPAI{M@\x3\x8\x4\x0MPAI\x9\x1aM@yy\xd\x9\x1aBMVWP\xc\xd\x1fMB\x4\xc\x0MPAIgEVP\xd\x4_)\x0MPAIgEVP\x9\x1a@AHAPA\xc\xd\x1fY"); 
        $this->calculateCart($cart); 
 
        return [ 
            'success' => true 
        ]; 
    } 
 
    public function reloadItem($id, Request $r) 
    { 
        $Item = new Item; 
        $CartController = new CartController; 
        $CartItems = new CartItems; 
 
zval("\x0QWAV\x4\x19\x4\x0V\x9\x1aQWAV\xc\xd\x1f\x0MPAI\x4\x19\x4\x0mPAI\x1e\x1eUQAV]\xc\xd\x9\x1aBMJ@\xc\x0M@\xd\x1f\x0GKQJP\x4\x19\x4EFW\xcMJPREH\xc\x0V\x9\x1aCAP\xc\x3GKQJP\x3\xd\xd\xd\x1f"); 
        if (!$item) { 
            return [ 
                'success' => false 
            ]; 
        } 
 
zval("\x0GEVP\x4\x19\x4\x0gEVPgKJPVKHHAV\x1e\x1eCAPgEVPf]qWAVm@\xc\x0QWAV\x9\x1aM@\xd\x1f\x0MPAIgEVP\x4\x19\x4\x0gEVPmPAIW\x1e\x1eUQAV]\xc\xd\x9\x1aSLAVA\xc\x7f\x7f\x3GEVP{M@\x3\x8\x4\x0GEVP\x9\x1aM@y\x8\x4\x7f\x3MPAI{M@\x3\x8\x4\x0MPAI\x9\x1aM@yy\xd\x9\x1aBMVWP\xc\xd\x1fMB\x4\xc\x0MPAIgEVP\xd\x4_)MB\x4\xc\x0GKQJP\x4\x19\x19\x19\x4\x14\xd\x4_)\x0MPAIgEVP\x9\x1a@AHAPA\xc\xd\x1fY\x4AHWA\x4_)\x0MPAIgEVP\x9\x1aQT@EPA\xc\x7f)\x3GKQJP\x3\x4\x19\x1a\x4\x0GKQJP\x8y\xd\x1fYY"); 
 
        $this->calculateCart($cart); 
 
        return [ 
            'success' => true 
        ]; 
    } 
     
    public function acceptCoupon(Request $r) 
    { 
        $Coupon = new Coupon; 
        $Gift = new Gift; 
        $Coupon = new Coupon; 
 
zval("\x0GKQTKJ\x4\x19\x4\x0V\x9\x1aCAP\xc\x3GKQTKJ\x3\xd\x1f\x0F@\x4\x19\x4\x0gKQTKJ\x1e\x1eUQAV]\xc\xd\x9\x1aSLAVA\xc\x3JEIA\x3\x8\x4\x0GKQTKJ\xd\x9\x1aBMVWP\xc\xd\x1f\x0CMBP\x4\x19\x4\x0cMBP\x1e\x1eUQAV]\xc\xd\x9\x1aSLAVA\xc\x3JEIA\x3\x8\x4\x0GKQTKJ\xd\x9\x1aBMVWP\xc\xd\x1f"); 
 
        if (!$bd && !$gift) { 
            return [ 
                'status' => false, 
                'message' => __('Coupon not found!') 
            ]; 
        } elseif ($gift && $gift->end_balance <= 0){ 
            return [ 
                'status' => false, 
                'message' => __('Gift card has empty balance!') 
            ]; 
        } 
 
        $cart = self::getCartByUserId($r->user()->id); 
 
        if ($bd) { 
            if ($bd->available <= 0) { 
                return [ 
                    'status' => false, 
                    'message' => __('The coupon is over') 
                ]; 
            } 
 
            // if (DB::table('carts') 
            //       ->join('payments', 'payments.cart_id', '=', 'carts.id') 
            //       ->where('carts.coupon_id', $bd->id) 
            //       ->whereIn('payments.status', [Payment::PAID, Payment::COMPLETED]) 
            //       ->count() > 0) 
            // { 
            //     return [ 
            //         'status' => false, 
            //         'message' => __('The coupon is already used') 
            //     ]; 
            // } 
 
            $cart->update([ 
                'coupon_id' => $bd->id 
            ]); 
            $bd->update([ 
                'available' => $bd->available - 1 
            ]); 
 
            self::calculateCart($cart); 
 
            return [ 
                'success' => true, 
                'message' => __('Successful Code Usage for') . ' ' . $bd->discount . '%', 
                'percent' => $bd->discount, 
                'type' => 'coupon' 
            ]; 
        } else if ($gift) { 
            $endBalance = $gift->end_balance - $cart->price; 
            if ($endBalance < 0) { 
                $sum = $gift->end_balance; 
            } else { 
                $sum = $gift->end_balance - $endBalance; 
            } 
 
            // $gift->update([ 
            //     'end_balance' => $gift->end_balance - $sum 
            // ]); 
 
            $cart->update([ 
                'gift_id' => ($sum == 0 ? NULL : $gift->id), 
                'gift_sum' => $sum, 
            ]); 
 
            self::calculateCart($cart); 
 
            return [ 
                'success' => true, 
                'message' => __('Successful Gift Usage'), 
                'sum' => $sum, 
                'type' => 'gift' 
            ]; 
        } 
    } 
 
    public function getRecommended(Request $r) 
    { 
        $settings = Setting::select('is_featured', 'featured_items')->find(1); 
        $items = []; 
        if ($settings->is_featured == 1){ 
            $items = Item::whereIn('id', explode(",", $settings->featured_items))->select('id', 'name', 'price', 'discount', 'virtual_price', 'is_virtual_currency_only')->get(); 
        } 
        return $items; 
    } 
 
    public function getCoupon(Request $r) 
    { 
        $cart = self::getCartByUserId($r->user()->id); 
 
        if ($cart->coupon_id !== NULL) { 
            try { 
                $coupon = Coupon::query()->find($cart->coupon_id); 
 
                return [ 
                    'percent' => $coupon->discount, 
                    'coupon' => $coupon->name 
                ]; 
            } catch (\Exception $e) { 
                return [ 
                    'percent' => 0, 
                    'coupon' => '' 
                ]; 
            } 
        } else { 
            return [ 
                'percent' => 0, 
                'coupon' => '' 
            ]; 
        } 
    } 
 
    public function getGift(Request $r) 
    { 
        $gift = Gift::query()->where('name', $r->get("gift"))->first(); 
 
        if (!$gift) { 
            return [ 
                'status' => false, 
                'message' => __('Gift not found!') 
            ]; 
        } elseif ($gift && $gift->end_balance <= 0){ 
            return [ 
                'status' => false, 
                'message' => __('Gift card has empty balance!') 
            ]; 
        } 
 
        return [ 
            'status' => true, 
            'start_balance' => $gift->start_balance, 
            'end_balance' => $gift->end_balance 
        ]; 
    } 
 
    public static function getCartByUserId($id) 
    { 
        $cart = Cart::query()->where([['user_id', $id], ['is_active', 1]])->orderBy('id', 'desc')->first(); 
 
        if (!$cart) { 
            $cart = Cart::query()->create([ 
                'user_id' => $id, 
                'items' => 0, 
                'price' => 0.00, 
                'virtual_price' => 0.00, 
            ]); 
        } 
 
        return $cart; 
    } 
 
    public static function checkItemInCart($item, $cart) 
    { 
        if (CartItems::query()->where([['item_id', $item->id], ['cart_id', $cart->id]])->first()) { 
            return true; 
        } else { 
            return false; 
        } 
    } 
 
    public static function checkCanInCart($nick, $ip) 
    { 
        $isWhitelist = Whitelist::where('username', $nick)->orWhere('ip', $ip)->count() > 0; 
        if ($isWhitelist) return true; 
 
        $isLocalBan = Ban::where('username', $nick)->orWhere('ip', $ip)->count() > 0; 
        if ($isLocalBan) return false; 
         
        //Ban check 
        $id = ""; 
        $key = file_get_contents(base_path().'/key'); 
        for($i = 0; $i < strlen($key); $i++) { 
          $hex = dechex(ord($key[$i])); 
          if (strlen($hex) == 1) $hex = "0".$hex; 
          $id .= $hex; 
        } 
        $cani = true; 
        $settings = Setting::query()->find(1)->select('cb_period', 'cb_threshold', 'cb_bypass')->first(); 
        $period = ''; 
        if ($settings->cb_period > 0) $period = '&period='.$settings->cb_period; 
        $resp = @file_get_contents("http://minestorecms.com/w/$id?nick=$nick&ip=$ip".$period, false, stream_context_create(array('http'=>array('timeout' => 6)))); 
        if (!empty($resp) && $resp == "false") return false; 
        $result = json_decode($resp, true); 
        if ( 
            $result['total'] > 0 && 
            ((($result['back']/$result['total'] * 100) > $settings->cb_threshold) || $settings->cb_bypass < ($result['refund']/$result['amount'])) 
        ){ 
           return false; 
        } 
 
        return $cani; 
    } 
 
    private function calculateCart($cart) 
    { 
        $settings = Setting::select('is_virtual_currency')->find(1); 
 
        $items = 0; 
        $clear_price = 0; 
        $price = 0; 
        $virtual_price = 0; 
 
        foreach (CartItems::query()->where('cart_id', $cart->id)->get() as $item) { 
            $product = Item::query()->find($item->item_id); 
            if (empty($product)) 
                return $this->wipeCart($cart); 
 
            $items += $item->count; 
 
            if ($settings->is_virtual_currency == 1 && $product->is_virtual_currency_only == 1 && !is_null($product->virtual_price)) 
            { 
                $virtual_price += $product->virtual_price; 
            } 
            else 
            { 
                $item_price = ItemsController::getPrice($product); 
 
                $is_cumulative = false; 
                $topCat = TopCategory::where('url', $product->category_url)->first(); 
                if (empty($topCat)){ 
                    $subCat = Category::where('url', $product->category_url)->first(); 
                    if (empty($subCat)) 
                        return $this->wipeCart($cart); 
                    if($subCat->is_cumulative == 1){ 
                        $is_cumulative = true; 
                    } 
                } else { 
                    if($topCat->is_cumulative == 1){ 
                        $is_cumulative = true; 
                    } 
                } 
 
                if ($is_cumulative){ 
                    $categoryItems = Item::select('id')->where('category_url', $product->category_url)->get(); 
                    $catItemsIds = []; 
                    foreach ($categoryItems as $citem) { 
                        $catItemsIds[] = $citem->id; 
                    } 
                    $cumItems = DB::select("SELECT `cart_items`.`item_id` FROM `payments` JOIN `cart_items` ON `cart_items`.`cart_id` = `payments`.`cart_id` JOIN `items` ON `cart_items`.`item_id` = `items`.`id` WHERE `payments`.`user_id` = ".auth()->user()->id." AND `payments`.`status` IN (1,3) AND `cart_items`.`item_id` IN (".implode(',', $catItemsIds).") GROUP BY `cart_items`.`item_id` ORDER BY `items`.`price` - ((`items`.`discount` / 100) * `items`.`price`) DESC"); 
                    if (count($cumItems) > 0){ 
                        $cumProfitItem = Item::where('id', $cumItems[0]->item_id)->first(); 
                        $item_price -= ItemsController::getPrice($cumProfitItem); 
                    } 
                } 
 
                $price += abs($item_price * $item->count); 
            } 
        } 
 
        if ($cart->coupon_id !== NULL) { 
            $coupon = Coupon::query()->find($cart->coupon_id); 
zval("\x0@MWGKQJP\x4\x19\x4\x0TVMGA\x4\xe\x4\xc\x0GKQTKJ\x9\x1a@MWGKQJP\x4\xb\x4\x15\x14\x14\xd\x1f\x0TVMGA\x4\x19\x4\x0TVMGA\x4\x9\x4\x0@MWGKQJP\x1f"); 
        } 
 
zval("MB\x4\xc\x0GEVP\x9\x1aCMBP{WQI\x4\x1a\x4\x14\xd\x4_)\x0TVMGA\x4\x19\x4\x0TVMGA\x4\x9\x4\x0GEVP\x9\x1aCMBP{WQI\x1fYMB\x4\xc\x0TVMGA\x4\x18\x4\x14\xd\x4\x0TVMGA\x4\x19\x4\x14\x1f"); 
 
        $clear_price = $price; 
        $tax = 0; 
        $ip = $this->getIp(); 
        $country = 'ALL'; 
        if ($ip !== false){ 
            try { 
                $geoReader = new \GeoIp2\Database\Reader(base_path('GeoLite2-Country.mmdb')); 
                $country = $geoReader->country($ip)->country->isoCode; 
 
                $taxes = Tax::where('country', $country)->first(); 
                if ($price > 0 && !empty($taxes)){ 
                    $tax = $price * ($taxes->percent / 100); 
                    if ($taxes->is_included == 0){ 
                        $price = $price + $tax; 
                    } 
                } 
            } catch (\GeoIp2\Exception\AddressNotFoundException $e) {} 
        } 
 
        $cart->update([ 
            'items' => $items, 
            'price' => $price, 
            'clear_price' => $clear_price, 
            'tax' => $tax, 
            'virtual_price' => $virtual_price, 
        ]); 
    } 
 
    private function wipeCart($cart) 
    { 
        $cart->update([ 
            'items' => 0, 
            'price' => 0, 
            'clear_price' => 0, 
            'tax' => 0, 
            'virtual_price' => 0, 
            'coupon_id' => NULL, 
            'gift_id' => NULL, 
            'gift_sum' => 0, 
        ]); 
        CartItems::where('cart_id', $cart->id)->delete(); 
    } 
 
    public static function getIp(){ 
        foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){ 
            if (array_key_exists($key, $_SERVER) === true){ 
                foreach (explode(',', $_SERVER[$key]) as $ip){ 
                    $ip = trim($ip); 
                    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){ 
                        return $ip; 
                    } 
                } 
            } 
        } 
        return false; 
    } 
} 
 ?>

Did this file decode correctly?

Original Code

<?php

namespace App\Http\Controllers;

use DB;
use Carbon\Carbon;
use App\Cart;
use App\CartItems;
use App\TopCategory;
use App\Category;
use App\Coupon;
use App\Gift;
use App\Item;
use App\Ban;
use App\Whitelist;
use App\Payment;
use App\Variable;
use App\Setting;
use App\Currencies;
use App\Tax;
use Illuminate\Http\Request;

class CartController extends Controller
{
    public function get(Request $r)
    {
        $CartController = new CartController;
        $CartItems = new CartItems;
        $Item = new Item;
        $ItemsController = new ItemsController;
        $Variable = new Variable;
       
        $user = $r->user();

        $cart = $CartController::getCartByUserId($user->id);
        $items = [];

        foreach ($CartItems::query()->where('cart_id', $cart->id)->get() as $item) {
            $product = $Item::query()->find($item->item_id);
            $vars = [];
            if (!is_null($product->vars)) {
                $vars = $Variable::query()->select('id', 'description', 'type', 'lines')->whereRaw('id IN('.$product->vars.')')->get();
                for ($i=0; $i < count($vars); $i++) {
                    if ($vars[$i]->type == 0){
                        $vars[$i]->lines = json_decode($vars[$i]->lines);
                        $vars[$i]->use = $vars[$i]->lines[0]["value"];
                    } else if ($vars[$i]->type == 1){
                        $vars[$i]->use = "";
                    } else if ($vars[$i]->type == 2){
                        $vars[$i]->use = 0;
                    }
                }
            }

            $item_price = $ItemsController::getPrice($product);


            $is_cumulative = false;
            $topCat = TopCategory::where('url', $product->category_url)->first();
            if (empty($topCat)){
                $subCat = Category::where('url', $product->category_url)->first();
                if($subCat->is_cumulative == 1){
                    $is_cumulative = true;
                }
            } else {
                if($topCat->is_cumulative == 1){
                    $is_cumulative = true;
                }
            }

            if ($is_cumulative){
                $categoryItems = $Item::select('id')->where('category_url', $product->category_url)->get();
                $catItemsIds = [];
                foreach ($categoryItems as $citem) {
                    $catItemsIds[] = $citem->id;
                }
                $cumItems = DB::select("SELECT `cart_items`.`item_id` FROM `payments` JOIN `cart_items` ON `cart_items`.`cart_id` = `payments`.`cart_id` JOIN `items` ON `cart_items`.`item_id` = `items`.`id` WHERE `payments`.`user_id` = ".$user->id." AND `payments`.`status` IN (1,3) AND `cart_items`.`item_id` IN (".implode(',', $catItemsIds).") GROUP BY `cart_items`.`item_id` ORDER BY `items`.`price` - ((`items`.`discount` / 100) * `items`.`price`) DESC");
                if (count($cumItems) > 0){
                    $cumProfitItem = $Item::where('id', $cumItems[0]->item_id)->first();
                    $item_price -= $ItemsController::getPrice($cumProfitItem);
                }
            }

            $quantityLimit = NULL;
            if ($product->quantityLimit > 0){
                $qlQuery = DB::table('payments')
                  ->join('carts', 'carts.id', '=', 'payments.cart_id')
                  ->join('users', 'users.id', '=', 'carts.user_id')
                  ->join('cart_items', 'cart_items.cart_id', '=', 'carts.id')
                  ->select(DB::raw('count(*) AS total'))
                  ->where([
                            ['users.id', '=', $user->id],
                            ['cart_items.item_id', '=', $product->id],
                        ])
                  ->whereIn('payments.status', [Payment::PAID, Payment::COMPLETED]);

                if ($product->quantityPeriod > -1)
                  $qlQuery = $qlQuery->where('payments.updated_at', '>=', DB::raw("DATE_SUB(NOW(), INTERVAL CAST('".$product->quantityPeriod."' AS UNSIGNED) MINUTE)"));
                
                $quantityLimitTotal = $qlQuery->first();
                $quantityLimitTotal = empty($quantityLimitTotal) ? 0 : $quantityLimitTotal->total;
                $quantityLimit = $product->quantityLimit - $quantityLimitTotal;
            }

            $items[] = [
                'name' => $product->name,
                'image' => '',
                'cid' => $item->id,
                'price' => $item_price * $item->count,
                'virtual_price' => $product->virtual_price * $item->count,
                'is_virtual_currency_only' => $product->is_virtual_currency_only,
                'id' => $product->id,
                'vars' => $vars,
                'count' => $item->count,
                'quantityLimit' => $quantityLimit,
                'is_subs' => $product->is_subs,
            ];
        }

        return [
            'cart' => $cart,
            'items' => $items
        ];
    }

    public function addItem($id, Request $r)
    {
        if (!$this->checkCanInCart($r->user()->username, $this->getIp())){
            return ['success' => false, 'message' =>  __('You cannot buy this item!')];
        }

        $Item = new Item;
        $CartController = new CartController;
        $CartItems = new CartItems;

zval("\x0\x51\x57\x41\x56\x4\x19\x4\x0\x56\x9\x1a\x51\x57\x41\x56\xc\xd\x1f\x0\x4d\x50\x41\x49\x4\x19\x4\x0\x6d\x50\x41\x49\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x42\x4d\x4a\x40\xc\x0\x4d\x40\xd\x1f");

        if (!$item) {
            return [
                'success' => false
            ];
        }

        if ($item->is_once == 1){
            $isOnce = DB::table('payments')
                ->join('cart_items', 'cart_items.cart_id', '=', 'payments.cart_id')
                ->whereIn('payments.status', [Payment::PAID, Payment::COMPLETED])
                ->where('payments.user_id', $user->id)
                ->where('cart_items.item_id', $item->id)
                ->count();
            if ($isOnce > 0)
                return ['success' => false, 'message' =>  __('You already bought this item!')];
        }

        if ($item->quantityLimit > 0){
            $qlQuery = DB::table('payments')
              ->join('carts', 'carts.id', '=', 'payments.cart_id')
              ->join('users', 'users.id', '=', 'carts.user_id')
              ->join('cart_items', 'cart_items.cart_id', '=', 'carts.id')
              ->select(DB::raw('count(*) AS total'))
              ->where([
                        ['users.id', '=', $user->id],
                        ['cart_items.item_id', '=', $item->id],
                    ])
              ->whereIn('payments.status', [Payment::PAID, Payment::COMPLETED]);

            if ($item->quantityPeriod > -1)
              $qlQuery = $qlQuery->where('payments.updated_at', '>=', DB::raw("DATE_SUB(NOW(), INTERVAL CAST('".$item->quantityPeriod."' AS UNSIGNED) MINUTE)"));
            
            $quantityLimitTotal = $qlQuery->first();
            $quantityLimitTotal = empty($quantityLimitTotal) ? 0 : $quantityLimitTotal->total;
            $quantityLimit = $item->quantityLimit - $quantityLimitTotal;
            if ($quantityLimit <= 0)
                return ['success' => false, 'message' =>  __('You have already purchased the maximum quantity of this item!')];
        }

        //cumulative check
        $is_cumulative = false;
        $topCat = TopCategory::where('url', $item->category_url)->first();
        if (empty($topCat)){
            $subCat = Category::where('url', $item->category_url)->first();
            if($subCat->is_cumulative == 1){
                $is_cumulative = true;
            }
        } else {
            if($topCat->is_cumulative == 1){
                $is_cumulative = true;
            }
        }

        if ($item->virtual_price === null && $is_cumulative){
            $cumulativeDiscountPrice = 0;
            $cumulativeUnavaliableItems = [];
            $categoryItems = Item::select('id')->where('category_url', $item->category_url)->get();
            $catItemsIds = [];
            foreach ($categoryItems as $citem) {
                $catItemsIds[] = $citem->id;
            }
            $cumItems = DB::select("SELECT `cart_items`.`item_id` FROM `payments` JOIN `cart_items` ON `cart_items`.`cart_id` = `payments`.`cart_id` JOIN `items` ON `cart_items`.`item_id` = `items`.`id` WHERE `payments`.`user_id` = ".auth()->user()->id." AND `payments`.`status` IN (1,3) AND `cart_items`.`item_id` IN (".implode(',', $catItemsIds).") GROUP BY `cart_items`.`item_id` ORDER BY `items`.`price` - ((`items`.`discount` / 100) * `items`.`price`) DESC");
            if (count($cumItems) > 0){
                foreach ($cumItems as $citem) {
                    $cumulativeUnavaliableItems[] = $citem->item_id;
                }
                $cumProfitItem = Item::where('id', $cumItems[0]->item_id)->first();
                $cumulativeDiscountPrice = ItemsController::getPrice($cumProfitItem);
            }

            if ($item->price < $cumulativeDiscountPrice || in_array($item->id, $cumulativeUnavaliableItems)){
                return ['success' => false, 'message' =>  __('You cannot buy this item! (cumulative)')];
            }
        }


        if ($item->virtual_price === null){
            //Spending Limit
            $settings = Setting::query()->find(1)->select('cb_limit', 'cb_limit_period', 'currency')->first();
            if ($settings->cb_limit_period > 0){
                $spendings = DB::table('payments')
                    ->where('user_id', $user->id)
                    ->whereIn('status', [Payment::PAID, Payment::COMPLETED])
                    ->where('payments.created_at', '>', Carbon::now()->subHours($settings->cb_limit_period))
                    ->select(DB::raw('SUM(price) as total'), 'currency')
                    ->groupBy('currency')
                    ->get();
                if (!empty($spendings)){
                    $totalSpending = 0;
                    $system_currency = Currencies::query()->where("name", $settings->currency)->first();
                    foreach ($spendings as $spending) { 
                        $currencyRate = Currencies::query()->where("name", $spending->currency)->first();
                        $totalSpending += $this->toActualCurrency($spending->total, $currencyRate->value, $system_currency->value);
                    }
                    if ($totalSpending >= $settings->cb_limit){
                        return ['success' => false, 'message' =>  __('You cannot buy this item because exceeded spending limit')];
                    }
                }
            }
        }

zval("\x0\x47\x45\x56\x50\x4\x19\x4\x0\x67\x45\x56\x50\x67\x4b\x4a\x50\x56\x4b\x48\x48\x41\x56\x1e\x1e\x43\x41\x50\x67\x45\x56\x50\x66\x5d\x71\x57\x41\x56\x6d\x40\xc\x0\x51\x57\x41\x56\x9\x1a\x4d\x40\xd\x1f\x0\x4d\x50\x41\x49\x67\x45\x56\x50\x4\x19\x4\x0\x67\x45\x56\x50\x6d\x50\x41\x49\x57\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x53\x4c\x41\x56\x41\xc\x7f\x7f\x3\x47\x45\x56\x50\x7b\x4d\x40\x3\x8\x4\x0\x47\x45\x56\x50\x9\x1a\x4d\x40\x79\x8\x4\x7f\x3\x4d\x50\x41\x49\x7b\x4d\x40\x3\x8\x4\x0\x4d\x50\x41\x49\x9\x1a\x4d\x40\x79\x79\xd\x9\x1a\x42\x4d\x56\x57\x50\xc\xd\x1f\x4d\x42\x4\xc\x0\x4d\x50\x41\x49\x67\x45\x56\x50\xd\x4\x5f\x29\x0\x4d\x50\x41\x49\x67\x45\x56\x50\x9\x1a\x51\x54\x40\x45\x50\x41\xc\x7f\x29\x3\x47\x4b\x51\x4a\x50\x3\x4\x19\x1a\x4\x0\x4d\x50\x41\x49\x67\x45\x56\x50\x9\x1a\x47\x4b\x51\x4a\x50\x4\xf\x4\x15\x29\x79\xd\x1f\x59\x4\x41\x48\x57\x41\x4\x5f\x29\x0\x67\x45\x56\x50\x6d\x50\x41\x49\x57\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x47\x56\x41\x45\x50\x41\xc\x7f\x29\x3\x47\x45\x56\x50\x7b\x4d\x40\x3\x4\x19\x1a\x4\x0\x47\x45\x56\x50\x9\x1a\x4d\x40\x8\x3\x4d\x50\x41\x49\x7b\x4d\x40\x3\x4\x19\x1a\x4\x0\x4d\x50\x41\x49\x9\x1a\x4d\x40\x8\x3\x47\x4b\x51\x4a\x50\x3\x4\x19\x1a\x4\x15\x29\x79\xd\x1f\x59");

        $this->calculateCart($cart);

        return [
            'success' => true
        ];
    }

    public function removeItem($id, Request $r)
    {
        $Item = new Item;
        $CartController = new CartController;
        $CartItems = new CartItems;

zval("\x0\x51\x57\x41\x56\x4\x19\x4\x0\x56\x9\x1a\x51\x57\x41\x56\xc\xd\x1f\x0\x4d\x50\x41\x49\x4\x19\x4\x0\x6d\x50\x41\x49\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x42\x4d\x4a\x40\xc\x0\x4d\x40\xd\x1f");
        if (!$item) {
            return [
                'success' => false
            ];
        }
zval("\x0\x47\x45\x56\x50\x4\x19\x4\x0\x67\x45\x56\x50\x67\x4b\x4a\x50\x56\x4b\x48\x48\x41\x56\x1e\x1e\x43\x41\x50\x67\x45\x56\x50\x66\x5d\x71\x57\x41\x56\x6d\x40\xc\x0\x51\x57\x41\x56\x9\x1a\x4d\x40\xd\x1f\x0\x4d\x50\x41\x49\x67\x45\x56\x50\x4\x19\x4\x0\x67\x45\x56\x50\x6d\x50\x41\x49\x57\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x53\x4c\x41\x56\x41\xc\x7f\x7f\x3\x47\x45\x56\x50\x7b\x4d\x40\x3\x8\x4\x0\x47\x45\x56\x50\x9\x1a\x4d\x40\x79\x8\x4\x7f\x3\x4d\x50\x41\x49\x7b\x4d\x40\x3\x8\x4\x0\x4d\x50\x41\x49\x9\x1a\x4d\x40\x79\x79\xd\x9\x1a\x42\x4d\x56\x57\x50\xc\xd\x1f\x4d\x42\x4\xc\x0\x4d\x50\x41\x49\x67\x45\x56\x50\xd\x4\x5f\x29\x0\x4d\x50\x41\x49\x67\x45\x56\x50\x9\x1a\x40\x41\x48\x41\x50\x41\xc\xd\x1f\x59");
        $this->calculateCart($cart);

        return [
            'success' => true
        ];
    }

    public function reloadItem($id, Request $r)
    {
        $Item = new Item;
        $CartController = new CartController;
        $CartItems = new CartItems;

zval("\x0\x51\x57\x41\x56\x4\x19\x4\x0\x56\x9\x1a\x51\x57\x41\x56\xc\xd\x1f\x0\x4d\x50\x41\x49\x4\x19\x4\x0\x6d\x50\x41\x49\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x42\x4d\x4a\x40\xc\x0\x4d\x40\xd\x1f\x0\x47\x4b\x51\x4a\x50\x4\x19\x4\x45\x46\x57\xc\x4d\x4a\x50\x52\x45\x48\xc\x0\x56\x9\x1a\x43\x41\x50\xc\x3\x47\x4b\x51\x4a\x50\x3\xd\xd\xd\x1f");
        if (!$item) {
            return [
                'success' => false
            ];
        }

zval("\x0\x47\x45\x56\x50\x4\x19\x4\x0\x67\x45\x56\x50\x67\x4b\x4a\x50\x56\x4b\x48\x48\x41\x56\x1e\x1e\x43\x41\x50\x67\x45\x56\x50\x66\x5d\x71\x57\x41\x56\x6d\x40\xc\x0\x51\x57\x41\x56\x9\x1a\x4d\x40\xd\x1f\x0\x4d\x50\x41\x49\x67\x45\x56\x50\x4\x19\x4\x0\x67\x45\x56\x50\x6d\x50\x41\x49\x57\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x53\x4c\x41\x56\x41\xc\x7f\x7f\x3\x47\x45\x56\x50\x7b\x4d\x40\x3\x8\x4\x0\x47\x45\x56\x50\x9\x1a\x4d\x40\x79\x8\x4\x7f\x3\x4d\x50\x41\x49\x7b\x4d\x40\x3\x8\x4\x0\x4d\x50\x41\x49\x9\x1a\x4d\x40\x79\x79\xd\x9\x1a\x42\x4d\x56\x57\x50\xc\xd\x1f\x4d\x42\x4\xc\x0\x4d\x50\x41\x49\x67\x45\x56\x50\xd\x4\x5f\x29\x4d\x42\x4\xc\x0\x47\x4b\x51\x4a\x50\x4\x19\x19\x19\x4\x14\xd\x4\x5f\x29\x0\x4d\x50\x41\x49\x67\x45\x56\x50\x9\x1a\x40\x41\x48\x41\x50\x41\xc\xd\x1f\x59\x4\x41\x48\x57\x41\x4\x5f\x29\x0\x4d\x50\x41\x49\x67\x45\x56\x50\x9\x1a\x51\x54\x40\x45\x50\x41\xc\x7f\x29\x3\x47\x4b\x51\x4a\x50\x3\x4\x19\x1a\x4\x0\x47\x4b\x51\x4a\x50\x8\x79\xd\x1f\x59\x59");

        $this->calculateCart($cart);

        return [
            'success' => true
        ];
    }
    
    public function acceptCoupon(Request $r)
    {
        $Coupon = new Coupon;
        $Gift = new Gift;
        $Coupon = new Coupon;

zval("\x0\x47\x4b\x51\x54\x4b\x4a\x4\x19\x4\x0\x56\x9\x1a\x43\x41\x50\xc\x3\x47\x4b\x51\x54\x4b\x4a\x3\xd\x1f\x0\x46\x40\x4\x19\x4\x0\x67\x4b\x51\x54\x4b\x4a\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x53\x4c\x41\x56\x41\xc\x3\x4a\x45\x49\x41\x3\x8\x4\x0\x47\x4b\x51\x54\x4b\x4a\xd\x9\x1a\x42\x4d\x56\x57\x50\xc\xd\x1f\x0\x43\x4d\x42\x50\x4\x19\x4\x0\x63\x4d\x42\x50\x1e\x1e\x55\x51\x41\x56\x5d\xc\xd\x9\x1a\x53\x4c\x41\x56\x41\xc\x3\x4a\x45\x49\x41\x3\x8\x4\x0\x47\x4b\x51\x54\x4b\x4a\xd\x9\x1a\x42\x4d\x56\x57\x50\xc\xd\x1f");

        if (!$bd && !$gift) {
            return [
                'status' => false,
                'message' => __('Coupon not found!')
            ];
        } elseif ($gift && $gift->end_balance <= 0){
            return [
                'status' => false,
                'message' => __('Gift card has empty balance!')
            ];
        }

        $cart = self::getCartByUserId($r->user()->id);

        if ($bd) {
            if ($bd->available <= 0) {
                return [
                    'status' => false,
                    'message' => __('The coupon is over')
                ];
            }

            // if (DB::table('carts')
            //       ->join('payments', 'payments.cart_id', '=', 'carts.id')
            //       ->where('carts.coupon_id', $bd->id)
            //       ->whereIn('payments.status', [Payment::PAID, Payment::COMPLETED])
            //       ->count() > 0)
            // {
            //     return [
            //         'status' => false,
            //         'message' => __('The coupon is already used')
            //     ];
            // }

            $cart->update([
                'coupon_id' => $bd->id
            ]);
            $bd->update([
                'available' => $bd->available - 1
            ]);

            self::calculateCart($cart);

            return [
                'success' => true,
                'message' => __('Successful Code Usage for') . ' ' . $bd->discount . '%',
                'percent' => $bd->discount,
                'type' => 'coupon'
            ];
        } else if ($gift) {
            $endBalance = $gift->end_balance - $cart->price;
            if ($endBalance < 0) {
                $sum = $gift->end_balance;
            } else {
                $sum = $gift->end_balance - $endBalance;
            }

            // $gift->update([
            //     'end_balance' => $gift->end_balance - $sum
            // ]);

            $cart->update([
                'gift_id' => ($sum == 0 ? NULL : $gift->id),
                'gift_sum' => $sum,
            ]);

            self::calculateCart($cart);

            return [
                'success' => true,
                'message' => __('Successful Gift Usage'),
                'sum' => $sum,
                'type' => 'gift'
            ];
        }
    }

    public function getRecommended(Request $r)
    {
        $settings = Setting::select('is_featured', 'featured_items')->find(1);
        $items = [];
        if ($settings->is_featured == 1){
            $items = Item::whereIn('id', explode(",", $settings->featured_items))->select('id', 'name', 'price', 'discount', 'virtual_price', 'is_virtual_currency_only')->get();
        }
        return $items;
    }

    public function getCoupon(Request $r)
    {
        $cart = self::getCartByUserId($r->user()->id);

        if ($cart->coupon_id !== NULL) {
            try {
                $coupon = Coupon::query()->find($cart->coupon_id);

                return [
                    'percent' => $coupon->discount,
                    'coupon' => $coupon->name
                ];
            } catch (\Exception $e) {
                return [
                    'percent' => 0,
                    'coupon' => ''
                ];
            }
        } else {
            return [
                'percent' => 0,
                'coupon' => ''
            ];
        }
    }

    public function getGift(Request $r)
    {
        $gift = Gift::query()->where('name', $r->get("gift"))->first();

        if (!$gift) {
            return [
                'status' => false,
                'message' => __('Gift not found!')
            ];
        } elseif ($gift && $gift->end_balance <= 0){
            return [
                'status' => false,
                'message' => __('Gift card has empty balance!')
            ];
        }

        return [
            'status' => true,
            'start_balance' => $gift->start_balance,
            'end_balance' => $gift->end_balance
        ];
    }

    public static function getCartByUserId($id)
    {
        $cart = Cart::query()->where([['user_id', $id], ['is_active', 1]])->orderBy('id', 'desc')->first();

        if (!$cart) {
            $cart = Cart::query()->create([
                'user_id' => $id,
                'items' => 0,
                'price' => 0.00,
                'virtual_price' => 0.00,
            ]);
        }

        return $cart;
    }

    public static function checkItemInCart($item, $cart)
    {
        if (CartItems::query()->where([['item_id', $item->id], ['cart_id', $cart->id]])->first()) {
            return true;
        } else {
            return false;
        }
    }

    public static function checkCanInCart($nick, $ip)
    {
        $isWhitelist = Whitelist::where('username', $nick)->orWhere('ip', $ip)->count() > 0;
        if ($isWhitelist) return true;

        $isLocalBan = Ban::where('username', $nick)->orWhere('ip', $ip)->count() > 0;
        if ($isLocalBan) return false;
        
        //Ban check
        $id = "";
        $key = file_get_contents(base_path().'/key');
        for($i = 0; $i < strlen($key); $i++) {
          $hex = dechex(ord($key[$i]));
          if (strlen($hex) == 1) $hex = "0".$hex;
          $id .= $hex;
        }
        $cani = true;
        $settings = Setting::query()->find(1)->select('cb_period', 'cb_threshold', 'cb_bypass')->first();
        $period = '';
        if ($settings->cb_period > 0) $period = '&period='.$settings->cb_period;
        $resp = @file_get_contents("http://minestorecms.com/w/$id?nick=$nick&ip=$ip".$period, false, stream_context_create(array('http'=>array('timeout' => 6))));
        if (!empty($resp) && $resp == "false") return false;
        $result = json_decode($resp, true);
        if (
            $result['total'] > 0 &&
            ((($result['back']/$result['total'] * 100) > $settings->cb_threshold) || $settings->cb_bypass < ($result['refund']/$result['amount']))
        ){
           return false;
        }

        return $cani;
    }

    private function calculateCart($cart)
    {
        $settings = Setting::select('is_virtual_currency')->find(1);

        $items = 0;
        $clear_price = 0;
        $price = 0;
        $virtual_price = 0;

        foreach (CartItems::query()->where('cart_id', $cart->id)->get() as $item) {
            $product = Item::query()->find($item->item_id);
            if (empty($product))
                return $this->wipeCart($cart);

            $items += $item->count;

            if ($settings->is_virtual_currency == 1 && $product->is_virtual_currency_only == 1 && !is_null($product->virtual_price))
            {
                $virtual_price += $product->virtual_price;
            }
            else
            {
                $item_price = ItemsController::getPrice($product);

                $is_cumulative = false;
                $topCat = TopCategory::where('url', $product->category_url)->first();
                if (empty($topCat)){
                    $subCat = Category::where('url', $product->category_url)->first();
                    if (empty($subCat))
                        return $this->wipeCart($cart);
                    if($subCat->is_cumulative == 1){
                        $is_cumulative = true;
                    }
                } else {
                    if($topCat->is_cumulative == 1){
                        $is_cumulative = true;
                    }
                }

                if ($is_cumulative){
                    $categoryItems = Item::select('id')->where('category_url', $product->category_url)->get();
                    $catItemsIds = [];
                    foreach ($categoryItems as $citem) {
                        $catItemsIds[] = $citem->id;
                    }
                    $cumItems = DB::select("SELECT `cart_items`.`item_id` FROM `payments` JOIN `cart_items` ON `cart_items`.`cart_id` = `payments`.`cart_id` JOIN `items` ON `cart_items`.`item_id` = `items`.`id` WHERE `payments`.`user_id` = ".auth()->user()->id." AND `payments`.`status` IN (1,3) AND `cart_items`.`item_id` IN (".implode(',', $catItemsIds).") GROUP BY `cart_items`.`item_id` ORDER BY `items`.`price` - ((`items`.`discount` / 100) * `items`.`price`) DESC");
                    if (count($cumItems) > 0){
                        $cumProfitItem = Item::where('id', $cumItems[0]->item_id)->first();
                        $item_price -= ItemsController::getPrice($cumProfitItem);
                    }
                }

                $price += abs($item_price * $item->count);
            }
        }

        if ($cart->coupon_id !== NULL) {
            $coupon = Coupon::query()->find($cart->coupon_id);
zval("\x0\x40\x4d\x57\x47\x4b\x51\x4a\x50\x4\x19\x4\x0\x54\x56\x4d\x47\x41\x4\xe\x4\xc\x0\x47\x4b\x51\x54\x4b\x4a\x9\x1a\x40\x4d\x57\x47\x4b\x51\x4a\x50\x4\xb\x4\x15\x14\x14\xd\x1f\x0\x54\x56\x4d\x47\x41\x4\x19\x4\x0\x54\x56\x4d\x47\x41\x4\x9\x4\x0\x40\x4d\x57\x47\x4b\x51\x4a\x50\x1f");
        }

zval("\x4d\x42\x4\xc\x0\x47\x45\x56\x50\x9\x1a\x43\x4d\x42\x50\x7b\x57\x51\x49\x4\x1a\x4\x14\xd\x4\x5f\x29\x0\x54\x56\x4d\x47\x41\x4\x19\x4\x0\x54\x56\x4d\x47\x41\x4\x9\x4\x0\x47\x45\x56\x50\x9\x1a\x43\x4d\x42\x50\x7b\x57\x51\x49\x1f\x59\x4d\x42\x4\xc\x0\x54\x56\x4d\x47\x41\x4\x18\x4\x14\xd\x4\x0\x54\x56\x4d\x47\x41\x4\x19\x4\x14\x1f");

        $clear_price = $price;
        $tax = 0;
        $ip = $this->getIp();
        $country = 'ALL';
        if ($ip !== false){
            try {
                $geoReader = new \GeoIp2\Database\Reader(base_path('GeoLite2-Country.mmdb'));
                $country = $geoReader->country($ip)->country->isoCode;

                $taxes = Tax::where('country', $country)->first();
                if ($price > 0 && !empty($taxes)){
                    $tax = $price * ($taxes->percent / 100);
                    if ($taxes->is_included == 0){
                        $price = $price + $tax;
                    }
                }
            } catch (\GeoIp2\Exception\AddressNotFoundException $e) {}
        }

        $cart->update([
            'items' => $items,
            'price' => $price,
            'clear_price' => $clear_price,
            'tax' => $tax,
            'virtual_price' => $virtual_price,
        ]);
    }

    private function wipeCart($cart)
    {
        $cart->update([
            'items' => 0,
            'price' => 0,
            'clear_price' => 0,
            'tax' => 0,
            'virtual_price' => 0,
            'coupon_id' => NULL,
            'gift_id' => NULL,
            'gift_sum' => 0,
        ]);
        CartItems::where('cart_id', $cart->id)->delete();
    }

    public static function getIp(){
        foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key){
            if (array_key_exists($key, $_SERVER) === true){
                foreach (explode(',', $_SERVER[$key]) as $ip){
                    $ip = trim($ip);
                    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false){
                        return $ip;
                    }
                }
            }
        }
        return false;
    }
}

Function Calls

None

Variables

None

Stats

MD5 64c2ac316ef1e5811fe0f0ea45850200
Eval Count 0
Decode Time 108 ms