审查视图

app/portal/controller/EnjoyController.php 4.2 KB
景龙 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?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 think\Db;
//星享体验
class EnjoyController extends HomeBaseController
{
    private $index_limit = 16;//首页分页
    private $more_limit = 8;//更多列表分页
    public function index(){
        //按照城市查询
23 24
        //默认澳大利亚
        $city_id = $this->request->param('city_id',35,'intval');
景龙 authored
25
        $position['city_id'] = $city_id;
26 27 28 29
        $this->assign('city_id',$city_id);
        //城市分类
        $city_name = $this->getCityName();
        $this->assign('city_name',$city_name);
景龙 authored
30 31 32 33

        //亲临现场
        $position['category_id'] = CityCategoryModel::qlxc;
        $field = 'id,thumbnail,post_title,post_excerpt';
34
        $res_qlxc = $this->getChildArticle($position,$field,$this->index_limit);
景龙 authored
35 36 37
        $this->assign('res_qlxc',$res_qlxc);

        //市井漫游
38 39 40 41
        $position['category_id'] = CityCategoryModel::sjmy;
        $field = 'id,thumbnail,post_title,post_excerpt,more';
        $res_sjmy = $this->getChildArticle($position,$field,$this->index_limit);
        foreach($res_sjmy as &$value){
景龙 authored
42 43 44 45 46 47 48
            $more = json_decode($value['more'],true);
            if(isset($more['photos']) && !empty($more['photos'])){
                $value['photos'] = $more['photos'][0]['url'];
            }else{
                $value['photos'] = '';
            }
        }
49
        $this->assign('res_sjmy',$res_sjmy);
景龙 authored
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

        //视听盛宴
        $position['category_id'] = CityCategoryModel::stsy;
        $field = 'id,thumbnail,post_title,post_excerpt';
        $res_stsy = $this->getChildArticle($position,$field);
        $this->assign('res_stsy',$res_stsy);

        //户外天堂
        $position['category_id'] = CityCategoryModel::hwtt;
        $field = 'id,thumbnail,post_title,post_excerpt';
        $res_hwtt = $this->getChildArticle($position,$field);
        $this->assign('res_hwtt',$res_hwtt);

        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('city_id',$position['city_id'])
            ->where('delete_time', 0)
            ->field($field)
            ->limit($limit)
            ->order('weigh desc')
            ->select()
            ->toArray();
        return $res;
    }
88 89 90 91 92 93 94 95 96 97 98 99

    //亲临现场,市井漫游,视听盛宴,户外天堂详情(页面底部有轮播图)
    public function getEnjoyDetail(){
        $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']:'';
        }
        $this->assign('res',$res);
100 101 102 103 104 105 106 107 108 109
        return $this->fetch(':enjoy_detail');
    }

    //获取城市名称
    public function getCityName(){
        $res = Db::name('city_category')
            ->where('pid','<>',0)
            ->where('delete_time',0)
            ->field('id,name')->select()->toArray();
        return $res;
110
    }
景龙 authored
111
}