| 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/huyhoangvn.com/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use App\Models\Coupon;
use Illuminate\Http\Request;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Session;
use DB;
use Illuminate\Support\Facades\Redirect;
use App\Http\Controllers\Controller;
session_start();
class CouponController extends Controller
{
public function AuthLogin(){
$admin_id=session::get('admin_id');
if($admin_id){
return Redirect::to('dashboard');
}
else{
return Redirect::to('admin')->send();
}
}
public function insert_coupon(){
$this->AuthLogin();
Return view('admin.coupon.insert_coupon');
}
public function list_coupon(){
$this->AuthLogin();
$list_coupon=Coupon::orderby('coupon_id','DESC')->get();
//$all_category_product= DB::table('tbl_category_product')->orderby('category_id','desc')->get();
// $manager_coupon = view('admin.coupon.list_coupon')->with('list_coupon',$list_coupon);
return view('admin.coupon.list_coupon')->with(compact('list_coupon'));
}
public function delete_coupon($coupon_id){
$this->AuthLogin();
$Coupon=Coupon::find($coupon_id);
$Coupon->delete();
Session::put('message', 'xóa thành thành công');
return Redirect::to('/list-coupon');
//DB::table('tbl_coupon')->where('coupon_id',$coupon_id)->delete();
}
// frontend
public function check_coupon(Request $Request){
$data=$Request->all();
$coupon=Coupon::where('coupon_code',$data['coupon'])->first();
if($coupon){
$count_coupon=$coupon->count();
if($count_coupon>0){
$session_coupon= session::get('coupon');
if($session_coupon==true){
$is_avaiable=0;
if($is_avaiable==0){
$cou[]=array(
'coupon_code'=> $coupon->coupon_code,
'coupon_condition'=> $coupon->coupon_condition,
'coupon_number'=> $coupon->coupon_number,
);
Session::put('coupon',$cou);
}
}else{$cou[]=array(
'coupon_code'=> $coupon->coupon_code,
'coupon_condition'=> $coupon->coupon_condition,
'coupon_number'=> $coupon->coupon_number,
);Session::put('coupon',$cou);
}
Session::save();
return Redirect()->back()->with('message', 'Thêm mã giảm giá thành công');
}
}else{
return Redirect()->back()->with('error', 'Mã giảm giá không đúng');
}
}
public function insert_coupon_code(Request $Request){
$data=$Request->all();
$Coupon=new Coupon();
$Coupon->coupon_name=$data['coupon_name'];
$Coupon->coupon_time=$data['coupon_time'];
$Coupon->coupon_number=$data['coupon_number'];
$Coupon->coupon_condition=$data['coupon_condition'];
$Coupon->coupon_code=$data['coupon_code'];
$Coupon->timestamps = false;
$Coupon->save();
Session::put('message', 'Thêm mã giảm giá thành công');
return Redirect::to('/insert-coupon');
}
public function del_coupon(){
$coupon = session::get('coupon');
if($coupon==true){
Session::forget('coupon');
return Redirect()->back()->with('message', 'Xóa mã khuyến mãi thành công');
}
}
}