ScoutController.php 3.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 ScoutController extends HomeBaseController
{
    private $index_limit = 16;//首页分页
    public function index(){
        //旅游路线
        $position['category_id'] = CityCategoryModel::lylx;
        $field = 'id,thumbnail,post_title';
        $res_lylx = $this->getChildArticle($position,$field,1);
        $this->assign('res_lylx',$res_lylx);

        //地道风物
        $position['category_id'] = CityCategoryModel::ddfw;
        $field = 'id,thumbnail,post_title,price';
        $res_ddfw = $this->getChildArticle($position,$field);
        $this->assign('res_ddfw',$res_ddfw);

        //创意设计
        $position['category_id'] = CityCategoryModel::cysj;
        $field = 'id,thumbnail,post_title,price';
        $res_cysj = $this->getChildArticle($position,$field);
        $this->assign('res_cysj',$res_cysj);

        //悦己悦人
        $position['category_id'] = CityCategoryModel::yjyr;
        $field = 'id,thumbnail,post_title,price';
        $res_yjyr = $this->getChildArticle($position,$field);
        $this->assign('res_yjyr',$res_yjyr);

        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 getTravelDetail(){
        $id = $this->request->param('id',0,'intval');
        $field = 'id,thumbnail,notice,place,project,price,pay_url,post_title,post_excerpt,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);
    }

    //地道风物,创意设计,悦己悦人详情
    public function getSceneryDetail(){
        $id = $this->request->param('id',0,'intval');
        $field = 'id,thumbnail,price,pay_url,post_title,post_excerpt,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);
    }
}