封装Es商品搜索

main
ztt 9 months ago
parent 3a221d9db9
commit e04861703c
  1. 8
      app/api/controller/GoodsNew.php
  2. 12
      app/common/service/GoodsEs.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);
}

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

Loading…
Cancel
Save