where('is_del', 0) ->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){ $query->where('id', (int)$params['id']); }) ->when(isset($params['title']) && $params['title'] !== '',function($query) use ($params){ $query->where('title', 'like', "%{$params['title']}%"); }) ->when(isset($params['merchant_type']) && $params['merchant_type'] !== '',function($query) use ($params){ $query->where('merchant_type', (int)$params['merchant_type']); }) ->when(isset($params['weight']) && $params['weight'] !== '',function($query) use ($params){ $query->where('weight', (int)$params['weight']); }) ->order('weight DESC,id DESC'); } }