function ($query) { $query->with(['subLinks' => function ($q) { $q->order('click_count', 'desc'); }]); }, ])->where('status', 1)->find($id); if (!$info) { return redirect('/haonav/index.html'); } // 顶级分类且有子分类:按二级子分类分组展示 if ($info->pid == 0 && $info->children && $info->children->count() > 0) { // 未细分二级的链接(sub_cid=0)归入「常用」分组,排在最后 $others = LinksModel::where('cid', $id) ->where('sub_cid', 0) ->where('status', 1) ->order('click_count', 'desc') ->select(); $this->view->assign('others', $others); $this->view->assign('mode', 'group'); } else { // 二级分类 / 叶子分类:直接列出该分类下的全部链接 $links = ($info->pid == 0) ? LinksModel::where('cid', $id)->where('status', 1) : LinksModel::where('sub_cid', $id)->where('status', 1); $links = $links->order('click_count', 'desc')->select(); $this->view->assign('links', $links); $this->view->assign('mode', 'flat'); } $this->view->assign('info', $info); $this->assignSeo(); return $this->view->fetch(); } }