审查视图

app/portal/controller/RegionController.php 11.8 KB
景龙 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use app\portal\model\CityCategoryModel;
15
use app\portal\model\PortalPostModel;
景龙 authored
16 17 18 19 20 21 22 23 24
use think\Db;
//星域秀场
class RegionController extends HomeBaseController
{
    private $index_limit = 16;//首页分页
    private $more_limit = 8;//更多列表分页
    public function index(){
        //星球影院
        $position['category_id'] = CityCategoryModel::xqyy;
zhangwei authored
25
        $field = 'id,more,thumbnail';
景龙 authored
26 27 28
        $res_xqyy = $this->getChildArticle($position,$field,1);
        foreach($res_xqyy as &$value){
            $more = json_decode($value['more'],true);
景龙 authored
29
            $value['video'] = isset($more['video']) && !empty($more['video'])?$more['video']:'';
景龙 authored
30
        }
景龙 authored
31 32 33
        if($res_xqyy){
            $res_xqyy = $res_xqyy[0];
        }
景龙 authored
34 35 36 37 38 39
        $this->assign('res_xqyy',$res_xqyy);

        //明星访谈
        $position['category_id'] = CityCategoryModel::mxft;
        $field = 'id,thumbnail avatar,full_name,position,trade,post_excerpt';
        $res_mxft = $this->getChildArticle($position,$field,1);
景龙 authored
40 41 42
        if($res_mxft){
            $res_mxft = $res_mxft[0];
        }
景龙 authored
43 44 45 46
        $this->assign('res_mxft',$res_mxft);

        //星球故事
        $position['category_id'] = CityCategoryModel::xqgs;
47
        $field = 'id,thumbnail,post_excerpt,more,excerpt';
景龙 authored
48 49 50
        $res_xqgs = $this->getChildArticle($position,$field,$this->index_limit);
        foreach($res_xqgs as &$value){
            $more = json_decode($value['more'],true);
景龙 authored
51
            $value['audio'] = isset($more['audio']) && !empty($more['audio'])?$more['audio']:'';
52 53
            $contentModel = new PortalPostModel();
            $value['excerpt'] = $contentModel->getPostContentAttr($value['excerpt']);
景龙 authored
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
        }
        $this->assign('res_xqgs',$res_xqgs);

        //星域画廊
        $position['category_id'] = CityCategoryModel::xyhl;
        $field = 'id,thumbnail';
        $res_xyhl = $this->getChildArticle($position,$field,$this->index_limit);
        $this->assign('res_xyhl',$res_xyhl);

        //独角快报
        $position['category_id'] = CityCategoryModel::djkb;
        $field = 'id,thumbnail,post_title,post_excerpt,create_time';
        $res_djkb = $this->getChildArticle($position,$field,3);
        $this->assign('res_djkb',$res_djkb);

        //独角日志
        $position['category_id'] = CityCategoryModel::djrz;
71
        $field = 'id,thumbnail avatar,index_thumbnail,post_title,post_excerpt,more';
景龙 authored
72 73 74 75 76 77
        $res_djrz = $this->getChildArticle($position,$field,3);
        $this->assign('res_djrz',$res_djrz);

        //童趣未来
        $position['category_id'] = CityCategoryModel::tqwl;
        $field = 'id,thumbnail,post_title,post_excerpt';
景龙 authored
78
        $res_tqwl = $this->getChildArticle($position,$field,2);
景龙 authored
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        $this->assign('res_tqwl',$res_tqwl);

        return $this->fetch();
    }

    //根据子类获取文章
    public function getChildArticle($position,$field,$limit=''){
        $pre = CityCategoryModel::pre;
        $limit = empty($limit)?0:$limit;
        $post_id = Db::table($pre.'portal_category_post')
            ->whereIn('category_id',$position['category_id'])
            ->field('post_id')
            ->select()
            ->toArray();
        $post_id = array_column($post_id,'post_id');
        //查询文章
        $res = Db::table($pre.'portal_post')
            ->whereIn('id',$post_id)
            ->where('delete_time', 0)
            ->field($field)
            ->limit($limit)
            ->order('weigh desc')
            ->select()
            ->toArray();
        return $res;
    }

    //根据子类获取文章分页
107
    public function getChildArticlePage($position,$field,$limit=''){
景龙 authored
108 109 110 111 112 113 114 115 116
        $pre = CityCategoryModel::pre;
        $limit = empty($limit)?$this->more_limit:$limit;
        $post_id = Db::table($pre.'portal_category_post')
            ->whereIn('category_id',$position['category_id'])
            ->field('post_id')
            ->select()
            ->toArray();
        $post_id = array_column($post_id,'post_id');
        //查询文章
景龙 authored
117
        $res = Db::name('portal_post')
景龙 authored
118 119 120 121
            ->whereIn('id',$post_id)
            ->where('delete_time', 0)
            ->field($field)
            ->order('weigh desc')
122
            ->paginate($limit);
景龙 authored
123
        $arr['data'] = $res->toArray();
景龙 authored
124 125
        $arr['page'] = $res->render();
        return $arr;
景龙 authored
126 127 128 129 130 131 132 133 134 135 136 137 138
    }

    //获取城市分类
    public function getCityCategory($id){
        $city_name = Db::table('cmf_city_category')
            ->where('id',$id)
            ->field('name')
            ->find();
        return $city_name['name'];
    }

    //星球影院更多(按照城市查询)
    public function getMoreVideo(){
景龙 authored
139
        $city_id = $this->request->param('city_id',0,'intval');
140 141 142 143 144
        //城市名字
        $star = new StarController();
        $cityName = $star->getCityName($city_id);
        $this->assign('cityName',$cityName);
景龙 authored
145 146
        $position['city_id'] = $city_id;
        $position['category_id'] = CityCategoryModel::xqyy;
景龙 authored
147
        $field = 'id,post_title,framing,release_time,city_id,more,thumbnail';
148
        $res = $star->getChildArticlePage($position,$field,'-1');
景龙 authored
149
        foreach($res['data']['data'] as &$value){
景龙 authored
150
            $more = json_decode($value['more'],true);
景龙 authored
151
            $value['video'] = isset($more['video']) && !empty($more['video'])?$more['video']:'';
景龙 authored
152 153
            $value['city_name'] = $this->getCityCategory($value['city_id']);
        }
景龙 authored
154 155 156 157
        $this->assign('res',$res['data']);
        $this->assign('page',$res['page']);

        //城市分类
158
        $city_name = $this->getVideoCityName();
景龙 authored
159
        $this->assign('city_name',$city_name);
景龙 authored
160
景龙 authored
161
        $this->assign('city_id',$city_id);
景龙 authored
162
        return $this->fetch();
景龙 authored
163 164
    }
165 166 167 168 169
    //获取城市名称
    public function getVideoCityName(){
        $res = Db::name('city_category')
            ->where('pid','<>',0)
            ->where('id','<>',CityCategoryModel::xqgh_cc)
170
            ->where('is_show',1)
171
            ->where('delete_time',0)
景龙 authored
172 173 174 175
            ->field('id,name')
            ->order('weigh desc')
            ->select()
            ->toArray();
176 177 178
        return $res;
    }
景龙 authored
179 180 181 182
    //明星访谈更多
    public function getMoreStar(){
        $position['category_id'] = CityCategoryModel::mxft;
        $field = 'id,thumbnail avatar,full_name,position,trade,post_excerpt';
183
        $res = $this->getChildArticlePage($position,$field,5);
景龙 authored
184 185 186
        $this->assign('res',$res['data']);
        $this->assign('page',$res['page']);
        return $this->fetch();
景龙 authored
187 188
    }
189 190 191 192 193 194 195
    //明星访谈详情
    public function getStarDetail(){
        $id = $this->request->param('id',0,'intval');
        $field = 'id,thumbnail avatar,full_name,position,trade,post_excerpt,create_time,post_content';
        $starModel = new StarController();
        $res = $starModel->getDetail($id,$field);
        $this->assign('res',$res);
景龙 authored
196
        return $this->fetch();
197 198
    }
景龙 authored
199 200 201
    //星球故事更多
    public function getMoreStory(){
        $position['category_id'] = CityCategoryModel::xqgs;
202
        $field = 'id,thumbnail,post_excerpt,more,create_time,excerpt';
jinglong authored
203
        $res = $this->getChildArticlePage($position,$field);
景龙 authored
204
        foreach($res['data']['data'] as &$value){
景龙 authored
205
            $more = json_decode($value['more'],true);
景龙 authored
206
            $value['audio'] = isset($more['audio']) && !empty($more['audio'])?$more['audio']:'';
207 208
            $contentModel = new PortalPostModel();
            $value['excerpt'] = $contentModel->getPostContentAttr($value['excerpt']);
景龙 authored
209
        }
jinglong authored
210 211 212
        $this->assign('res',$res['data']);
        $this->assign('page',$res['page']);
        return $this->fetch();
景龙 authored
213 214 215 216 217 218
    }

    //星域画廊更多
    public function getMoreGallery(){
        $position['category_id'] = CityCategoryModel::xyhl;
        $field = 'id,thumbnail';
jinglong authored
219 220 221
        $res = $this->getChildArticlePage($position,$field,16);
        $this->assign('res',$res['data']);
        $this->assign('page',$res['page']);
jinglong authored
222 223 224 225 226

        //封面图
        $imgModel = new IndexController();
        $coverImg = $imgModel->getCoverImg(CityCategoryModel::galleryImg,1);
        $this->assign('coverImg',$coverImg);
jinglong authored
227 228 229 230 231 232 233 234 235 236 237 238
        return $this->fetch();
    }

    //星域画廊详情
    public function getGalleryDetail(){
        $id = $this->request->param('id',0,'intval');
        $field = 'id,thumbnail,post_title,post_content,more';
        $starModel = new StarController();
        $res = $starModel->getDetail($id,$field);
        if($res){
            $more = json_decode($res['more'],true);
            $res['image_url'] = isset($more['photos']) && !empty($more['photos'])?$more['photos']:'';
景龙 authored
239
            $res['m_image_url'] = isset($more['m_photos']) && !empty($more['m_photos'])?$more['m_photos']:'';
jinglong authored
240
        }
景龙 authored
241
        $this->assign('res',$res);
jinglong authored
242
        return $this->fetch();
景龙 authored
243 244 245 246 247 248
    }

    //独角快报更多
    public function getMoreNews(){
        $position['category_id'] = CityCategoryModel::djkb;
        $field = 'id,thumbnail,post_title,post_excerpt,create_time';
jinglong authored
249 250 251 252
        $res = $this->getChildArticlePage($position,$field,6);
        $this->assign('res',$res['data']);
        $this->assign('page',$res['page']);
        return $this->fetch();
景龙 authored
253
    }
254 255 256 257

    //独角快报详情
    public function getNewsDetail(){
        $id = $this->request->param('id',0,'intval');
jinglong authored
258
        $field = 'id,thumbnail,post_title,post_excerpt,create_time,post_content,more';
259 260
        $starModel = new StarController();
        $res = $starModel->getDetail($id,$field);
jinglong authored
261 262 263 264
        if($res){
            $more = json_decode($res['more'],true);
            $res['image_url'] = isset($more['photos']) && !empty($more['photos'])?$more['photos'][0]['url']:'';
        }
265
        $this->assign('res',$res);
jinglong authored
266
        return $this->fetch();
267 268
    }
269 270 271 272 273 274 275 276 277 278
    //独角日志更多
    public function getMoreNote(){
        $position['category_id'] = CityCategoryModel::djrz;
        $field = 'id,thumbnail avatar,index_thumbnail,post_title,post_excerpt,create_time';
        $res = $this->getChildArticlePage($position,$field,6);
        $this->assign('res',$res['data']);
        $this->assign('page',$res['page']);
        return $this->fetch();
    }
279 280 281 282 283 284 285
    //独角日志详情
    public function getNoteDetail(){
        $id = $this->request->param('id',0,'intval');
        $field = 'id,thumbnail avatar,full_name,post_excerpt,create_time,post_content';
        $starModel = new StarController();
        $res = $starModel->getDetail($id,$field);
        $this->assign('res',$res);
景龙 authored
286
        return $this->fetch();
287 288
    }
289 290 291 292 293 294 295 296 297 298
    //童趣未来更多
    public function getMoreFuture(){
        $position['category_id'] = CityCategoryModel::tqwl;
        $field = 'id,thumbnail,post_title,post_excerpt,create_time';
        $res = $this->getChildArticlePage($position,$field,5);
        $this->assign('res',$res['data']);
        $this->assign('page',$res['page']);
        return $this->fetch();
    }
299 300 301 302 303 304 305 306 307 308 309
    //童趣未来详情
    public function getFutureDetail(){
        $id = $this->request->param('id',0,'intval');
        $field = 'id,thumbnail,post_title,post_excerpt,create_time,post_content,more';
        $starModel = new StarController();
        $res = $starModel->getDetail($id,$field);
        if($res){
            $more = json_decode($res['more'],true);
            $res['image_url'] = isset($more['photos']) && !empty($more['photos'])?$more['photos'][0]['url']:'';
        }
        $this->assign('res',$res);
景龙 authored
310
        return $this->fetch();
311
    }
景龙 authored
312
}