From e04861703cd24b7d2f859ea74d78fd33da53dd94 Mon Sep 17 00:00:00 2001 From: ztt <835303992@qq.com> Date: Fri, 31 May 2024 11:44:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85Es=E5=95=86=E5=93=81=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/GoodsNew.php | 8 +++++++- app/common/service/GoodsEs.php | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/api/controller/GoodsNew.php b/app/api/controller/GoodsNew.php index 2332a571..16679059 100644 --- a/app/api/controller/GoodsNew.php +++ b/app/api/controller/GoodsNew.php @@ -20,10 +20,16 @@ class GoodsNew extends Controller $keyword = $this->request->param('keyword'); $page = $this->request->param('page', 1); $limit = $this->request->param('limit', 10); + if (!$keyword) { + $this->renderError('请输入搜索关键字'); + } $params = ['goods_name' => $keyword]; $goodsService = new GoodsEs(); $data = $goodsService->list($params, $page, $limit); - $this->renderSuccess($data); + $data['total'] = $goodsService->count(); + $data['list'] = $data; + + return $this->renderSuccess($data); } diff --git a/app/common/service/GoodsEs.php b/app/common/service/GoodsEs.php index 7ea8e2c4..ec3261bb 100644 --- a/app/common/service/GoodsEs.php +++ b/app/common/service/GoodsEs.php @@ -19,7 +19,6 @@ class GoodsEs /** * 查询商品列表 * @param $params - * @return */ public function list($params = [],$page = 1, $limit = 10) { @@ -32,6 +31,17 @@ class GoodsEs ->query(); } + public function count($params = [],$page = 1, $limit = 10) + { + return $this->esService +// ->setDebug() + ->like($params) + ->from($page) + ->size($limit) + ->order(['goods_id' => 'desc']) + ->query(true); + } + /** * 更新商品