分页查询
DB分页查询方法:
$param = get_params();
$where = [];
if (!empty($param['keywords'])) {
$where[] = ['p.title', 'like', '%' . $param['keywords'] . '%'];
}
if (!empty($param['diff_time'])) {
$diff_time =explode('~', $param['diff_time']);
$where[] = ['pr.repair_time', 'between', [strtotime(urldecode($diff_time[0])),strtotime(urldecode($diff_time[1]))]];
}
$where[] = ['pr.delete_time','=',0];
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = Db::name('PropertyRepair')
->field('pr.*,pc.title as cate,pb.title as brand,p.title,p.model,u.name as director_name')
->alias('pr')
->join('Property p', 'p.id = pr.property_id', 'left')
->join('PropertyCate pc', 'pc.id = p.cate_id', 'left')
->join('PropertyBrand pb', 'pb.id = p.brand_id', 'left')
->join('Admin u', 'u.id = pr.director_id', 'left')
->where($where)
->order('id desc')
->paginate(['list_rows'=> $rows])
->each(function ($item, $key){
$item['repair_time'] = date('Y-m-d',$item['repair_time']);
$item['create_time'] = date('Y-m-d H:i',$item['create_time']);
return $item;
});
return table_assign(0, '', $list);
Model分页查询方法:
$where = [];
$where[] = ['delete_time', '=', 0];
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = ReceiptList::order('create_time desc')
->paginate(['list_rows'=> $rows])
->each(function ($item, $key) {
$item['order'] = Db::name('Sold')->where(['id' => $item['sold_id']])->find('code');
$item->['customer'] = Db::name('Customer')->where(['id' => $item['customer_id'])->find('name');
});