ActiveController.php 2.6 KB
<?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;//首页分页
    private $more_limit = 6;//更多列表分页
    public function index(){
        //星际活动
        $page = $this->request->param('page',1,'intval');
        $position['category_id'] = CityCategoryModel::xjhd_c;
        $field = 'id,thumbnail,post_title';
        $res_xjhd = $this->getChildArticlePage($position,$field,$page);
        $this->assign('res_xjhd',$res_xjhd);

        return $this->fetch();
    }

    //根据子类获取文章分页
    public function getChildArticlePage($position,$field,$page,$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::table($pre.'portal_post')
            ->whereIn('id',$post_id)
            ->where('delete_time', 0)
            ->field($field)
            ->page($page,$limit)
            ->order('weigh desc')
            ->select()
            ->toArray();
        return $res;
    }

    //星际活动详情
    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);
            $res['image_url'] = isset($more['photos']) && !empty($more['photos'])?$more['photos']:'';
        }
        $this->assign('res',$res);
    }
}