alias('b')->field([ 'b.id', 'b.typeid', 'bt.name' => 'typename', 'bt.description' => 'typedesc', 'b.name', 'b.categoryid', 'b.url', 'b.picture', 'b.alt', 'b.style', 'b.description' => 'desc', 'b.descolor', 'b.btncolor', 'b.videourl', ]) ->join('banner_type bt', 'bt.stat= 0 and bt.id=b.typeid') ->where('b.stat', '=', 0) ->where('b.typeid', 'in', $typeids) ->order(['sort' => 'asc', 'id' => 'asc']) ->select(); $chucks = []; foreach ($banners as $val) { if (empty($chucks['typeid_' . $val['typeid']])) { $chucks['typeid_' . $val['typeid']]['id'] = $val['typeid']; $chucks['typeid_' . $val['typeid']]['name'] = $val['typename']; $chucks['typeid_' . $val['typeid']]['desc'] = $val['typedesc']; $chucks['typeid_' . $val['typeid']]['banners'] = []; } $link = $val['url']; if (empty($val['url']) && !empty($val['categoryid'])) { $link = url_rewrite('productsub', ['id' => $val['categoryid']]); } $chucks['typeid_' . $val['typeid']]['banners'][] = [ 'id' => $val['id'], 'name' => $val['name'], 'link' => $link, 'picture' => $val['picture'], 'alt' => $val['alt'], 'style' => $val['style'], 'desc' => $val['desc'], 'desc_color' => $val['descolor'], 'btn_color' => $val['btncolor'], 'video_url' => $val['videourl'], ]; } return $chucks; } /** * nas专题页首页 */ public function index() { $chucks = $this->getBanners([113, 114, 115, 116, 117, 118]); $data = [ 'swiper' => $chucks['typeid_113'], 'product' => $chucks['typeid_114'], 'video' => $chucks['typeid_115'], 'plan' => $chucks['typeid_116'], 'weline' => $chucks['typeid_117'], 'download' => $chucks['typeid_118'], ]; $this->assign("data", $data); return $this->fetch(); } /** * nas新品公测 */ public function beta() { return $this->fetch(); } public function download() { return $this->fetch(); } /** * nas 客户合作 */ public function cooperation() { $chucks = $this->getBanners([123, 124, 125]); $data = [ 'image_text' => $chucks['typeid_123'], 'advantage' => $chucks['typeid_124'], 'expectation' => $chucks['typeid_125'], ]; $data['advantage']['banners'] = array_chunk($data['advantage']['banners'], 2); $this->assign("data", $data); return $this->fetch(); } /** * getProductSeries 获取产品系列 */ private function getProductSeries() { return Loader::model('ProductSeries') ->field([ 'id', 'name', ]) ->where('stat', '=', 0) ->where('isshow', '=', 1) ->order(['id' => 'asc', 'sort' => 'asc']) ->select(); } /** * getCategoryTree 获取特定文章分类树 */ private function getCategoryTree($cid = 36) { // 设备 $category = Loader::model('ArticleCategory') ->field([ 'id', 'pid', 'name', ]) ->where('isshow', '=', 1) ->where('country_code', '=', $this->country_code) ->order(['sort' => 'asc']) ->select(); $category_array = collection($category)->toArray(); $category_tree = $this->buildTree($category_array, $cid); return $category_tree; } /** * getCategoryChildren 获取子孙分类id */ private function getCategoryChildren($category) { return \think\Db::query(" SELECT t2.id FROM ( SELECT @r AS _id, (SELECT @r := GROUP_CONCAT(id) FROM cod_article_category WHERE FIND_IN_SET(pid, _id)) AS parent_id FROM (SELECT @r := $category) vars, cod_article_category h WHERE @r <> 0) t1 JOIN cod_article_category t2 ON FIND_IN_SET(t2.pid, t1._id) ORDER BY t2.id; "); } /** * getProductSeriesIdMaps 获取文章系列型号 */ private function getProductSeriesIdMaps($article) { $series = []; $array_items = array_column($article, 'product_series'); array_walk($array_items, function ($val) use (&$series) { $series = array_merge($series, explode(',', $val)); }); if (!empty($series)) { $product_series = Loader::model('ProductSeries') ->where('id', 'in', array_unique($series)) ->column('name', 'id'); foreach ($article as $key => $val) { $p_series = explode(',', $val['product_series']); $p_item = []; foreach ($p_series as $k => $v) { if (!empty($product_series[$v])) { $p_item[] = $product_series[$v]; } } $article[$key]['product_series'] = $p_item; } } return $article; } /** * guide 使用教程 */ public function guide() { $params = [ 'keywords' => input('get.keywords'), 'series' => input('get.series'), 'device' => input('get.device', 38), 'category' => input('get.category'), 'page' => input('get.page', 1), 'size' => input('get.size', 10), ]; // 型号 $this->assign('series', $this->getProductSeries()); // 设备 $this->assign('category', $this->getCategoryTree(36)); // 文章列表 $article = Loader::model('Article') ->field([ 'id', 'name', 'description', 'product_series', 'content', ]) ->where('stat', '=', 0) ->where('country_code', '=', $this->country_code) ->where(function ($query) use ($params) { if (!empty($params['keywords'])) { $query->where(function ($q) use ($params) { $q->where('name', 'like', '%' . $params['keywords'] . '%') ->whereOr(sprintf('MATCH(content) AGAINST("%s" IN BOOLEAN MODE)', $params['keywords'])); }); } if (!empty($params['device']) && empty($params['category'])) { $params['category'] = $params['device']; } $children = $this->getCategoryChildren($params['category']); $categorys = array_merge([$params['category']], array_column($children, 'id')); $query->where('cid', 'in', $categorys); if (!empty($params['series'])) { $query->where(sprintf('find_in_set(%s, `product_series`)', $params['series'])); } }) ->order(['id' => 'desc', 'sort' => 'desc']) ->paginate($params['size']); $list = $this->getProductSeriesIdMaps($article->items()); $this->assign('list', $list); $this->assign('page', $article->render()); return $this->fetch(); } }