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