feat: 产品搜索页
This commit is contained in:
@@ -154,6 +154,39 @@ class Product extends Common
|
||||
return View::fetch('category');
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品搜索
|
||||
*/
|
||||
public function search()
|
||||
{
|
||||
$keywords = request()->param('keywords', '');
|
||||
|
||||
// 关键词搜索
|
||||
$products = ProductModel::field([
|
||||
'id',
|
||||
'name',
|
||||
'short_name',
|
||||
'cover_image',
|
||||
'spu'
|
||||
])
|
||||
->where(fn ($query) => $query->withSearch(['keywords'], ['keywords' => $keywords]))
|
||||
->language($this->lang_id)
|
||||
->enabled(true)
|
||||
->onSale(true)
|
||||
->onShelves(true)
|
||||
->order(['sort' => 'asc', 'id' => 'desc'])
|
||||
->select()
|
||||
->each(function ($item) use($keywords) {
|
||||
$item['spu'] = str_replace($keywords, '<strong class="redpoint">'.$keywords.'</strong>', $item['spu']);
|
||||
$item['name'] = str_replace($keywords, '<strong class="redpoint">'.$keywords.'</strong>', $item['name']);
|
||||
$item['short_name'] = str_replace($keywords, '<strong class="redpoint">'.$keywords.'</strong>', $item['short_name']);
|
||||
return $item;
|
||||
});
|
||||
View::assign('products', $products);
|
||||
|
||||
return View::fetch('search');
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品详情页
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user