| Server IP : 103.48.194.25 / Your IP : 216.73.217.33 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 : 8.2.20 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/khonguyenlieu.vn/public_html/site/models/ |
Upload File : |
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Sanpham_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function get_all($catid=0,$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 ;
}
//if($catid) $this->db->where('CategoryID',$catid) ;
$arr = $this->get_subcat($catid) ;
if($arr) $this->db->where_in('CategoryID',$arr) ;
elseif($catid) $this->db->where('CategoryID',$catid) ;
$this->db->where('bl_active',1) ;
$this->db->order_by('Ordering','asc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_all($catid=0,$ord=0)
{
switch($ord){
case 1 :
$this->db->order_by('Price', 'asc') ; break ;
case 2 :
$this->db->order_by('Price', 'desc') ; break ;
}
//if($catid) $this->db->where('CategoryID',$catid) ;
$arr = $this->get_subcat($catid) ;
if($arr) $this->db->where_in('CategoryID',$arr) ;
elseif($catid) $this->db->where('CategoryID',$catid) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('product') ;
return $query->num_rows() ;
}
function get_subcat($catid)
{
$ar_id = array($catid);
$list = $this->get_record('category',array('ParentID'=>$catid));
if($list){
foreach($list as $rs):
array_push($ar_id,$rs->CategoryID);
$list1 = $this->get_record('category',array('ParentID'=>$rs->CategoryID));
if($list1){
foreach($list1 as $rs1):
array_push($ar_id,$rs1->CategoryID);
$list2 = $this->get_record('category',array('ParentID'=>$rs1->CategoryID));
if($list2){
foreach($list2 as $rs2):
array_push($ar_id,$rs2->CategoryID);
endforeach;
}
endforeach;
}
endforeach;
}
return $ar_id;
}
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_link_redirect($link)
{
$this->db->where('old_url', trim($link));
$query = $this->db->get('product_redirects');
$rs = $query->row(); //trit($rs);
if(empty($rs))
{
// ko tìm thấy link redirect thì tìm sp theo alias.
$plug = clean_slug($link);
$rs_pro = $this->get_product_by_alias($plug); //trit($plug);
if($rs_pro)
{
$req['new_url'] = "san-pham/".$rs_pro->pro_alias.'-'.$rs_pro->proid.'.html';
$req['created_at'] = date("Y-m-d H:i:s");
$req['bl_active'] = 1;
}
$req['old_url'] = $link;
$this->db->insert('product_redirects',$req);
$new_url = isset($req['new_url'])? $req['new_url'] : '';
return $new_url;
//return $req['new_url'] ?? '';
}
return $rs->new_url;
}
public function get_product_by_alias($alias)
{
return $this->db->where('Alias', $alias)->get('product')->row();
}
//start category
function get_catid($catid, $num=20,$start=0)
{
$arr = $this->get_arr_cat($catid) ;
$this->db->where_in('CategoryID',$arr) ;
$this->db->where('bl_active',1) ;
$this->db->order_by('ProductStatus','ASC') ;
$this->db->order_by('Ordering','asc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_catid($catid)
{
$arr = $this->get_arr_cat($catid) ;
$this->db->where_in('CategoryID',$arr) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('product') ;
return $query->num_rows();
}
function get_arr_cat($catid=0)
{
$arr = array($catid);
$rs = $this->get_cat($catid);
if($rs && $rs->Level<2)
{
$list = $this->vdb->find_by_list("category",array("ParentID"=>$rs->CategoryID));
foreach ($list as $row) :
array_push($arr,$row->CategoryID);
$list2 = $this->vdb->find_by_list("category",array("ParentID"=>$row->CategoryID));
foreach ($list2 as $row2) :
array_push($arr,$row2->CategoryID);
endforeach ;
endforeach ;
return $arr;
}
return $arr;
}
//start hot product
function get_hotproduct($CategoryID=0,$num=20,$start=0)
{
$random = mt_rand(10,1000);
if(!empty($CategoryID)) :
$arr = $this->get_arr_cat($CategoryID) ;
$this->db->where_in('CategoryID',$arr) ;
endif;
$this->db->where('ProductID <',$random) ;
$this->db->where('ProductStatus',1) ;
$this->db->where('bl_active',1) ;
$this->db->order_by('ProductID','desc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_hotproduct($CategoryID=0)
{
if(!empty($CategoryID)) :
$arr = $this->get_arr_cat($CategoryID) ;
$this->db->where_in('CategoryID',$arr) ;
endif;
$this->db->select('CategoryID');
$this->db->where('is_hot',1) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('product') ;
return $query->num_rows();
}
function get_list_cat_home()
{
$this->db->where('IsHome',1) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('category') ;
return $query->result() ;
}
// start thuong hiệu
function get_manu($manuid=0, $num=20,$start=0)
{
$this->db->where('bl_active',1) ;
$this->db->where('MenufactureID',$manuid) ;
$this->db->order_by('ProductStatus','ASC') ;
$this->db->order_by('Ordering','asc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_manu($manuid)
{
$this->db->where('bl_active',1) ;
$this->db->where('MenufactureID',$manuid) ;
$query = $this->db->get('product') ;
return $query->num_rows();
}
function get_id($id)
{
$this->db->where('id',$id) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('product') ;
return $query->row() ;
}
function get_cat($id)
{
$this->db->where('CategoryID',$id) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('category') ;
return $query->row() ;
}
function save($tbl, $data, $name='', $id=0)
{
if($name)
{
$this->db->where($name, $id) ;
if($this->db->update($tbl, $data))
return $id ;
else return false;
}
else
{
if($this->db->insert($tbl,$data))
return $this->db->insert_id();
else return false;
}
}
function get_search($keyword, $num=20,$start=0)
{
$this->db->like('ProductName', $keyword) ;
$this->db->or_like('ProductFunc', $keyword) ;
$this->db->where('bl_active',1) ;
$this->db->order_by('Ordering','asc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_search($keyword)
{
$this->db->like('ProductName', $keyword) ;
$this->db->or_like('ProductFunc', $keyword) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('product') ;
return $query->num_rows() ;
}
function get_tukhoa($keyword, $num=20,$start=0)
{
$this->db->like('ProductName', $keyword) ;
$this->db->or_like('ProductFunc', $keyword) ;
$this->db->or_like('metakey', $keyword) ;
$this->db->where('bl_active',1) ;
$this->db->order_by('Ordering','asc') ;
$query = $this->db->get('product', $num, $start) ;
return $query->result() ;
}
function count_tukhoa($keyword)
{
$this->db->like('ProductName', $keyword) ;
$this->db->or_like('ProductFunc', $keyword) ;
$this->db->or_like('metakey', $keyword) ;
$this->db->where('bl_active',1) ;
$query = $this->db->get('product') ;
return $query->num_rows() ;
}
}
?>