feat: 产品搜索页
This commit is contained in:
@@ -154,6 +154,39 @@ class Product extends Common
|
|||||||
return View::fetch('category');
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 产品详情页
|
* 产品详情页
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare (strict_types = 1);
|
|||||||
namespace app\index\model;
|
namespace app\index\model;
|
||||||
|
|
||||||
use app\common\model\ProductBaseModel;
|
use app\common\model\ProductBaseModel;
|
||||||
|
use think\facade\Db;
|
||||||
use think\model\concern\SoftDelete;
|
use think\model\concern\SoftDelete;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,4 +75,10 @@ class ProductModel extends ProductBaseModel
|
|||||||
{
|
{
|
||||||
$query->where('is_new', '=', (int)$stat);
|
$query->where('is_new', '=', (int)$stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关键词搜索
|
||||||
|
public function searchKeywordsAttr($query, string $keywords)
|
||||||
|
{
|
||||||
|
$query->whereRaw('BINARY spu LIKE "%' . $keywords . '%" OR BINARY name LIKE "%' . $keywords . '%" OR BINARY short_name LIKE "%' . $keywords . '%"');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,24 +7,30 @@
|
|||||||
<div class="orico_Page_search">
|
<div class="orico_Page_search">
|
||||||
<div class="searchMain">
|
<div class="searchMain">
|
||||||
<!-- 搜索框 -->
|
<!-- 搜索框 -->
|
||||||
|
<form action="{:url('product/search')}" method="get">
|
||||||
<div class="search-ipt">
|
<div class="search-ipt">
|
||||||
<input class="ssipt" placeholder="请搜索" />
|
<input class="ssipt" name="keywords" value="{$Request.param.keywords}" placeholder="请搜索" />
|
||||||
<img src="/static/index/images/ssico.png" class="ssico" />
|
<img src="__IMAGES__/ssico.png" class="ssico" />
|
||||||
</div>
|
</div>
|
||||||
|
</form>
|
||||||
<!-- 搜索结果列表-->
|
<!-- 搜索结果列表-->
|
||||||
<ul class="seul">
|
<ul class="seul">
|
||||||
<a>
|
{volist name="products" id="pro"}
|
||||||
|
<a href="{:url('product/detail', ['id' => $pro['id']])}">
|
||||||
<li class="seitme">
|
<li class="seitme">
|
||||||
<div class="imgb">
|
<div class="imgb">
|
||||||
<img src="/static/index/images/ORCIO-HSQ-02H-800-220.jpg" class="search-pr-img" />
|
<img src="{$pro.cover_image}" class="search-pr-img" />
|
||||||
</div>
|
</div>
|
||||||
<div class="prInfp">
|
<div class="prInfp">
|
||||||
<div class="txt1"><strong class="redpoint">电脑</strong>显示器支架</div>
|
<div class="txt1">{$pro.name|raw}</div>
|
||||||
<div class="txt2"> ORICO-HSQ-02Q </div>
|
{notempty name="pro.short_name"}
|
||||||
<div class="txt3"> ORICO-HSQ-02Q </div>
|
<div class="txt2">{$pro.short_name|raw}</div>
|
||||||
|
{/notempty}
|
||||||
|
<div class="txt3">{$pro.spu|raw}</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</a>
|
</a>
|
||||||
|
{/volist}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user