error('请输入搜索关键词'); } // 自定义分页驱动 app('think\App')->bind(Paginator::class, DxtcPageA::class); $items = []; $paginate = [ 'list_rows' => 20, 'query' => ['keyword' => $keyword, 'type' => $type] ]; $orderList = ['sort' => 'desc', 'id' => 'desc']; $path = ''; switch ($type) { case 'product': $items = ProductModel::where('title|description|content|params', 'like', '%'.$keyword.'%') ->where('visible', 1) ->order($orderList) ->paginate($paginate); $path = '/product/detail.html'; break; case 'news': $categoryIds = Category::where('template_list', Category::TEMPLATE_NEWS)->column('id'); $items = \app\model\Article::where('title|summary|content', 'like', '%'.$keyword.'%') ->whereIn('category_id', $categoryIds) ->where('status', 1) ->order($orderList) ->paginate($paginate); $path = '/news/detail.html'; break; case 'scheme': $categoryIds = Category::where('template_list', Category::TEMPLATE_SCHEME)->column('id'); $items = \app\model\Article::where('title|summary|content', 'like', '%'.$keyword.'%') ->whereIn('category_id', $categoryIds) ->where('status', 1) ->order($orderList) ->paginate($paginate); $path = '/scheme/detail.html'; break; } $this->data['items'] = $items; $this->data['bodyClass'] = 'main'; $this->data['type'] = $type; $this->data['keyword'] = $keyword; $this->data['path'] = $path; return $this->view(); } }