商品搜索添加商品分类搜索
This commit is contained in:
parent
3677f25ab5
commit
a6407048b7
@ -907,6 +907,20 @@ class GoodsLogic extends Logic
|
||||
return [];
|
||||
}
|
||||
|
||||
SearchRecord::create([
|
||||
'user_id'=>$user_id,
|
||||
'keyword'=>$shop_name,
|
||||
'count' => 1,
|
||||
'update_time' => time(),
|
||||
'del' => 0
|
||||
]);
|
||||
|
||||
$category = GoodsCategory::where(['is_show' => 1, 'del' => 0])
|
||||
->where([['name', 'like', '%' . trim($shop_name) . '%']])
|
||||
->field('id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$onSaleWhere = [
|
||||
'del' => GoodsEnum::DEL_NORMAL, // 未删除
|
||||
'status' => GoodsEnum::STATUS_SHELVES, // 上架中
|
||||
@ -921,19 +935,23 @@ class GoodsLogic extends Logic
|
||||
|
||||
$where[] = ['name', 'like', '%' . trim($shop_name) . '%'];
|
||||
|
||||
SearchRecord::create([
|
||||
'user_id'=>$user_id,
|
||||
'keyword'=>$shop_name,
|
||||
'count' => 1,
|
||||
'update_time' => time(),
|
||||
'del' => 0
|
||||
]);
|
||||
if (empty($category)) {
|
||||
$goods = Goods::field('id, name')
|
||||
->where($onSaleWhere)
|
||||
->where($where)
|
||||
->order('sort_weight asc, sort asc, id desc')
|
||||
->select()->toArray();
|
||||
|
||||
} else {
|
||||
foreach ($category as &$v) {
|
||||
$goods = Goods::where([['first_cate_id|second_cate_id|third_cate_id', 'like', '%' . $v['id'] . '%']])
|
||||
->where($onSaleWhere)
|
||||
->order('sort_weight asc, sort asc, id desc')
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
$goods = Goods::field('id, name')
|
||||
->where($onSaleWhere)
|
||||
->where($where)
|
||||
->order('sort_weight asc, sort asc, id desc')
|
||||
->select()->toArray();
|
||||
if ($goods) {
|
||||
return $goods;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user