From 95bff5a215b943a7b1a80bf5256e4c3669b994f1 Mon Sep 17 00:00:00 2001 From: guojia <445241500@qq.com> Date: Mon, 6 May 2024 22:25:21 +0800 Subject: [PATCH] sort --- app/api/controller/Merchant.php | 3 ++- app/common/model/Merchant.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/api/controller/Merchant.php b/app/api/controller/Merchant.php index 06eea5e0..0aa28390 100644 --- a/app/api/controller/Merchant.php +++ b/app/api/controller/Merchant.php @@ -130,7 +130,8 @@ class Merchant extends Controller public function list(): Json { $model = new MerchantModel; $pageSize = $this->request->param('pageSize') ?? 15; - $list = $model->getList($this->request->param(), intval($pageSize))->toArray(); + $sort = $this->request->param('sort') ?? "merchant_id"; + $list = $model->getList($this->request->param(), intval($pageSize), $sort)->toArray(); foreach ($list['data'] as $kr => $r) { $res[$kr]['licenseImg'] = []; diff --git a/app/common/model/Merchant.php b/app/common/model/Merchant.php index c81cd519..701776f1 100644 --- a/app/common/model/Merchant.php +++ b/app/common/model/Merchant.php @@ -84,12 +84,12 @@ class Merchant extends BaseModel * @return \think\Paginator * @throws \think\db\exception\DbException */ - public function getList(array $param = [], int $pageSize = 15): \think\Paginator + public function getList(array $param = [], int $pageSize = 15, $sortField): \think\Paginator { $res = $this->with(['logoImage']) ->where($this->getFilter($param)) ->where('is_delete', '=', 0) - ->order(['sort' => 'asc', $this->getPk()]) + ->order(['sort' => 'desc', $sortField]) ->paginate($pageSize); return $res;