diff --git a/app/api/logic/GoodsLogic.php b/app/api/logic/GoodsLogic.php index c2051736..04a82e78 100755 --- a/app/api/logic/GoodsLogic.php +++ b/app/api/logic/GoodsLogic.php @@ -931,27 +931,27 @@ class GoodsLogic extends Logic $category = GoodsCategory::where(['is_show' => 1, 'del' => 0]) ->where([['name', 'like', '%' . trim($shop_name) . '%']]) - ->field('id') + ->field('id, level') ->select() ->toArray(); + if (!empty($category)) { - $ids = array_column($category, 'id'); - $ids = implode(',', $ids); - $like1 = [ - ['first_cate_id', 'like', '%' . $ids . '%'], - ]; - $like2 = [ - ['second_cate_id', 'like', '%' . $ids . '%'], - ]; - $like3 = [ - ['third_cate_id', 'like', '%' . $ids . '%'], - ]; - $goods = Goods::where($onSaleWhere) - ->whereOr([$like1, $like2, $like3])->order('sort_weight asc, sort asc, id desc') - ->field('id, name') - ->limit(20) - ->select() - ->toArray(); + $con = array( + 1 => 'first_cate_id', + 2 => 'second_cate_id', + 3 => 'second_cate_id', + ); + foreach ($category as &$v) { + $goods[] = Goods::where($onSaleWhere) + ->where([ + [$con[$v['level']], 'like', '%' . $v['id'] . '%'], + ])->order('sort_weight asc, sort asc, id desc') + ->field('id, name') + ->limit(20) + ->select() + ->toArray(); + } + $goods = call_user_func_array('array_merge', $goods); } else { $goods = Goods::field('id, name') ->where($onSaleWhere)