|
|
@ -35,19 +35,26 @@ class AgentProductController extends Controller |
|
|
//首页搜索框
|
|
|
//首页搜索框
|
|
|
public function search() |
|
|
public function search() |
|
|
{ |
|
|
{ |
|
|
|
|
|
$category_id = request()->input('category_id'); |
|
|
$keywords = request()->input('keywords'); |
|
|
$keywords = request()->input('keywords'); |
|
|
$type = request()->input('type', 0); |
|
|
$type = request()->input('type', 0); |
|
|
$by = request()->input('by', 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']; |
|
|
$fields = ['id', 'sale', 'updated_at', 'price']; |
|
|
|
|
|
|
|
|
$field = $fields[$type] ?? $fields[0]; |
|
|
$field = $fields[$type] ?? $fields[0]; |
|
|
$by = $by == 0 ? 'desc' : 'asc'; |
|
|
$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); |
|
|
$list = $this->paginatePicAddHost($list); |
|
|
|
|
|
|
|
|
return $this->success($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) { |
|
|
$list = AgentProduct::list($this->agent_id)->whereHas('product', function($query) use ($formData) { |
|
|
|
|
|
//出发地
|
|
|
if (!empty($formData['departure_place'])) { |
|
|
if (!empty($formData['departure_place'])) { |
|
|
$query->whereRaw("extends->'$.field_0_departure_place' LIKE ?", ["%{$formData['departure_place']}%"]); |
|
|
$query->whereRaw("extends->'$.field_0_departure_place' LIKE ?", ["%{$formData['departure_place']}%"]); |
|
|
} |
|
|
} |
|
|
|
|
|
//目的地
|
|
|
if (!empty($formData['destination'])) { |
|
|
if (!empty($formData['destination'])) { |
|
|
$query->whereRaw("extends->'$.field_0_destination' LIKE ?", ["%{$formData['destination']}%"]); |
|
|
$query->whereRaw("extends->'$.field_0_destination' LIKE ?", ["%{$formData['destination']}%"]); |
|
|
} |
|
|
} |
|
|
|