From 5f87eaa056880cf68b6ea299446b28ba8dd3be85 Mon Sep 17 00:00:00 2001 From: liuyingkang <liuyingkang@163.com> Date: Tue, 22 Apr 2025 14:43:01 +0800 Subject: [PATCH] feat: 添加分页设置并优化查询逻辑 在LawyerCovenantIncomeController中添加分页设置,默认每页显示50条,并提供可选分页大小。优化Covenant仓库中的查询逻辑,确保分页参数从请求中获取,并调整默认每页显示数量为50。同时,修复查询条件,确保已删除的记录不被计入统计。 --- app/Admin/Controllers/LawyerCovenantIncomeController.php | 4 ++++ app/Admin/Repositories/Covenant.php | 15 ++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Admin/Controllers/LawyerCovenantIncomeController.php b/app/Admin/Controllers/LawyerCovenantIncomeController.php index e7bf9e7..e45c6a1 100644 --- a/app/Admin/Controllers/LawyerCovenantIncomeController.php +++ b/app/Admin/Controllers/LawyerCovenantIncomeController.php @@ -90,6 +90,10 @@ protected function grid() $actions->append('<a href="/view-covenant-invoiced?cid=' . $cid . '" alt="查看开票" >查看开票</a>'); } }); + + // 添加分页设置 + $grid->paginate(50); // 默认每页50条 + $grid->perPages([10, 20, 50, 100]); // 可选分页大小 }); } diff --git a/app/Admin/Repositories/Covenant.php b/app/Admin/Repositories/Covenant.php index 5d54c5c..d335745 100644 --- a/app/Admin/Repositories/Covenant.php +++ b/app/Admin/Repositories/Covenant.php @@ -9,6 +9,7 @@ use Dcat\Admin\Repositories\EloquentRepository; use Dcat\Admin\Grid; use Illuminate\Support\Facades\DB; +use App\Command\Log; class Covenant extends EloquentRepository { @@ -46,8 +47,8 @@ public function get(Grid\Model $model) { // 获取当前页数 $currentPage = $model->getCurrentPage(); - // 获取每页显示行数 - $perPage = $model->getPerPage(); + // 获取每页显示行数,从请求参数中获取,默认50 + $perPage = $model->filter()->input('per_page', 50); $start = ($currentPage - 1) * $perPage; @@ -68,6 +69,7 @@ public function get(Grid\Model $model) $param = [ 'sort' => $sort, 'start' => $start, + 'per_page' => $perPage, // 添加这行 'search' => ['lawyer_id' => $lawyerID, 'number' => $number, 'cname' => $cname, 'principal' => $principal, 'invoiced_at' => $invoiced_at, 'received_at' => $received_at,] ]; @@ -82,7 +84,7 @@ public function get(Grid\Model $model) // 获取列表数据 public function getList(array $param) { - $prePage = $param['per_page'] ?? 20; + $prePage = $param['per_page'] ?? 50; $stepstart = $param['start'] ?? 0; $lawyer_id = $param['search']['lawyer_id'] ?? 0; $number = $param['search']['number'] ?? ''; @@ -180,10 +182,13 @@ public function getList(array $param) $tmp['ctype'] = $item->ctype; $tmp['principal'] = $item->principal; $cid = $item->cid; + $lawyer_id = $item->lawyer_id; //开票金额 - $invoiced_money = ModelsCovenantReceivePayment::where(['cid' => $cid, 'rtype' => 2])->sum('invoiced_money'); + $invoiced_money = ModelsCovenantReceivePayment::where(['cid' => $cid,'lawyer_id' => $lawyer_id, 'rtype' => 2])->whereNull('deleted_at')->sum('invoiced_money'); + //Log::add("debug: ",'invoiced_money:'.$invoiced_money.';lawyer_id:'.$lawyer_id.';cid:'.$item->cid); + //已收款 - $receipt_money = ModelsCovenantReceivePayment::where(['cid' => $cid, 'rtype' => 1])->sum('received_amount'); + $receipt_money = ModelsCovenantReceivePayment::where(['cid' => $cid,'lawyer_id' => $lawyer_id, 'rtype' => 1])->whereNull('deleted_at')->sum('received_amount'); $tmp['invoice_amount'] = number_format($invoiced_money, 2); $tmp['receipt_money'] = number_format($receipt_money, 2); -- libgit2 0.26.0