| 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/webadmin/models/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Common extends CI_Model
{
function __construct()
{
parent::__construct();
}
function get_product_detail($tbl,$proid)
{
$this->db->where('proid',$proid);
$query = $this->db->get($tbl);
return $query->row();
}
function get_product_by_code($pcode)
{
return $this->db->get_where('product',array('pcode'=>$pcode))->row();
}
function get_img_by_id($table,$proid)
{
$this->db->where('proid',$proid);
return $this->db->get($table)->result();
}
/**
* Ver : 1.0
* Date : 16-15-2021
* Desc : Copy Picture to product
* Params :
* Return :
*/
function copy_img($rs,$path='pktn')
{
$data = array(
'proid' => (int)$rs->proid,
'ImageName' => $rs->ImageName,
'ImagePath' => 'products/800/',
'ImageType' => 1,
'ImageSession' => ''
);
$this->db->insert('productimage',$data);
copy(ROOT_IMG.$path.'/800/'.$rs->ImageName,ROOT_IMG.'products/800/'.$rs->ImageName);
return true;
}
function get_list_product( $num=20, $start=0)
{
//$this->db->where('Alias <>', '') ;
//$this->db->where('ProductName <>', 0) ;
$this->db->where('IsHome', 0) ;
$query = $this->db->get('auto_product_chobinhtay', $num, $start);
return $query->result() ;
}
function get_all($tbl, $num=10, $start=0)
{
$this->db->where('bl_active', 1) ;
$query = $this->db->get($tbl, $num, $start);
return $query->result() ;
}
function count_all($tbl)
{
$this->db->where('bl_active', 1) ;
$query = $this->db->get($tbl);
return $query->num_rows() ;
}
function get_id($tbl,$name,$id)
{
$this->db->where($name,$id) ;
$query = $this->db->get($tbl);
return $query->row() ;
}
/**
* Ver : 2.0
* Date : 01-01-2020
* Desc : Lay 1 dong theo field chi định
* Params : string $tbl, array $where
*/
function getrow($tbl,$where)
{
if($where):
foreach($where as $k => $v)
{
$this->db->where($k, $v);
}
endif;
$query = $this->db->get($tbl,1,0);
return $query->row();
}
function get_record($tbl, $wh=array())
{
if($wh)
{
foreach($wh as $k => $v)
{
$this->db->where($k, $v);
}
}
$query = $this->db->get($tbl,1,0);
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 savewh($tbl, $data, $wh=array())
{
if($wh)
{
foreach($wh as $k => $v)
{
$this->db->where($k, $v);
}
if($this->db->update($tbl,$data))
return true ;
else return false;
}
else
{
if($this->db->insert($tbl,$data))
return $this->db->insert_id();
else return false;
}
}
function del($tbl, $name, $id)
{
if($id){
$this->db->where($name, $id) ;
$this->db->delete($tbl) ;
}
}
function trash($tbl, $name, $id)
{
if($id){
$this->db->where($name, $id);
return $this->db->update($tbl, array('bl_active'=>-1));
}
}
function restore($tbl, $name, $id)
{
if($id){
$this->db->where($name, $id);
return $this->db->update($tbl, array('bl_active'=>1));
}
}
function remove($tbl)
{
$date = new DateTime();
$date->modify('-3 month');
$date_del = $date->format('Y-m-d H:i:s');
$this->db->where('bl_active', -1);
$this->db->where('dt_create <', $date_del);
if($this->db->delete($tbl)){
return true;
}else{
return false;
}
}
function get_result($tbl, $wh='', $order=0, $num=20, $start=0)
{
if($wh)
{
foreach($wh as $k => $v)
{
$this->db->where($k, $v);
}
}
if(is_array($order))
{
foreach($order as $k => $v)
{
$this->db->order_by($k, $v);
}
}
$query = $this->db->get($tbl, $num, $start);
return $query->result() ;
}
function count_result($tbl, $wh='', $field='')
{
if($field) $this->db->select($field);
if(is_array($wh))
{
foreach($wh as $k => $v)
{
$this->db->where($k, $v);
}
}
$query = $this->db->get($tbl);
return $query->num_rows() ;
}
public function dosql($sql)
{
$query = $this->db->query($sql);
return $query->result() ;
}
}
?>