<?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; use app\portal\model\PortalPostModel; use think\Db; //星域秀场 class RegionController extends HomeBaseController { private $index_limit = 16;//首页分页 private $more_limit = 8;//更多列表分页 public function index(){ //星球影院 $position['category_id'] = CityCategoryModel::xqyy; $field = 'id,more,thumbnail'; $res_xqyy = $this->getChildArticle($position,$field,1); foreach($res_xqyy as &$value){ $more = json_decode($value['more'],true); $value['video'] = isset($more['video']) && !empty($more['video'])?$more['video']:''; } if($res_xqyy){ $res_xqyy = $res_xqyy[0]; } $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); if($res_mxft){ $res_mxft = $res_mxft[0]; } $this->assign('res_mxft',$res_mxft); //星球故事 $position['category_id'] = CityCategoryModel::xqgs; $field = 'id,thumbnail,post_excerpt,more,excerpt'; $res_xqgs = $this->getChildArticle($position,$field,$this->index_limit); foreach($res_xqgs as &$value){ $more = json_decode($value['more'],true); $value['audio'] = isset($more['audio']) && !empty($more['audio'])?$more['audio']:''; $contentModel = new PortalPostModel(); $value['excerpt'] = $contentModel->getPostContentAttr($value['excerpt']); } $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; $field = 'id,thumbnail avatar,index_thumbnail,post_title,post_excerpt,more'; $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'; $res_tqwl = $this->getChildArticle($position,$field,2); $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; } //根据子类获取文章分页 public function getChildArticlePage($position,$field,$limit=''){ $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'); //查询文章 $res = Db::name('portal_post') ->whereIn('id',$post_id) ->where('delete_time', 0) ->field($field) ->order('weigh desc') ->paginate($limit); $arr['data'] = $res->toArray(); $arr['page'] = $res->render(); return $arr; } //获取城市分类 public function getCityCategory($id){ $city_name = Db::table('cmf_city_category') ->where('id',$id) ->field('name') ->find(); return $city_name['name']; } //星球影院更多(按照城市查询) public function getMoreVideo(){ $city_id = $this->request->param('city_id',0,'intval'); //城市名字 $star = new StarController(); $cityName = $star->getCityName($city_id); $this->assign('cityName',$cityName); $position['city_id'] = $city_id; $position['category_id'] = CityCategoryModel::xqyy; $field = 'id,post_title,framing,release_time,city_id,more,thumbnail'; $res = $star->getChildArticlePage($position,$field,'-1'); foreach($res['data']['data'] as &$value){ $more = json_decode($value['more'],true); $value['video'] = isset($more['video']) && !empty($more['video'])?$more['video']:''; $value['city_name'] = $this->getCityCategory($value['city_id']); } $this->assign('res',$res['data']); $this->assign('page',$res['page']); //城市分类 $city_name = $this->getVideoCityName(); $this->assign('city_name',$city_name); $this->assign('city_id',$city_id); return $this->fetch(); } //获取城市名称 public function getVideoCityName(){ $res = Db::name('city_category') ->where('pid','<>',0) ->where('id','<>',CityCategoryModel::xqgh_cc) ->where('is_show',1) ->where('delete_time',0) ->field('id,name') ->order('weigh desc') ->select() ->toArray(); return $res; } //明星访谈更多 public function getMoreStar(){ $position['category_id'] = CityCategoryModel::mxft; $field = 'id,thumbnail avatar,full_name,position,trade,post_excerpt'; $res = $this->getChildArticlePage($position,$field,5); $this->assign('res',$res['data']); $this->assign('page',$res['page']); return $this->fetch(); } //明星访谈详情 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); return $this->fetch(); } //星球故事更多 public function getMoreStory(){ $position['category_id'] = CityCategoryModel::xqgs; $field = 'id,thumbnail,post_excerpt,more,create_time,excerpt'; $res = $this->getChildArticlePage($position,$field); foreach($res['data']['data'] as &$value){ $more = json_decode($value['more'],true); $value['audio'] = isset($more['audio']) && !empty($more['audio'])?$more['audio']:''; $contentModel = new PortalPostModel(); $value['excerpt'] = $contentModel->getPostContentAttr($value['excerpt']); } $this->assign('res',$res['data']); $this->assign('page',$res['page']); return $this->fetch(); } //星域画廊更多 public function getMoreGallery(){ $position['category_id'] = CityCategoryModel::xyhl; $field = 'id,thumbnail'; $res = $this->getChildArticlePage($position,$field,16); $this->assign('res',$res['data']); $this->assign('page',$res['page']); //封面图 $imgModel = new IndexController(); $coverImg = $imgModel->getCoverImg(CityCategoryModel::galleryImg,1); $this->assign('coverImg',$coverImg); 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']:''; $res['m_image_url'] = isset($more['m_photos']) && !empty($more['m_photos'])?$more['m_photos']:''; } $this->assign('res',$res); return $this->fetch(); } //独角快报更多 public function getMoreNews(){ $position['category_id'] = CityCategoryModel::djkb; $field = 'id,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(); } //独角快报详情 public function getNewsDetail(){ $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); return $this->fetch(); } //独角日志更多 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(); } //独角日志详情 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); return $this->fetch(); } //童趣未来更多 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(); } //童趣未来详情 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); return $this->fetch(); } }