| Server IP : 103.48.194.25 / Your IP : 216.73.216.74 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hocthongminh.net-bk/public_html/site/components/khuyenmai/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class khuyenmai extends MX_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('common') ;
//$this->load->library('breadcrumb');
$this->load->model('khuyenmai_model','khuyenmai');
}
public function index($start=0)
{
$display = 24;
$config['base_url'] = site.'khuyen-mai/';
$data['num'] = $this->khuyenmai->count_product_promotion();
$config['total_rows'] = $data['num'];
$config['per_page'] = $display;
$config['uri_segment'] = 3;
$config['num_links'] = 3;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['list'] = $this->khuyenmai->get_product_promotion();
$cfg = get_cauhinh();
$data['metatitle'] = $cfg->site_title;
$data['metadesc'] = $cfg->site_des;
$data['metakey'] = $cfg->site_keyword;
$data['metaimg'] = '';
$data['canonical'] = site."khuyen-mai.html";
$data['title'] = 'Trang khuyến mãi, hàng giảm giá' ;
$data['start'] = (int) $start ;
//trit($this->db->last_query());
$data['page'] = "index" ;
$this->load->view('skin', $data);
}
public function category($alias='',$start=0)
{
$catid = get_id_from_alias($alias);
$data['rs_cat'] = $rs_cat = $this->khuyenmai->get_detail_catid($catid);
$display = 24;
$config['base_url'] = site.'danh-muc/'.$alias;
$data['num'] = $this->khuyenmai->count_list_product($catid);
$config['total_rows'] = $data['num'];
$config['per_page'] = $display;
$config['uri_segment'] = 3;
$config['num_links'] = 5;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['list'] = $this->khuyenmai->get_list_product($display,$start,$catid);
//$data['list_banner'] = $this->khuyenmai->get_bn_category();
//$data['list_cate'] = $this->khuyenmai->get_category();
$data['metatitle'] = $rs_cat->metatitle.'-'.$start;
$data['metadesc'] = $rs_cat->metatitle.'-'.$start;
$data['metakey'] = $rs_cat->metatitle.'-'.$start;
$data['metaimg'] = ''; //$row->metatitle;
$data['canonical'] = site.uri_string().".html";
$data['start'] = (int) $start ;
$data['page'] = "category" ;
$this->load->view('skin', $data);
}
public function detail($alias='')
{
$proid = get_id_from_alias($alias);
$data['rs'] = $rs = $this->khuyenmai->get_id($proid) ;
if($data['rs'])
{
//SEO
$data['title'] = $data['rs']->pro_name ;
$data['list_img'] = $this->khuyenmai->get_product_img($proid) ;
$data['list_pro'] = $this->khuyenmai->get_product_category($rs->catid, 8,0) ;
$data['rs_cat'] = $rs_cat = $this->khuyenmai->get_detail_catid($rs->catid) ;
$data['rs_fac'] = $rs_fac = $this->khuyenmai->get_factory_detail($rs->factory_id) ;
$page = 0;
$data['metatitle'] = $rs->metatitle;
$data['metadesc'] = $rs->metadesc;
$data['metakey'] = $rs->metakey;
$data['metaimg'] = urlimg."products/800/".$rs->proimg;
$data['canonical'] = site."san-pham/".alias($rs->pro_name).'-'.$proid.".html";
$data['list_cate'] = $this->khuyenmai->get_list_product(10,0,$rs->catid);
$data['page'] = 'detail';
$this->load->view('skin',$data);
}
else
{
/*log_message('error', "Product Not found :" .$alias);
redirect("error/index");*/
}
}
public function viewcart()
{
$ses_login = get_ses_login() ;
if(!empty($ses_login)) redirect('profile/shopping') ;
$data['cart'] = get_ses_cart() ;
if(isset($_POST['update_cart']))
{
$soluong = isset($_POST['soluong'])? $_POST['soluong'] : '';
for ($i=0;$i<count($data['cart']);$i++):
foreach ($soluong as $b=>$c):
if($data['cart'][$i]['proid'] == $b)
$data['cart'][$i]['nb_order'] = $c ;
endforeach ;
endfor ;
}
$data['title'] = 'Xem đơn hàng' ;
$data['page'] = 'khuyenmai/viewcart';
$this->load->view('skin', $data);
}
public function thanhtoan()
{
$data['title'] = 'Thanh toán' ;
$data['page'] = 'khuyenmai/thanhtoan';
$this->load->view('skin', $data);
}
function sendcart()
{
//Lay thong tin khách hàng
$pass = $this->getRandomString(6) ;
$req = $this->_frm_customer($pass) ;
$rs_cus = $this->khuyenmai->chkemail($req['cusmail']) ;
if(empty($rs_cus))
$cusid = $this->khuyenmai->save('customer',$req);
else
$cusid = $rs_cus->cusid;
// Lưu thông tin đơn hàng
$req_cart = $this->_frm_cart($cusid);
$cartid = $this->khuyenmai->save("cart",$req_cart);
// Đơn hàng chi tiết
$total = 0;
$ses_cart = get_ses_cart();
if($ses_cart)
{
foreach($ses_cart as $cart):
$req2 = $this->_frm_cart_detail($cusid,$cartid,$cart);
$total = $total + to_number($cart['pro_price']);
$this->khuyenmai->save_cart($req2);
endforeach;
//cập nhật total và code
if($cartid)
{
//$data_cart['total'] = $total;
$data_cart['cart_code'] = mk_code("DH",$cartid,6);
$this->khuyenmai->save("cart",$data_cart,'cart_id',$cartid);
}
// goi mailo
$this->load->helper('mail');
$data['total'] = $total;
$data['cart_id'] = $cartid;
$data['cusname'] = $this->input->post('fullname');
$data['address'] = $this->input->post('address');
$data['phone'] = $this->input->post('phone');
$data['email'] = $this->input->post('cusmail');
$subject = 'Don hang tai khomayvanphong.com';
$content = $this->load->view("mail_to_customer",$data,true);
sendmail("May photocopy|ketoan@huynhgiatrading.com", "","Nguyen Trieu thang|sysdoanhnghiep@gmail.com", 'Dat hang tai khomayvanphong.com', $content) ;
//sendmail("May photocopy|tritigi@gmail.com","","",'Dat hang tai khomayvanphong.com',$content);
//if($req['cusmail']) sendmail($req['cusname'].'|'.$req['cusmail'],'','', $subject, $content);
$_SESSION['cart'] = array();
$payment_type = $this->input->post('payment_type');
if($payment_type)
redirect('thanh-cong/'.$payment_type.'/'.$data_cart['cart_code']);
else
redirect('thanh-cong/'.$payment_type.'/'.$data_cart['cart_code']);
}
else
redirect();
}
function _frm_cart($cusid='')
{
$data['cusid'] = $cusid ;
$data['cusname'] = $this->input->post('fullname');
$data['address'] = $this->input->post('address');
$data['email'] = $this->input->post('email');
$data['phone'] = $this->input->post('phone');
$data['cusnote'] = $this->input->post('note');
$data['is_payment'] = 0;
$data['is_delete'] = 0;
$data['status'] = 1;
$data['towncost'] = $this->input->post('towncost');
$data['total'] = $this->input->post('total');
$data['company'] = $this->input->post('company');
$data['taxcode'] = $this->input->post('taxcode');
$data['bl_address'] = $this->input->post('bl_address');
$data['town_name'] = $this->input->post('town_name');
$data['payment_type'] = $this->input->post('payment_type');
$data['dt_create'] = date('Y-m-d H:i:s');
$data['dt_modify'] = date('Y-m-d H:i:s');
return $data;
}
function _frm_cart_detail($cusid,$cart_id,$cart)
{
$data['cusid'] = $cusid ;
$data['cart_id'] = $cart_id ;
$data['proid'] = $cart['proid'] ;
$data['pro_name'] = $cart['pro_name'] ;
$data['pro_img'] = $cart['pro_img'] ;
$data['pro_price'] = $cart['pro_price'] ;
$data['nb_order'] = $cart['nb_order'] ;
$data['subtotal'] = $cart['nb_order'] * to_number($cart['pro_price']) ;
$data['dt_create'] = date('Y-m-d H:i:s') ;
$data['dt_modify'] = date('Y-m-d H:i:s') ;
$data['bl_active'] = 1 ;
return $data ;
}
function _frm_customer($pass='')
{
$data['cuspass'] = md5($pass);
$data['cusmail'] = trim($this->input->post('email')) ;
$data['cusname'] = $this->input->post('fullname') ;
$data['address'] = $this->input->post('address') ;
$data['cusphone'] = $this->input->post('phone') ;
$data['dt_create'] = date('Y-m-d H:i:s') ;
$data['bl_active'] = 1;
return $data ;
}
function getRandomString($length = 6)
{
$validCharacters = "abcdefghijklmnopqrstuxyvwzABCDEFGHIJKLMNOPQRSTUXYVWZ+-*#&@!?";
$validCharNumber = strlen($validCharacters);
$result = "";
for ($i = 0; $i<$length; $i++)
{
$index = mt_rand(0, $validCharNumber - 1);
$result .= $validCharacters[$index];
}
return $result;
}
function thanhcong($payment_type,$cartid=0)
{
$data['title'] = 'Đặt hàng thành công' ;
$data['cartid'] = $cartid;
$data['payment_type'] = $payment_type;
$data['page'] = 'khuyenmai/thanhcong';
$this->load->view('skin', $data);
}
function confirm($list_oid='')
{
if($list_oid)
{
$arr_oid = explode("-",$list_oid) ;
foreach ($arr_oid as $oid):
$data['status'] = 1 ;
$oid = $this->khuyenmai->save('cart',$data,'cart_id',$oid);
endforeach;
}
$data['title'] = 'Xác nhận đơn hàng thành công' ;
$data['cont'] = 'Cảm ơn bạn đã mua hàng tại website. Chúng tôi sẽ liên hệ trong thời gian sớm nhất';
$data['page'] = 'khuyenmai/thanhcong';
$this->load->view('html/skin', $data);
}
public function search()
{
$data['title'] = 'Tìm kiếm' ;
$keyword = $this->uri->segment(3) ;
$data['start'] = (int) $this->uri->segment(4) ;
$config['base_url'] = base_url().'khuyenmai/search/'.(int)$this->uri->segment(3);
$data['num'] = $this->khuyenmai->count_search($keyword);
$config['total_rows'] = $data['num'];
$config['per_page'] = 20;
$config['uri_segment'] = 4;
$config['num_links'] = 3 ;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['list'] = $this->khuyenmai->get_search($keyword, $config['per_page'],$data['start']);
$data['page'] = 'home/product';
$this->load->view('html/skin_product', $data);
}
function filter()
{
}
}
?>