diff --git a/app/index/controller/TopsNas.php b/app/index/controller/TopsNas.php index 1a49d7c..b27a174 100755 --- a/app/index/controller/TopsNas.php +++ b/app/index/controller/TopsNas.php @@ -194,6 +194,7 @@ class TopsNas extends BaseController 'id', 'pid', 'name', + 'picture' ]) ->where('isshow', '=', 1) ->where('country_code', '=', $this->country_code) @@ -310,4 +311,158 @@ class TopsNas extends BaseController return $this->fetch(); } + + // 根据分类获取文章 + private function getArticleByCategory($categorys, $limit = 3) + { + if (!is_array($categorys)) { + throw new \Exception('请确认分类正确'); + } + if (empty($categorys)) { + return []; + } + + $model = Loader::model('Article') + ->field([ + 'id', + 'cid', + 'name', + 'sort' + ]) + ->where('stat', '=', 0) + ->where('cid', '=', $categorys[0]['id']) + ->where('country_code', '=', $this->country_code); + foreach ($categorys as $key => $val) { + if ($key == 0) continue; + $model->union(function($query) use($val, $limit) { + $query->name('article')->field([ + 'id', + 'cid', + 'name', + 'sort' + ]) + ->where('stat', '=', 0) + ->where('cid', '=', $val['id']) + ->where('country_code', '=', $this->country_code) + ->order(['sort' => 'asc', 'id' => 'desc']) + ->limit($limit); + }); + } + + $map = []; + $data = $model->order(['sort' => 'asc', 'id' => 'desc'])->limit($limit)->select(); + foreach ($data as $key => $val) { + $map['cid_' . $val['cid']][] = $val; + } + return $map; + } + // 帮忙中心 + public function helper() + { + // 获取分类 + $categorys = $this->getCategoryTree(76); + // 获取文章 + $articles = $this->getArticleByCategory($categorys, 3); + // 组装数据 + foreach ($categorys as $key => &$val) { + if (!isset($val['articles'])) { + $val['articles'] = []; + } + if (isset($articles['cid_' . $val['id']])) { + $articles = $articles['cid_' . $val['id']]; + foreach ($articles as $k => $v) { + $val['articles'][] = [ + 'id' => $v['id'], + 'name' => $v['name'] + ]; + } + } + } + unset($val); + $this->assign('categorys', $categorys); + + $banners = $this->getBanners(126); + if (!empty($banners)) { + $banners = $banners['typeid_126']['banners']; + } + $this->assign('banners', $banners); + $this->assign('banners_size', count($banners)); + + return $this->fetch(); + } + + // 搜索帮助文章 + public function helper_search() + { + $base_category = 76; + $keywords = request()->param('keywords'); + $articles = Loader::model('Article') + ->field([ + 'id', + 'name', + 'sort', + ]) + ->where('stat', '=', 0) + ->where('country_code', '=', $this->country_code) + ->where('cid', 'in', function($query) use($base_category) { + $query->name('article_category') + ->field(['id']) + ->where('id', '=', $base_category) + ->whereOr('pid', '=', $base_category); + }) + ->where(function($query) use($keywords) { + if (!empty($keywords)) { + $query->where('name', 'like', '%' . $keywords . '%'); + } + }) + ->order(['sort' => 'asc', 'id' => 'desc']) + ->select(); + + return json([ + 'code' => 0, + 'message' => '获取成功', + 'data' => $articles + ]); + } + + // 帮助中心文章详细 + public function helper_detail() + { + $id = request()->param('id'); + $article = Loader::model('Article')->where('id', '=', $id)->find(); + + if (request()->isAjax()) { + return json([ + 'code' => 0, + 'message' => '获取成功', + 'data' => $article + ]); + } else { + // 获取分类 + $categorys = $this->getCategoryTree(76); + // 获取文章 + $articles = $this->getArticleByCategory($categorys, 3); + // 组装数据 + foreach ($categorys as $key => &$val) { + if (!isset($val['articles'])) { + $val['articles'] = []; + } + if (isset($articles['cid_' . $val['id']])) { + $articles = $articles['cid_' . $val['id']]; + foreach ($articles as $k => $v) { + $val['articles'][] = [ + 'id' => $v['id'], + 'name' => $v['name'] + ]; + } + } + } + unset($val); + $this->assign('categorys', $categorys); + $this->assign('article', $article); + $this->assign('cid', request()->param('cid')); + } + + return $this->fetch(); + } } diff --git a/app/index/view/tops_nas/helper.phtml b/app/index/view/tops_nas/helper.phtml new file mode 100644 index 0000000..0d60520 --- /dev/null +++ b/app/index/view/tops_nas/helper.phtml @@ -0,0 +1,481 @@ + + +
+ + +
+
+
+
+
+ {/volist}
+ 查看更多
+
+
+
+
+
+ {if condition="!empty($banners[0]['picture']) && $banners[0]['picture'] != '/uploads/nopic.jpg'"}
+
+ {if condition="!empty($banners[1]['picture']) && $banners[1]['picture'] != '/uploads/nopic.jpg'"}
+
+ {if condition="!empty($banners[2]['picture']) && $banners[2]['picture'] != '/uploads/nopic.jpg'"}
+
+ {if condition="!empty($banners[3]['picture']) && $banners[3]['picture'] != '/uploads/nopic.jpg'"}
+
+ {if condition="!empty($banners[4]['picture']) && $banners[4]['picture'] != '/uploads/nopic.jpg'"}
+
+ {if condition="!empty($banners[5]['picture']) && $banners[5]['picture'] != '/uploads/nopic.jpg'"}
+
+ {if condition="!empty($banners[6]['picture']) && $banners[6]['picture'] != '/uploads/nopic.jpg'"}
+
+