| 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/models/ |
Upload File : |
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Khuyenmai_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function get_product_promotion($num=20,$start=0)
{
$today = date("Y-m-d");
$this->db->join('promotion','promotion.proid = product.proid');
$this->db->where('product.bl_active',1) ;
$this->db->where('price_old <>',0);
$this->db->where('fromdate <=',$today);
$this->db->where('todate >=',$today);
$query = $this->db->get('product', $num, $start);
return $query->result() ;
}
function count_product_promotion()
{
$today = date("Y-m-d");
$this->db->select('product.proid');
$this->db->join('promotion','promotion.proid = product.proid');
$this->db->where('product.bl_active',1) ;
$this->db->where('price_old <>',0);
$this->db->where('fromdate <=',$today);
$this->db->where('todate >=',$today);
$query = $this->db->get('product');
return $query->num_rows() ;
}
/*function get_category($num=20, $start=0)
{
$this->db->where('bl_active',1);
$this->db->where('parent_id',0) ;
$this->db->order_by('dt_modilfy','desc') ;
$query = $this->db->get('category', $num, $start) ;
return $query->result() ;
}*/
function get_subcat($catid)
{
$ar_id = array($catid);
$list = $this->get_record('category',array('parent_id'=>$catid));
if($list){
foreach($list as $rs):
array_push($ar_id,$rs->catid);
$list1 = $this->get_record('category',array('parent_id'=>$rs->catid));
if($list1){
foreach($list1 as $rs1):
array_push($ar_id,$rs1->catid);
$list2 = $this->get_record('category',array('parent_id'=>$rs1->catid));
if($list2){
foreach($list2 as $rs2):
array_push($ar_id,$rs2->catid);
endforeach;
}
endforeach;
}
endforeach;
}
return $ar_id;
}
function get_arr_cat($catid=0)
{
$arr = array($catid);
$rs = $this->get_cat($catid);
if($rs)
{
$list = $this->vdb->find_by_list("category",array("parent_id"=>$rs->catid));
foreach ($list as $row) :
array_push($arr,$row->catid);
$list2 = $this->vdb->find_by_list("category",array("parent_id"=>$row->catid));
foreach ($list2 as $row2) :
array_push($arr,$row2->catid);
endforeach ;
endforeach ;
return $arr;
}
return $arr;
}
function get_record($tbl,$arr)
{
foreach($arr as $k => $v) {
$this->db->where($k, $v);
}
$this->db->where('bl_active',1) ;
$query = $this->db->get($tbl) ;
return $query->result() ;
}
function get_product_category($catid, $num=20,$start=0)
{
$this->db->where('bl_active',1) ;
$this->db->where('catid',$catid) ;
//$this->db->order_by('dt_modilfy','desc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function get_id($id)
{
$sql="SELECT q.*, p.* FROM promotion q INNER JOIN product p where q.proid=p.proid AND p.bl_active=1 and p.proid=".$id;
$query = $this->db->query($sql);
return $query->row() ;
}
function get_product_img($id, $num=5,$start=0)
{
$this->db->where('proid',$id) ;
$query = $this->db->get('productimage', $num, $start=0) ;
return $query->result() ;
}
/*function get_product_category($catid, $num=20,$start=0)
{
$this->db->where('bl_active',1) ;
$this->db->where('catid',$catid) ;
$this->db->order_by('nb_order','ASC') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}*/
function get_catid($catid, $num=20,$start=0)
{
$this->db->where('bl_active',1) ;
$this->db->where('catid',$catid) ;
$this->db->order_by('dt_modilfy','desc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_catid($catid)
{
$this->db->where('bl_active',1) ;
$this->db->where('catid',$catid) ;
$query = $this->db->get('product') ;
return $query->num_rows();
}
function get_all($num=20,$start=0,$ord=0)
{
switch($ord){
case 1 :
$this->db->order_by('price', 'asc') ; break ;
case 2 :
$this->db->order_by('price', 'desc') ; break ;
}
$this->db->where('bl_active',1) ;
$this->db->order_by('dt_modilfy','desc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_all($ord=0)
{
switch($ord){
case 1 :
$this->db->order_by('price', 'asc') ; break ;
case 2 :
$this->db->order_by('price', 'desc') ; break ;
}
$this->db->where('bl_active',1) ;
$query = $this->db->get('product') ;
return $query->num_rows() ;
}
function get_detail_catid($catid)
{
$this->db->where('bl_active',1) ;
$this->db->where('catid',$catid) ;
$query = $this->db->get('category') ;
return $query->row() ;
}
function save_cart($data)
{
$this->db->insert('cart_detail', $data) ;
return $this->db->insert_id() ;
}
function get_search($keyword, $num=20,$start=0)
{
$this->db->like('pro_name', $keyword) ;
$this->db->or_like('pro_desc', $keyword) ;
$this->db->where('bl_active',1) ;
$this->db->order_by('dt_modilfy','desc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_search($keyword)
{
$this->db->like('pro_name', $keyword) ;
$this->db->or_like('pro_desc', $keyword) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('product') ;
return $query->num_rows() ;
}
function chkemail($cusmail)
{
//$this->db->where('bl_active',1) ;
$this->db->where('cusmail',$cusmail) ;
$query = $this->db->get('customer') ;
return $query->row() ;
}
function save($table,$data, $name='', $id=0)
{
if($name)
{
$this->db->where($name,$id);
$this->db->update($table, $data);
return $id;
}
else
{
$this->db->insert($table, $data);
return $this->db->insert_id() ;
}
}
function get_factory_detail($factory_id)
{
$this->db->where('bl_active',1) ;
$this->db->where('factory_id',$factory_id) ;
$query = $this->db->get('factory') ;
return $query->row() ;
}
//banner category
function get_bn_category()
{
$this->db->where('kind','1200x150') ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('banner') ;
return $query->result() ;
}
}
?>