Model(base)
class Base extends Model { protected $autoWriteTimestamp = true; public $page = ''; public $size = ''; public $from = ''; public function getTableList($data) { $query = http_build_query($data); $where = []; if(!empty($data['start']) && !empty($data['end'])) { $where['create_time'] = [['>=',strtotime($data['start'])],['<=',strtotime($data['end'])]]; } if(!empty($data['username'])){ $where['user_name'] = $data['username']; } $where['status'] = [ 'neq',Config('code.all_user_delete') ]; $this->getSizeAndPage($data); $result['tableList'] = $this->getTableListCondition($where); $result['tableListCount'] = $this->getTableListByConditionCount($where); $result['pagetotal'] = ceil($result['tableListCount']/$this->size); $result['page'] = $this->page; $result['query'] = $query; return $result; } public function getSizeAndPage($data) { $this->page = !empty($data['page']) ? $data['page'] : 1; $this->size = !empty($data['size']) ? $data['size'] : 1; $this->from = ($this->page - 1) * $this->size; } public function getTableListCondition($data,$from=0,$size=5) { if(empty($data['status'])){ $data['status']=[ 'neq',-1 ]; } $order=['id'=>'ASC']; $result = $this->where($data)->order($order)->limit($from,$size)->select(); return $result; } public function getTableListByConditionCount($where) { if(empty($where['status'])){ $where['status']=[ 'neq',-1 ]; } $result = $this->where($where)->count(); return $result; } } Controller
public function index() { $data = input('param.'); $result = model('User')->getTableList($data); $this->assign('curr',$result['page']); $this->assign('userlist',$result['tableList']); $this->assign('userlistcount',$result['tableListCount']); $this->assign('query',$result['query']); $this->assign('start',empty($data['start'])?'':$data['start']); $this->assign('end',empty($data['end'])?'':$data['end']); $this->assign('username',empty($data['username'])?'':$data['username']); $this->assign('pagetotal',$result['pagetotal']); return $this->fetch(); } view(js)