public function homepageInfo($page = 'index') { $pagedata = new PrintController(); $data = $pagedata->pagedata($page); $data_final = $data; $classify = new Classify(); foreach ($data as $k => $v) { if ($v['type'] == 'list') { $type_arr = array(1, 2, 3); $list = Classify::where('cus_id', '=', $pagedata->cus_id)->whereIn('type', array(1, 2, 3, 4, 5, 6))->where('pc_show', '=', 1)->get()->toArray(); $value = array(); $selected = false; foreach ($list as $key => $l) { $value[$key]['id'] = $l['id']; $value[$key]['name'] = $l['name']; $value[$key]['p_id'] = $l['p_id']; $value[$key]['type'] = $l['type']; if (isset($v['config']['id']) && $l['id'] == $v['config']['id']) { $value[$key]['selected'] = 1; $selected = true; } else { $value[$key]['selected'] = 0; } } if (isset($v['config']['filter'])) { if ($v['config']['filter'] == 'page') { $value = $classify->toTree($value); $type_arr = array(4); } elseif ($v['config']['filter'] == 'list') { $value = $classify->toTree($value); $type_arr = array(1, 2, 3); } elseif ($v['config']['filter'] == 'feedback') { $value = $classify->toTree($value); $type_arr = array(5); } elseif ($v['config']['filter'] == 'ALL') { $value = $classify->toTree($value); $type_arr = array(1, 2, 3, 4, 5, 6); } else { $value = $classify->toTree($value); $type_arr = array(1, 2, 3, 4); } } $this->unsetFalseClassify($value, $type_arr); if (!$selected && count($value)) { foreach ($value as $key => $v) { $value[$key]['selected'] = 1; break; } } if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) { $this->unsetLastClassify($value); } $data_final[$k]['config']['list'] = $value; if (isset($v['config']['star_only'])) { $data_final[$k]['config']['star_only'] = $v['config']['star_only']; } else { $data_final[$k]['config']['star_only'] = "0"; } } elseif ($v['type'] == 'page') { $list = Classify::where('cus_id', '=', $pagedata->cus_id)->where('type', 4)->where('pc_show', '=', 1)->get()->toArray(); $value = array(); $selected = false; foreach ($list as $key => $l) { $value[$key]['id'] = $l['id']; $value[$key]['name'] = $l['name']; $value[$key]['p_id'] = $l['p_id']; $value[$key]['type'] = $l['type']; if (isset($v['config']['id']) && $l['id'] == $v['config']['id']) { $value[$key]['selected'] = "1"; $selected = true; } else { $value[$key]['selected'] = "0"; } } if (!$selected) { $value[0]['selected'] = 1; } if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) { $this->unsetLastClassify($value); } $data_final[$k]['config']['list'] = $value; if (isset($v['config']['star_only'])) { $data_final[$k]['config']['star_only'] = $v['config']['star_only']; } else { $data_final[$k]['config']['star_only'] = "0"; } } elseif ($v['type'] == 'navs') { $type_arr = array(1, 2, 3, 4, 6); $list = Classify::where('cus_id', '=', $pagedata->cus_id)->whereIn('type', array(1, 2, 3, 4, 6))->where('pc_show', '=', 1)->get()->toArray(); $value = array(); $selected = false; foreach ($list as $key => $l) { $value[$key]['id'] = $l['id']; $value[$key]['name'] = $l['name']; $value[$key]['p_id'] = $l['p_id']; $value[$key]['type'] = $l['type']; if (isset($v['config']['id']) && $l['id'] == $v['config']['id']) { $value[$key]['selected'] = 1; $selected = true; } else { $value[$key]['selected'] = 0; } } if (isset($v['config']['filter'])) { if ($v['config']['filter'] == 'page') { $value = $classify->toTree($value); $type_arr = array(4); } elseif ($v['config']['filter'] == 'list') { $value = $classify->toTree($value); $type_arr = array(1, 2, 3); } elseif ($v['config']['filter'] == 'ALL') { $value = $classify->toTree($value); $type_arr = array(1, 2, 3, 4, 6); } else { $value = $classify->toTree($value); $type_arr = array(1, 2, 3, 4); } } $this->unsetFalseClassify($value, $type_arr); if (!$selected && count($value)) { foreach ($value as $key => $v) { $value[$key]['selected'] = 1; break; } } if (isset($v['config']['mustchild']) && $v['config']['mustchild'] == true) { $this->unsetLastClassify($value); } $data_final[$k]['config']['list'] = $value; if (isset($v['config']['star_only'])) { $data_final[$k]['config']['star_only'] = $v['config']['star_only']; } else { $data_final[$k]['config']['star_only'] = "0"; } } } //dd($data_final); return $data_final; }
/** * 手机首页 */ public function mhomepagePush($publicdata) { $result = $publicdata['result']; $result['navs'] = $publicdata['navs']; $customer_info = CustomerInfo::where('cus_id', $this->cus_id)->first(); $result['title'] = $customer_info->title; $result['keywords'] = $customer_info->keywords; $result['description'] = $customer_info->description; //获取模板目录 $data = $this->pagedata('index', $publicdata['pagedata']); $show_navs = DB::table('mobile_homepage')->leftJoin('classify', 'classify.id', '=', 'mobile_homepage.c_id')->where('mobile_homepage.index_show', 1)->where('classify.mobile_show', 1)->where('mobile_homepage.cus_id', '=', $this->cus_id)->orderBy('mobile_homepage.s_sort', 'asc')->select('classify.id', 'classify.p_id', 'classify.name', 'classify.en_name', 'classify.type', 'classify.meta_description', 'classify.page_id', 'classify.url', 'classify.img', 'classify.icon', 'mobile_homepage.star_only', 'mobile_homepage.show_num', 'mobile_homepage.m_index_showtype')->get(); //===调试测试账号=== $mIndexCats = array(); if (count($show_navs) > 0) { if ($this->showtype == 'preview') { foreach ($show_navs as $nav) { $mIndexCat = array(); $mIndexCat['id'] = $nav->id; $mIndexCat['p_id'] = $nav->p_id; $mIndexCat['name'] = $nav->name; $mIndexCat['en_name'] = $nav->en_name; $mIndexCat['icon'] = '<i class="iconfont">' . $nav->icon . '</i>'; $mIndexCat['image'] = $nav->img ? $this->source_dir . 'l/category/' . $nav->img : ''; if ($nav->url) { $mIndexCat['link'] = $nav->url; } else { $mIndexCat['link'] = $this->domain . "/category/" . $nav->id; } $mIndexCat['type'] = $nav->type; $mIndexCat['showtype'] = $nav->m_index_showtype; $mIndexCat['description'] = $nav->meta_description; $id_arr = explode(',', $this->getChildrenClassify($nav->id, 1)); if ($nav->type == 1 || $nav->type == 2 || $nav->type == 3) { $art_arr = array(); if ($nav->star_only) { //是否只显示推荐 $articles = Articles::whereIn('c_id', $id_arr)->where('mobile_show', 1)->where('is_star', 1)->orderBy('is_top', 'desc')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->take($nav->show_num)->get(); } else { $articles = Articles::whereIn('c_id', $id_arr)->where('mobile_show', 1)->orderBy('is_top', 'desc')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->take($nav->show_num)->get(); } if (count($articles) > 0) { $i = 0; foreach ($articles as &$article) { $art_arr[$i]['title'] = $article->title; $art_arr[$i]['image'] = $article->img ? $this->source_dir . 's/articles/' . $article->img : ''; $art_arr[$i]['link'] = $this->domain . "/detail/" . $article->id; if ($article->use_url) { $art_arr[$i]['link'] = $article->url; } $art_arr[$i]['description'] = $article->introduction; $art_arr[$i]['pubdate'] = (string) $article->created_at; $art_arr[$i]['pubtimestamp'] = strtotime($article->created_at); $art_arr[$i]['category']['name'] = $nav->name; $art_arr[$i]['category']['en_name'] = $nav->name; if ($nav->url) { $art_arr[$i]['category']['link'] = $nav->url; } else { $art_arr[$i]['category']['link'] = $this->domain . "/category/" . $nav->id; } $i++; } } $mIndexCat['data'] = $art_arr; } elseif ($nav->type == 4) { $content = Page::where('id', $nav->page_id)->pluck('content'); $mIndexCat['content'] = $content; } elseif ($nav->type == 5 || $nav->type == 6 || $nav->type == 7 || $nav->type == 8 || $nav->type == 9) { //暂时缺省 } $mIndexCats[] = $mIndexCat; } } else { foreach ($show_navs as $nav) { $mIndexCat = array(); $mIndexCat['id'] = $nav->id; $mIndexCat['p_id'] = $nav->p_id; $mIndexCat['name'] = $nav->name; $mIndexCat['en_name'] = $nav->en_name; $mIndexCat['icon'] = '<i class="iconfont">' . $nav->icon . '</i>'; $mIndexCat['image'] = $nav->img ? $this->source_dir . "/l/category/" . $nav->img : ''; if ($nav->url) { $mIndexCat['link'] = $nav->url; } else { $mIndexCat['link'] = $this->domain . "/category/" . $nav->id . ".html"; } $mIndexCat['type'] = $nav->type; $mIndexCat['showtype'] = $nav->m_index_showtype; $mIndexCat['description'] = $nav->meta_description; $id_arr = explode(',', $this->getChildrenClassify($nav->id, 1)); if ($nav->type == 1 || $nav->type == 2 || $nav->type == 3) { $art_arr = array(); if ($nav->star_only) { //是否只显示推荐 $articles = Articles::whereIn('c_id', $id_arr)->where('mobile_show', 1)->where('is_star', 1)->orderBy('is_top', 'desc')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->take($nav->show_num)->get(); } else { $articles = Articles::whereIn('c_id', $id_arr)->where('mobile_show', 1)->orderBy('is_top', 'desc')->orderBy('sort', 'ASC')->orderBy('created_at', 'DESC')->take($nav->show_num)->get(); } if (count($articles) > 0) { $i = 0; foreach ($articles as &$article) { $art_arr[$i]['title'] = $article->title; $art_arr[$i]['image'] = $article->img ? $this->source_dir . "/s/articles/" . $article->img : ''; $art_arr[$i]['link'] = $this->domain . "/detail/" . $article->id . ".html"; if ($article->use_url) { $art_arr[$i]['link'] = $article->url; } $art_arr[$i]['description'] = $article->introduction; $art_arr[$i]['pubdate'] = (string) $article->created_at; $art_arr[$i]['pubtimestamp'] = strtotime($article->created_at); $art_arr[$i]['category']['name'] = $nav->name; $art_arr[$i]['category']['en_name'] = $nav->name; if ($nav->url) { $art_arr[$i]['category']['link'] = $nav->url; } else { $art_arr[$i]['category']['link'] = $this->domain . "/category/" . $nav->id; } $i++; } } $mIndexCat['data'] = $art_arr; } elseif ($nav->type == 4) { $content = Page::where('id', $nav->page_id)->pluck('content'); $mIndexCat['content'] = $content; } elseif ($nav->type == 5 || $nav->type == 6 || $nav->type == 7 || $nav->type == 8 || $nav->type == 9) { //暂时缺省 } $mIndexCats[] = $mIndexCat; } } } $classify = new Classify(); foreach ($mIndexCats as $key => $val) { $mIndexCats[$key]['childmenu'] = $classify->toTree($mIndexCats, $mIndexCats[$key]['id']); } $result['mIndexCats'] = $mIndexCats; $content = $publicdata['repleace']['index.html']; $content = preg_replace($publicdata['pattern'], $publicdata['repleace'], $content); $smarty = new Smarty(); $smarty->setCompileDir(app_path('storage/views/compile')); $smarty->setTemplateDir(app_path('views/templates/' . $this->themename)); $smarty->registerPlugin('function', 'mapExt', array('PrintController', 'createMap')); $smarty->registerPlugin('function', 'shareExt', array('PrintController', 'createShare')); $smarty->assign($result); ob_start(); $smarty->display('string:' . $content); $output = ob_get_contents(); ob_end_clean(); return $output; }