From 9ea72e64f6a9992d23e1a76b85f21dd2d3654fbd Mon Sep 17 00:00:00 2001 From: liapples Date: Thu, 14 Oct 2021 15:58:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E5=88=86?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/AgentProductController.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/AgentProductController.php b/app/Http/Controllers/Api/AgentProductController.php index f2ad7d8..0f479f4 100644 --- a/app/Http/Controllers/Api/AgentProductController.php +++ b/app/Http/Controllers/Api/AgentProductController.php @@ -35,19 +35,26 @@ class AgentProductController extends Controller //首页搜索框 public function search() { + $category_id = request()->input('category_id'); $keywords = request()->input('keywords'); $type = request()->input('type', 0); $by = request()->input('by', 0); - if (!$keywords) { - return $this->error('请输入关键词'); + + $list = AgentProduct::list($this->agent_id); + + if ($category_id) { + $list = $list->where('category_id', $category_id); } + if ($keywords) { + $list = $list->where('title', 'like', "%$keywords%"); + } + $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 = $list->orderBy($field, $by)->simplePaginate(); $list = $this->paginatePicAddHost($list); return $this->success($list); @@ -63,9 +70,11 @@ class AgentProductController extends Controller } $list = AgentProduct::list($this->agent_id)->whereHas('product', function($query) use ($formData) { + //出发地 if (!empty($formData['departure_place'])) { $query->whereRaw("extends->'$.field_0_departure_place' LIKE ?", ["%{$formData['departure_place']}%"]); } + //目的地 if (!empty($formData['destination'])) { $query->whereRaw("extends->'$.field_0_destination' LIKE ?", ["%{$formData['destination']}%"]); }