勾股OA在线文档

分页查询

DB分页查询方法:

    $where = array();
    $where[] = ['delete_time', '=', 0];
    $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
    $list = Db::name('Customer')
        ->field('id,name,address')
        ->order('id asc')->where($where)->paginate($rows, false)
        ->each(function($item, $key){
            $contact = Db::name('CustomerContact')->where(['cid'=>$item['id'],'is_default'=>1])->find();
            if(!empty($contact)){
                $item['contact_name'] = $contact['name'];
                $item['contact_mobile'] = $contact['mobile'];
            }
            else{
                $item['contact_name'] = '';
                $item['contact_mobile'] = '';
            }
            return $item;
    });

Model分页查询方法:

    $where = [];
    $where[] = ['delete_time', '=', 0];
    $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
    $list = ReceiptList::order('create_time desc')
        ->paginate($rows, false, ['query' => $param])
        ->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');
    });