PHP分页查询

public function getAdminOpLogListByPager(AdminOpLogListContext $context, $sys)
    {
        $op = Db::table('admin_op_log')
            ->where('sys', $sys);

        if ($context->admin_id_arr != [-1]) {
            $op = $op->whereIn('admin_id', $context->admin_id_arr);
        }

        if ($context->field) {
            if ($context->lifting == 1) {
                $op = $op->order($context->field . ' desc');
            } else {
                $op = $op->order($context->field . ' asc');
            }
        }

        //总共记录
        $total = $op->count();
        $list = $op->limit($context->page_count * ($context->page_no - 1), $context->page_count + 1)->select();

        $count = count($list);
        $hasMore = false;
        if ($count > (int)$context->page_count) {
            $hasMore = true;
            array_pop($list);
        }

        return [
            'data' => array_values($list),
            'total' => $total,
            'has_more' => $hasMore
        ];
    }


        //处理前端样式
        $data = $result['data'];
        //总共记录
        $total_count = $result['total'];
        //总页数
        $totalPage = ceil($totalCount / $context->page_count);
        $page_info = [
            'page_no' => (int)$context->page_no,
            'page_count' => (int)$context->page_count,
            'page_total' => $totalPage,
            'total' => $totalCount,
        ];

        return [
            'page_info' => $page_info,
            'list' => array_values($data)
        ];


        //总页数
        $totalPage = ceil($totalCount / $pageCount);

        return [
            'page_no' => (int)$pageNo,
            'page_count' => (int)$pageCount,
            'has_more' => $result['has_more'],
            'list' => array_values($data),
            'total' => $totalPage,
        ];

Buy me a cup of coffee :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值