diff --git a/app/Http/Controllers/Api/AgentProductController.php b/app/Http/Controllers/Api/AgentProductController.php index 1cf51b1..f2ad7d8 100644 --- a/app/Http/Controllers/Api/AgentProductController.php +++ b/app/Http/Controllers/Api/AgentProductController.php @@ -53,6 +53,28 @@ class AgentProductController extends Controller return $this->success($list); } + //旅游线路搜索 + public function travel_search() + { + $formData = request()->only(['departure_place', 'destination']); + + if (empty($formData['departure_place']) && empty($formData['destination'])) { + return $this->error('请输入出发地和目的地'); + } + + $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']}%"]); + } + })->orderBy('id', 'DESC')->simplePaginate(); + + $list = $this->paginatePicAddHost($list); + return $this->success($list); + } + // 产品详情 public function show() { diff --git a/routes/api.php b/routes/api.php index 24ded03..90d3495 100644 --- a/routes/api.php +++ b/routes/api.php @@ -60,7 +60,8 @@ 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'); //人气爆款列表 + Route::post('search', 'AgentProductController@search'); //首页搜索框 + Route::post('travel_search', 'AgentProductController@travel_search'); //旅游线路搜索 }); # 产品分类