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); + } + /** * 更新商品