From 69f13e606947064c424c1203c28ad1cbae1efc6a Mon Sep 17 00:00:00 2001 From: liapples Date: Tue, 7 Sep 2021 10:32:54 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=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 --- .../Api/AgentProductController.php | 21 +++++++++++++++++++ routes/api.php | 1 + 2 files changed, 22 insertions(+) diff --git a/app/Http/Controllers/Api/AgentProductController.php b/app/Http/Controllers/Api/AgentProductController.php index 34f3cc6..f13be9c 100644 --- a/app/Http/Controllers/Api/AgentProductController.php +++ b/app/Http/Controllers/Api/AgentProductController.php @@ -31,6 +31,27 @@ class AgentProductController extends Controller return $this->success($list); } + //首页搜索框 + public function search() + { + $keywords = request()->input('keywords'); + $type = request()->input('type', 0); + $by = request()->input('by', 0); + if (!$keywords) { + return $this->error('请输入关键词'); + } + $fields = ['id', 'sale', 'updated_at', 'price']; + + $field = $fields[$type] ?? $fields[0]; + $by = $by == 0 ? 'desc' : 'asc'; + + $list = AgentProduct::list($this->agent_id)->where('title', 'like', "%$keywords%")->orderBy($field, $by)->simplePaginate(); + + $list = $this->paginatePicAddHost($list); + + return $this->success($list); + } + // 产品详情 public function show() { diff --git a/routes/api.php b/routes/api.php index 5711e11..80c8ec7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -51,6 +51,7 @@ Route::namespace('App\Http\Controllers\Api') Route::post('show', 'AgentProductController@show'); //产品详情 Route::post('recommend', 'AgentProductController@recommendList'); //我的下方推荐 Route::post('hot', 'AgentProductController@hotList'); //人气爆款列表 + Route::post('search', 'AgentProductController@search'); //人气爆款列表 }); # 产品分类