| Server IP : 103.161.17.216 / Your IP : 216.73.216.1 Web Server : nginx/1.18.0 System : Linux tipsysaigoncharming 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/applehotel.vn/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Models\Category;
use App\Models\Product;
use App\Models\Slider;
use App\Models\CatePost;
use App\Models\Cate;
use App\Models\Attr;
use Session;
use App\Imports\ExcelImports;
use App\Exports\ExcelExports;
use Excel;
use Illuminate\Support\Facades\Redirect;
use App\Http\Controllers\Controller;
session_start();
class CategoryProduct extends Controller
{
//xac thuc dang nhap
public function AuthLogin() {
$admin_id=session::get('admin_id');
if($admin_id){
return Redirect::to('dashboard');
}
else{
return Redirect::to('admin')->send();
}
}
//them chủng loại sp
public function add_cate_product(){
$cate=Cate::orderby('cate_id','DESC')->get();
return view('admin.category.add_cate')->with(compact('cate'));
}
public function save_cate_product(Request $Request){
$this->AuthLogin();
$data=$Request->all();
$Cate=new Cate();
$Cate->cate_name=$data['cate_product_name'];
$Cate->slug_cate_product=$data['slug_cate_product'];
$Cate->cate_desc=$data['cate_product_desc'];
$Cate->cate_status=$data['cate_product_status'];
$Cate->meta_keywords=$data['cate_product_keywords'];
$Cate->save();
Session::put('message', 'Thêm chủng loại sản phẩm thành công');
return Redirect::to('/all-cate-product');
}
public function all_cate_product(){
$this->AuthLogin();
$all_cate_product=Cate::orderby('cate_id','DESC')->get();
return view('admin.category.all_cate')->with(compact('all_cate_product'));
}
public function unactive_cate_product($cate_product_id){
$this->AuthLogin();
DB::table('tbl_category')->where('cate_id',$cate_product_id)->update(['cate_status'=>1]);
Session::put('message', 'Không kích hoạt thành công trạng thái');
return Redirect::to('/all-cate-product');
}
//kich hoat trang thai
public function active_cate_product($cate_product_id){
$this->AuthLogin();
DB::table('tbl_category')->where('cate_id',$cate_product_id)->update(['cate_status'=>0]);
Session::put('message', 'Không kích hoạt thành công trạng thái');
return Redirect::to('/all-cate-product');
}
//chinh sua danh muc
public function edit_cate_product($cate_product_id){
$this->AuthLogin();
$cate=Cate::orderby('cate_id','DESC')->get();
$category=Category::orderby('category_id','DESC')->get();
$edit_cate_product=Cate::find($cate_product_id);
return view('admin.category.edit_cate')->with(compact('edit_cate_product','category','cate'));
// $edit_category_product= DB::table('tbl_category_product')->where('category_id',$category_product_id)->get();
//$manager_category_product = view('admin.edit_category_product')->with('edit_category_product',$edit_category_product);
//return view('admin_layout')->with('admin.edit_category_product', $manager_category_product);
//
}
//cap nhat danh muc
public function update_cate_product(Request $Request, $cate_product_id){
$this->AuthLogin();
$data=$Request->all();
$Cate=Cate::find($cate_product_id);
$Cate->cate_name=$data['cate_product_name'];
$Cate->slug_cate_product=$data['slug_cate_product'];
$Cate->cate_desc=$data['cate_product_desc'];
$Cate->meta_keywords=$data['cate_product_keywords'];
$Cate->save();
// $data=array();
// $data['category_name']=$Request->category_product_name;
// $data['category_desc']=$Request->category_product_desc;
// $data['slug_category_product']=$Request->slug_category_product;
// $data['meta_keywords']=$Request->category_product_keywords;
// DB::table('tbl_category_product')->where('category_id',$category_product_id)->update($data);
Session::put('message', 'cập nhật thành công');
return Redirect::to('/all-cate-product');
}
//xoa danh muc
public function delete_cate_product($cate_product_id) {
$this->AuthLogin();
DB::table('tbl_category')->where('cate_id',$cate_product_id)->delete();
Session::put('message', 'xóa thành thành công');
return Redirect::to('/all-cate-product');
}
// ----- end chủng loại sản phẩm
//them loại sản phẩm
public function add_category_product(){
$category=Category::orderby('category_id','DESC')->get();
$cate=Cate::orderby('cate_id','DESC')->get();
return view('admin.category.add_category_product')->with(compact('category','cate'));
// hien thi toan bo danh muc
}
public function all_category_product(){
$this->AuthLogin();
$cate1=Cate::orderby('cate_id','DESC')->get();
$all_category_product=Category::orderby('category_id','DESC')->get();
return view('admin.category.all_category_product')->with(compact('all_category_product','cate1'));
//$all_category_product= DB::table('tbl_category_product')->orderby('category_id','desc')->get();
// $manager_category_product = view('admin.all_category_product')->with('all_category_product',$all_category_product);
}
public function save_category_product(Request $Request){
$this->AuthLogin();
$data=$Request->all();
$Category=new Category();
$Category->category_name=$data['category_product_name'];
$Category->slug_category_product=$data['slug_category_product'];
$Category->category_desc=$data['category_product_desc'];
$Category->category_status=$data['category_product_status'];
$Category->cate_id=$data['cate'];
$Category->meta_keywords=$data['category_product_keywords'];
$get_image=$Request->file('category_product_image');
if ($get_image){
$get_name_image = $get_image->getClientOriginalName(); //lay ten của hình ảnh
$name_image = current(explode('.',$get_name_image));
$new_image = $name_image.rand(0,99).'.'.$get_image->getClientOriginalExtension();
$get_image->move('public/uploads/product',$new_image);
$Category->category_image =$new_image;
$Category->save();
// $data=array();
// $data['category_name']=$Request->category_product_name;
// $data['category_desc']=$Request->category_product_desc;
// $data['slug_category_product']=$Request->slug_category_product;
// $data['meta_keywords']=$Request->category_product_keywords;
// $data['category_status']=$Request->category_product_status;
// DB::table('tbl_category_product')->insert($data);
Session::put('message', 'Thêm danh mục sản phẩm thành công');
return Redirect::to('/all-category-product');
}
}
//kich hoat trang thai
public function unactive_category_product($category_product_id){
$this->AuthLogin();
DB::table('tbl_category_product')->where('category_id',$category_product_id)->update(['category_status'=>1]);
Session::put('message', 'Không kích hoạt thành công trạng thái');
return Redirect::to('/all-category-product');
}
//kich hoat trang thai
public function active_category_product($category_product_id){
$this->AuthLogin();
DB::table('tbl_category_product')->where('category_id',$category_product_id)->update(['category_status'=>0]);
Session::put('message', 'Không kích hoạt thành công trạng thái');
return Redirect::to('/all-category-product');
}
//chinh sua danh muc
public function edit_category_product($category_product_id){
$this->AuthLogin();
$cate=Cate::orderby('cate_id','DESC')->get();
$category=Category::orderby('category_id','DESC')->get();
$edit_category_product=Category::find($category_product_id);
return view('admin.category.edit_category_product')->with(compact('edit_category_product','category','cate'));
// $edit_category_product= DB::table('tbl_category_product')->where('category_id',$category_product_id)->get();
//$manager_category_product = view('admin.edit_category_product')->with('edit_category_product',$edit_category_product);
//return view('admin_layout')->with('admin.edit_category_product', $manager_category_product);
//
}
//cap nhat danh muc
public function update_category_product(Request $Request,$category_id){
$this->AuthLogin();
$data=$Request->all();
$Category=Category::find($category_id);
$Category->category_name=$data['category_product_name'];
$Category->category_desc=$data['category_product_desc'];
$Category->slug_category_product=$data['slug_category_product'];
$Category->cate_id=$data['cate'];
$Category->meta_keywords=$data['category_product_keywords'];
$get_image=$Request->file('category_image');
if ($get_image){
$get_name_image = $get_image->getClientOriginalName(); //lay ten của hình ảnh
$name_image = current(explode('.',$get_name_image));
$new_image = $name_image.rand(0,99).'.'.$get_image->getClientOriginalExtension();
$get_image->move('public/uploads/product',$new_image);
$Category->category_image =$new_image;
$Category->update();
// $data=array();
// $data['category_name']=$Request->category_product_name;
// $data['category_desc']=$Request->category_product_desc;
// $data['slug_category_product']=$Request->slug_category_product;
// $data['meta_keywords']=$Request->category_product_keywords;
// DB::table('tbl_category_product')->where('category_id',$category_product_id)->update($data);
Session::put('message', 'cập nhật thành công');
return Redirect::to('/all-category-product');
}
}
//xoa danh muc
public function delete_category_product($category_product_id) {
$this->AuthLogin();
$category=Category::find($category_product_id);
unlink('public/uploads/product/'.$category->category_image);
$category->delete();
// DB::table('tbl_category_product')->where('category_id',$category_product_id)->delete();
Session::put('message', 'xóa thành thành công');
return Redirect::to('/all-category-product');
}
//end function admin page
////(lấy dữ liệu cho trang hiễn thị sản phẩm theo danh muc)
public function show_category_home(Request $request) {
$url=$request->segment(2);
$url=preg_split('/(-)/i', $url);
if ($category_id=array_pop($url)){
$category_by_id=Product::where('category_id',$category_id)->orderby('product_id','DESC')->get();
// foreach( $category_by_id as $product) {
// $product_id= $product->product_id;
// $all_attr=Attr::where('product_id',$product_id)->with('product')->get();
// echo '<pre>';
// print_r($all_attr);
// echo '</pre>';
if($request->orderby ){
$orderby=$request->orderby;
switch($orderby)
{
case 'desc';
$all_attr =Attr::orderby('attr_id','desc')->with('product')->get();
break;
case 'asc';
$all_attr =Attr::orderby('attr_id','asc')->with('product')->get();
break;
case 'price_max';
$all_attr =Attr::orderby('product_price','asc')->with('product')->get();
break;
case 'price_min';
$all_attr =Attr::orderby('product_price','desc')->with('product')->get();
break;
default:
$all_attr =Attr::orderby('product_id','desc',)->with('product')->get();
}
}
if($request->price ){
$price=$request->price;
switch($price)
{
case(1);
$all_attr =Attr::where('product_price','<','200000',)->with('product')->get();
break;
case(2);
$all_attr =Attr::whereBetween('product_price',[200000,400000])->with('product')->get();
break;
case(3);
$all_attr =Attr::whereBetween('product_price',[400000,600000])->with('product')->get();
break;
case(4);
$all_attr =Attr::whereBetween('product_price',[6000,800000])->with('product')->get();
break;
case(5);
$all_attr =Attr::where('product_price','>','800000',)->with('product')->get();
break;
}
}
elseif (!$request->price &&!$request->orderby) {
$all_attr =Attr::orderby('attr_id','asc')->with('product')->get();
// echo '<pre>';
// print_r($all_attr);
// echo '</pre>';
}
}
$slide =Slider::orderby('slider_id','desc')->get();
$cate=Cate::orderby('cate_id','ASC')->get();
$cate_product=Category::where('category_status','1')->orderby('category_id','desc')->with('cate')->get();
$brand_product=DB::table('tbl_brand')->where('brand_status','1')->orderby('brand_id','desc')->get();
$all_product=DB::table('tbl_product')->where('product_status','1')->orderby('product_id','desc')->get();
$category_post = CatePost::orderBy('cate_post_id','DESC')->get();
// $all_attr=Attr::with('product')->get();
// $category_by_id=Product::where('product_status','1')->join('tbl_category_product','tbl_product.category_id','=','tbl_category_product.category_id')->where('tbl_category_product.slug_category_product',$slug_category_product)->get();
// $category_by_id=DB::table('tbl_product')->where('product_status','1')->join('tbl_category_product','tbl_product.category_id','=','tbl_category_product.category_id')->where('tbl_category_product.slug_category_product',$slug_category_product)->get();
$meta_desc=collect();
$meta_keywords=collect();
$meta_title=collect();
$url_canonical=collect();
foreach ($category_by_id as $key => $val) {
$meta_desc=$val->category_desc;
$meta_keywords=$val->meta_keywords;
$meta_title=$val->category_name;
$url_canonical= $request->url();
}
$category_name = DB::table('tbl_category_product')->where('tbl_category_product.category_id',$category_id)->limit(1)->get();
return view('pages.category.show_category')->with(compact('cate_product','brand_product','category_name','category_by_id','meta_keywords','meta_desc','meta_title','url_canonical','all_product','all_attr','cate','slide','category_post'));
// return view('pages.category.show_category')->with('meta_keywords',$meta_keywords)->with('meta_desc',$meta_desc)->with('meta_title',$meta_title)->with('url_canonical',$url_canonical)->with(compact('cate_product','brand_product','category_name','category_by_id',));
// return view('pages.category.show_category')->with('category',$cate_product)->with('brand',$brand_product)->with('category_by_id',$category_by_id)->with('category_name',$category_name); cach 1
}
//import &export data
public function export_csv(){
return Excel::download(new ExcelExports , 'product.xlsx');
}
public function import_csv(Request $request){
// $path = $request->file('file')->getRealPath();
$path1 = $request->file('file')->store('temp');
$path=storage_path('app').'/'.$path1;
$data=Excel::import(new ExcelImports, $path);
return back();
}
}