| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 | <?phpif (!defined('BASEPATH'))exit('No direct script access allowed');include_once(FCPATH . 'application/models/Base_model.php');class Group_model extends Base_model {	 protected $table = 'lamp_group';    public function __construct() {        parent::__construct();    }        // 通过条件获取分组列表    public function get_list_by_fiter($filter){		foreach ($filter as $key => $value) {			if (is_array($value)) {				if (!empty($value)) {					$this->db->where_in($key,$value);				}    		}else{    			$this->db->where($key,$value);    		}		}		$data = $this->db->get($this->table)->result_array();		foreach ($data as $k=>$v) {			if (empty($v['lampid'])) {				$data[$k]['count'] = 0;			}else{				$ids = explode(',', $v['lampid']);				$data[$k]['count'] = count($ids);			}					}		return $data;    }    public function get_count_by_filter($filter){    	$this->db->select('count(*) as total');    	foreach ($filter as $key => $value) {    		if (is_array($value)) {    			if (!empty($value)) {    				$this->db->where_in($key,$value);    			}    		}else{    			$this->db->where($key,$value);    		}    	}    	$data = $this->db->get($this->table)->row_array();    	return $data['total'];    }    public function getData($filter){    	if (!empty($filter)) {    		foreach ($filter as $key => $value) {    			if (is_array($value)) {    				if (!empty($value)) {    					$this->db->where($key,$value);    				}else{    					$this->db->where($key,array(0));    				}    			}else{    				$this->db->where($key,$value);    			}    		}    	}else{    		return array();    	}    	return $this->db->get($this->table)->row_array();    }    public function getDataCount($condition, $id = 0) {		if (!empty($condition)){			foreach ($condition as $k => $v) {				$this->db->where($k,$v);			}		}        if (!empty($id)) {            $this->db->where('id !=',$id);         }  		$query = $this->db->get($this->table);		$data = $query->row_array();        		if (empty($data)) {			return 0;		} else { 			return $id == $data['id'] ? 0 : 1;		}	}}?>
 |