封装Es商品搜索

es
ztt 8 months ago
parent ddb8634042
commit 556eb0a875
  1. 55
      app/api/controller/GoodsNew.php
  2. 2
      app/common/service/GoodsEs.php

@ -4,6 +4,7 @@ namespace app\api\controller;
use app\common\service\GoodsEs; use app\common\service\GoodsEs;
use think\App;
class GoodsNew extends Controller class GoodsNew extends Controller
{ {
@ -13,4 +14,58 @@ class GoodsNew extends Controller
$data = $goodsService->list([]); $data = $goodsService->list([]);
dd($data); dd($data);
} }
public function search()
{
$keyword = $this->request->param('keyword');
$page = $this->request->param('page', 1);
$limit = $this->request->param('limit', 10);
$params = ['goods_name' => $keyword];
$goodsService = new GoodsEs();
$data = $goodsService->list($params, $page, $limit);
$this->renderSuccess($data);
}
/**
* 添加商品
*/
public function add()
{
$goods_id = 1;
$goods_data = \app\common\model\Goods::where('goods_id', '=', $goods_id)
->order('goods_id desc')
->find()
->toArray();
$goodsService = new GoodsEs();
$data = $goodsService->createData($goods_id, $goods_data);
$this->renderSuccess($data);
}
/**
* 更新商品
*/
public function update()
{
$goods_id = 1;
$update = [
'goods_name' => '测试商品',
'selling_point' => '测试商品',
'goods_price_min' => 100,
'goods_price_max' => 100,
];
$goodsService = new GoodsEs();
$data = $goodsService->updateData($goods_id, $update);
$this->renderSuccess($data);
}
/**
* 删除
*/
public function delete()
{
$goods_id = 1;
$goodsService = new GoodsEs();
$data = $goodsService->delete($goods_id);
$this->renderSuccess($data);
}
} }

@ -36,7 +36,7 @@ class GoodsEs
/** /**
* 更新商品 * 更新商品
*/ */
public function update($goods_id, $data) public function updateData($goods_id, $data)
{ {
return $this->esService->update($goods_id, $data); return $this->esService->update($goods_id, $data);
} }

Loading…
Cancel
Save