作者 景龙
1 个管道 的构建 通过 耗费 1 秒

修改首页加载速度问题

... ... @@ -27,30 +27,40 @@ class IndexController extends HomeBaseController
$this->assign('coverImg',$coverImg);
//星球奇境,城市分类
$res['asia'] = $this->getCity(CityCategoryModel::asia);
$res['europe'] = $this->getCity(CityCategoryModel::europe);
$res['africa'] = $this->getCity(CityCategoryModel::africa);
$res['oceania'] = $this->getCity(CityCategoryModel::oceania);
$res['north'] = $this->getCity(CityCategoryModel::north);
$res['south'] = $this->getCity(CityCategoryModel::south);
$res['antarctica'] = $this->getCity(CityCategoryModel::antarctica);
$res['arctic'] = $this->getCity(CityCategoryModel::arctic);
$this->assign('res_city',$res);
$city[1]['id'] = CityCategoryModel::asia;
$city[2]['id'] = CityCategoryModel::europe;
$city[3]['id'] = CityCategoryModel::africa;
$city[4]['id'] = CityCategoryModel::oceania;
$city[5]['id'] = CityCategoryModel::north;
$city[6]['id'] = CityCategoryModel::south;
$city[20]['id'] = CityCategoryModel::antarctica;
$city[43]['id'] = CityCategoryModel::arctic;
$city_name = $this->getCity(array_column($city,'id'));
foreach($city as &$value){
$k = 0;
foreach($city_name as $value1){
$k += 0;
if($value['id'] == $value1['pid']){
$value['name'][$k]['name'] = $value1['name'];
$value['name'][$k]['id'] = $value1['id'];
$k++;
}
}
}
$this->assign('res_city',$city);
//星享体验
$res_month['January'] = $this->getMonthArticle(CityCategoryModel::January);
$res_month['February'] = $this->getMonthArticle(CityCategoryModel::February);
$res_month['March'] = $this->getMonthArticle(CityCategoryModel::March);
$res_month['April'] = $this->getMonthArticle(CityCategoryModel::April);
$res_month['May'] = $this->getMonthArticle(CityCategoryModel::May);
$res_month['June'] = $this->getMonthArticle(CityCategoryModel::June);
$res_month['July'] = $this->getMonthArticle(CityCategoryModel::July);
$res_month['August'] = $this->getMonthArticle(CityCategoryModel::August);
$res_month['September'] = $this->getMonthArticle(CityCategoryModel::September);
$res_month['October'] = $this->getMonthArticle(CityCategoryModel::October);
$res_month['November'] = $this->getMonthArticle(CityCategoryModel::November);
$res_month['December'] = $this->getMonthArticle(CityCategoryModel::December);
$this->assign('res_month',$res_month);
$res_month = $this->getMonthArticle();
foreach($res_month['data'] as &$value){
foreach($res_month['category_name'] as $value1){
if($value['id'] == $value1['post_id']){
$value['category_name'] = $value1['name'];
}
}
}
$last_names = array_column($res_month['data'],'month');
array_multisort($last_names,SORT_ASC,$res_month['data']);
$this->assign('res_month',$res_month['data']);
//星域秀场->星球影院
$position = CityCategoryModel::xqyy;
... ... @@ -186,10 +196,10 @@ class IndexController extends HomeBaseController
}
//获取各洲对应的城市
private function getCity($pid){
private function getCity($city_ids){
$pre = CityCategoryModel::pre;
$res = Db::table($pre.'city_category')
->where('pid',$pid)
->whereIn('pid',$city_ids)
->where('is_show',1)
->where('delete_time', 0)
->field('id,pid,name')
... ... @@ -212,7 +222,7 @@ class IndexController extends HomeBaseController
}
//根据月份查询文章(星享体验)
private function getMonthArticle($month){
private function getMonthArticle(){
$position = CityCategoryModel::xxty;
$pre = CityCategoryModel::pre;
$category_id = Db::table($pre.'portal_category')
... ... @@ -231,24 +241,26 @@ class IndexController extends HomeBaseController
//查询文章
$res = Db::table($pre.'portal_post')
->whereIn('id',$post_id)
->where('month', $month)
->where('delete_time', 0)
->field('id,month,post_title,index_thumbnail,thumbnail,post_excerpt')
->limit(1)
->field('id,month,post_title,index_thumbnail')
->order('weigh desc')
->find();
->group('month')
->select()
->toArray();
$arr = [];
if($res){
$category_id = Db::table($pre.'portal_category_post')
->where('post_id', $res['id'])
->field('category_id')
->find();
$category_name = Db::table($pre.'portal_category')
->where('id', $category_id['category_id'])
->field('name')
->find();
$res['category_name'] = $category_name['name'];
$post_ids = array_column($res,'id');
$category_name = Db::name('portal_category_post')
->alias('c')
->join('portal_category p','c.category_id = p.id','LEFT')
->whereIn('post_id', $post_ids)
->field('c.post_id,p.name')
->select()
->toArray();
$arr['data'] = $res;
$arr['category_name'] = $category_name;
}
return $res;
return $arr;
}
//关于我们
... ...
... ... @@ -62,7 +62,7 @@ class CityCategoryModel extends Model
const africa = 3;//非洲
const oceania = 4;//大洋洲
const north = 5;//北美洲
const south = 6;//美洲
const south = 6;//拉丁美洲
const antarctica = 20;//南极洲
const arctic = 43;//北极
... ...
... ... @@ -34,7 +34,7 @@
<div class="show_2">
<!--banner-->
<div class="show_banner">
<notempty name="res.image_url">
<notempty name="res.thumbnail">
<img src="{:cmf_get_image_url($res.thumbnail)}" alt="">
<else/>
<img src="__TMPL__/public/assets/starImg/aicon_80.png" alt="">
... ...
... ... @@ -104,72 +104,94 @@
<img src="__TMPL__/public/assets/starImg/aicon_41.png" alt="">
<p>北美洲</p>
<ul class="star_happy_box">
<volist name="res_city.north" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
<notempty name="res_city.5.name">
<volist name="res_city.5.name" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
</notempty>
</ul>
</em>
<em class="beiji clearfix">
<img src="__TMPL__/public/assets/starImg/aicon_41.png" alt="">
<p>北极</p>
<ul class="star_happy_box">
<volist name="res_city.arctic" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
<notempty name="res_city.43.name">
<volist name="res_city.43.name" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
</notempty>
</ul>
</em>
<em class="south clearfix">
<img src="__TMPL__/public/assets/starImg/aicon_41.png" alt="">
<p>拉丁美洲</p>
<ul class="star_happy_box">
<volist name="res_city.south" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
<notempty name="res_city.6.name">
<volist name="res_city.6.name" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
</notempty>
</ul>
</em>
<em class="antarctica clearfix">
<img src="__TMPL__/public/assets/starImg/aicon_41.png" alt="">
<p>南极洲</p>
<ul class="star_happy_box">
<volist name="res_city.antarctica" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
<notempty name="res_city.20.name">
<volist name="res_city.20.name" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
</notempty>
</ul>
</em>
<em class="europe clearfix">
<img src="__TMPL__/public/assets/starImg/aicon_41.png" alt="">
<p>欧洲</p>
<ul class="star_happy_box">
<volist name="res_city.europe" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
<notempty name="res_city.2.name">
<volist name="res_city.2.name" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
</notempty>
</ul>
</em>
<em class="africa clearfix">
<img src="__TMPL__/public/assets/starImg/aicon_41.png" alt="">
<p>非洲</p>
<ul class="star_happy_box">
<volist name="res_city.africa" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
<notempty name="res_city.3.name">
<volist name="res_city.3.name" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
</notempty>
</ul>
</em>
<em class="asia clearfix">
<img src="__TMPL__/public/assets/starImg/aicon_41.png" alt="">
<p>亚洲</p>
<ul class="star_happy_box">
<volist name="res_city.asia" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
<notempty name="res_city.1.name">
<volist name="res_city.1.name" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
</notempty>
</ul>
</em>
<em class="oceania clearfix">
<img src="__TMPL__/public/assets/starImg/aicon_41.png" alt="">
<p>大洋洲</p>
<ul class="star_happy_box">
<volist name="res_city.oceania" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
<notempty name="res_city.4.name">
<volist name="res_city.4.name" id="vo">
<li><a href="/portal/star/index?city_id={$vo.id}">{$vo.name}</a></li>
</volist>
</notempty>
</ul>
</em>
</div>
... ... @@ -201,15 +223,15 @@
<p>January</p>
</div>
<!-- 图片 -->
<notempty name="res_month.January">
<notempty name="res_month.0">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.January.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.0.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.January.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.0.id}">
<div class="img_bottom">
<p>{$res_month.January.post_title}</p>
<p>{$res_month.January.category_name}</p>
<p>{$res_month.0.post_title}</p>
<p>{$res_month.0.category_name}</p>
</div>
</a>
<else/>
... ... @@ -238,15 +260,15 @@
<p>February</p>
</div>
<!-- 图片 -->
<notempty name="res_month.February">
<notempty name="res_month.1">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.February.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.1.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.February.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.1.id}">
<div class="img_bottom">
<p>{$res_month.February.post_title}</p>
<p>{$res_month.February.category_name}</p>
<p>{$res_month.1.post_title}</p>
<p>{$res_month.1.category_name}</p>
</div>
</a>
<else/>
... ... @@ -276,15 +298,15 @@
<p>March</p>
</div>
<!-- 图片 -->
<notempty name="res_month.March">
<notempty name="res_month.2">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.March.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.2.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.March.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.2.id}">
<div class="img_bottom">
<p>{$res_month.March.post_title}</p>
<p>{$res_month.March.category_name}</p>
<p>{$res_month.2.post_title}</p>
<p>{$res_month.2.category_name}</p>
</div>
</a>
<else/>
... ... @@ -315,15 +337,15 @@
<p>April</p>
</div>
<!-- 图片 -->
<notempty name="res_month.April">
<notempty name="res_month.3">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.April.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.3.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.April.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.3.id}">
<div class="img_bottom">
<p>{$res_month.April.post_title}</p>
<p>{$res_month.April.category_name}</p>
<p>{$res_month.3.post_title}</p>
<p>{$res_month.3.category_name}</p>
</div>
</a>
<else/>
... ... @@ -353,15 +375,15 @@
<p>May</p>
</div>
<!-- 图片 -->
<notempty name="res_month.May">
<notempty name="res_month.4">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.May.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.4.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.May.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.4.id}">
<div class="img_bottom">
<p>{$res_month.May.post_title}</p>
<p>{$res_month.May.category_name}</p>
<p>{$res_month.4.post_title}</p>
<p>{$res_month.4.category_name}</p>
</div>
</a>
<else/>
... ... @@ -390,15 +412,15 @@
<p>June</p>
</div>
<!-- 图片 -->
<notempty name="res_month.June">
<notempty name="res_month.5">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.June.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.5.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.June.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.5.id}">
<div class="img_bottom">
<p>{$res_month.June.post_title}</p>
<p>{$res_month.June.category_name}</p>
<p>{$res_month.5.post_title}</p>
<p>{$res_month.5.category_name}</p>
</div>
</a>
<else/>
... ... @@ -429,15 +451,15 @@
<p>July</p>
</div>
<!-- 图片 -->
<notempty name="res_month.July">
<notempty name="res_month.6">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.July.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.6.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.July.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.6.id}">
<div class="img_bottom">
<p>{$res_month.July.post_title}</p>
<p>{$res_month.July.category_name}</p>
<p>{$res_month.6.post_title}</p>
<p>{$res_month.6.category_name}</p>
</div>
</a>
<else/>
... ... @@ -468,15 +490,15 @@
<p>August</p>
</div>
<!-- 图片 -->
<notempty name="res_month.August">
<notempty name="res_month.7">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.August.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.7.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.August.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.7.id}">
<div class="img_bottom">
<p>{$res_month.August.post_title}</p>
<p>{$res_month.August.category_name}</p>
<p>{$res_month.7.post_title}</p>
<p>{$res_month.7.category_name}</p>
</div>
</a>
<else/>
... ... @@ -507,15 +529,15 @@
<p>September</p>
</div>
<!-- 图片 -->
<notempty name="res_month.September">
<notempty name="res_month.8">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.September.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.8.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.September.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.8.id}">
<div class="img_bottom">
<p>{$res_month.September.post_title}</p>
<p>{$res_month.September.category_name}</p>
<p>{$res_month.8.post_title}</p>
<p>{$res_month.8.category_name}</p>
</div>
</a>
<else/>
... ... @@ -544,15 +566,15 @@
<p>October</p>
</div>
<!-- 图片 -->
<notempty name="res_month.October">
<notempty name="res_month.9">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.October.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.9.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.October.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.9.id}">
<div class="img_bottom">
<p>{$res_month.October.post_title}</p>
<p>{$res_month.October.category_name}</p>
<p>{$res_month.9.post_title}</p>
<p>{$res_month.9.category_name}</p>
</div>
</a>
<else/>
... ... @@ -583,15 +605,15 @@
<p>November</p>
</div>
<!-- 图片 -->
<notempty name="res_month.November">
<notempty name="res_month.10">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.November.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.10.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.November.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.10.id}">
<div class="img_bottom">
<p>{$res_month.November.post_title}</p>
<p>{$res_month.November.category_name}</p>
<p>{$res_month.10.post_title}</p>
<p>{$res_month.10.category_name}</p>
</div>
</a>
<else/>
... ... @@ -622,15 +644,15 @@
<p>December</p>
</div>
<!-- 图片 -->
<notempty name="res_month.December">
<notempty name="res_month.11">
<div class="reverse_Imgs">
<img src="{:cmf_get_image_url($res_month.December.index_thumbnail)}"/>
<img src="{:cmf_get_image_url($res_month.11.index_thumbnail)}"/>
</div>
<!-- 图片下方文字 -->
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.December.id}">
<a href="/portal/enjoy/getEnjoyDetail?id={$res_month.11.id}">
<div class="img_bottom">
<p>{$res_month.December.post_title}</p>
<p>{$res_month.December.category_name}</p>
<p>{$res_month.11.post_title}</p>
<p>{$res_month.11.category_name}</p>
</div>
</a>
<else/>
... ...