$table
$table :
系统日志表model
<?php
/**
* 系统日志表model
*/
class Systemlog_model extends CI_Model
{
private $table = 'systemlog';
public function __construct()
{
parent::__construct();
}
/**
* 系统日志表列表
* @param $param array
* @param $start int 偏移量
* @param $limit int 限制调试
* @return array
* */
public function systemlogList($param=array(),$start=0,$limit=10)
{
$where = $this->_getWhere($param);
$this->db->order_by('operationTime','desc');
$query = $this->db->get_where($this->table, $where, $limit, $start);
return $query->result_array();
}
/**
* 获取总数
* @param $param array
* @return int
* */
public function systemlogCount($param=array())
{
$where = $this->_getWhere($param);
$query = $this->db->get_where($this->table, $where);
$res = $this->db->count_all_results();
return $res;
}
/**
* 查询条件
* @param $data array(
* 'userId' => 用户ID,
* 'userName' => 用户名,
* 'tureName' => 用户真实姓名,
* 'stattime' => 开始时间,
* 'endtime' => 结束时间
* )
* return array
* */
private function _getWhere($param=array())
{
$where = array();
if(!empty($param['userName']))
{
$where['userName like'] = '%'.$param['userName'].'%';
}
if(!empty($param['tureName']))
{
$where['tureName like'] = '%'.$param['tureName'].'%';
}
if(!empty($param['userId']))
{
$where['userId'] = intval($param['userId']);
}
if(isset($param['stattime']))
{
$where['operationTime >='] = intval($param['stattime']);
}
if(isset($param['endtime']))
{
$where['operationTime <='] = intval($param['endtime']);
}
return $where;
}
/**
* 系统日志表
* @param $logId int 日志id
* @return array
* */
public function getSystemlog($logId)
{
$logId = intval($logId);
$this->db->from($this->table);
$this->db->where('logId',$logId);
$result = $this->db->get();
return $result->row_array();
}
/**
* 添加日志
* @param $data array(
* 'userId' => 用户ID,
* 'userName' => 用户名,
* 'tureName' => 用户真实姓名,
* 'operation' => 操作内容,
* 'operationTime' =>操作时间
* )
* @return bool
* */
public function addSystemlog($data)
{
$param = array();
$param['adminId'] = intval($data['adminId']);
$param['adminName'] = $data['adminName'];
$param['realName'] = $data['realName'];
$param['operation'] = $data['operation'];
$param['operationTime'] = time();
$bool = $this->db->insert($this->table, $param);
//echo $this->db->last_query();exit;
return $bool;
}
}
/* End of file Systemlog_model.php */