审查视图

app/portal/controller/ActiveController.php 2.8 KB
景龙 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?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 ActiveController extends HomeBaseController
{
    private $index_limit = 16;//首页分页
20
    private $more_limit = 5;//更多列表分页
景龙 authored
21 22
    public function index(){
        //星际活动
jinglong authored
23 24 25 26 27 28

        //封面图
        $imgModel = new IndexController();
        $coverImg = $imgModel->getCoverImg(CityCategoryModel::activeImg,1);
        $this->assign('coverImg',$coverImg);
景龙 authored
29 30
        $position['category_id'] = CityCategoryModel::xjhd_c;
        $field = 'id,thumbnail,post_title';
31 32 33
        $res = $this->getChildArticlePage($position,$field);
        $this->assign('res',$res['data']);
        $this->assign('page',$res['page']);
景龙 authored
34 35 36 37
        return $this->fetch();
    }

    //根据子类获取文章分页
38
    public function getChildArticlePage($position,$field,$limit=''){
景龙 authored
39 40 41 42 43 44 45 46 47 48 49
        $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::table($pre.'portal_post')
            ->whereIn('id',$post_id)
景龙 authored
50
            ->where('delete_time',0)
景龙 authored
51 52
            ->field($field)
            ->order('weigh desc')
53 54 55
            ->paginate($limit);
        $arr['data'] = $res->toArray();
        $arr['page'] = $res->render();
景龙 authored
56
        return $arr;
景龙 authored
57
    }
58 59 60 61 62 63 64 65 66 67

    //星际活动详情
    public function getActiveDetail(){
        $id = $this->request->param('id',0,'intval');
        //活动外链登录后可见(active_url)
        $field = 'id,thumbnail,post_title,post_excerpt,post_content,active_url,create_time,more';
        $starModel = new StarController();
        $res = $starModel->getDetail($id,$field);
        if($res){
            $more = json_decode($res['more'],true);
景龙 authored
68
            $res['image_url'] = isset($more['photos']) && !empty($more['photos'])?$more['photos'][0]['url']:'';
69 70
        }
        $this->assign('res',$res);
景龙 authored
71
        return $this->fetch();
72
    }
景龙 authored
73
}