feat: mobile产品搜索页

This commit is contained in:
2025-05-26 17:36:05 +08:00
parent 7273594013
commit 6d9a0f3d06
8 changed files with 170 additions and 29 deletions

View File

@@ -267,7 +267,12 @@ class Product extends Common
*/
public function search()
{
$keywords = request()->param('keywords', '');
$param = request()->param([
'keywords',
'page/d' => 1,
'size/d' => 10
]);
$keywords = $param['keywords'] ?? '';
// 关键词搜索
$products = ProductModel::field([
@@ -283,7 +288,11 @@ class Product extends Common
->onSale(true)
->onShelves(true)
->order(['sort' => 'asc', 'id' => 'desc'])
->select()
->paginate([
'list_rows' => $param['size'],
'page' => $param['page'],
'query' => request()->param()
])
->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']);
@@ -291,6 +300,7 @@ class Product extends Common
return $item;
});
View::assign('products', $products);
View::assign('page', $products->render());
return View::fetch('search');
}