SuccessorController.class.php 3.9 KB
<?php
/**
 * Created by PhpStorm.
 * User: 29925
 * Date: 2018/4/2
 * Time: 13:34
 */

namespace Portal\Controller;

use Common\Controller\HomebaseController;

class SuccessorController extends HomebaseController {

    protected $successor_model;
    protected $successor_produce_model;

    function _initialize() {
        parent::_initialize();
        $this->successor_model = D("Common/Successor");
        $this->successor_produce_model = D("Common/SuccessorProduct");
    }

    // 传承人列表
    public function index(){
        $this->region();
        $this->nation();
        $this->product();
        if(I('get.product',0,'intval')) {
            $this->product_son(I('get.product'));
        }
        $this->assign('sex', array('1'=>'男', '2'=>'女'));
        $this->assign('level', array('国家级', '省市级', '地区级', '县级'));
        $this->assign('search',I('get.'));
        $where['is_del'] = 0;
        if(I('get.product')){
            $where['sort_path'] = array('like','0-'.I('get.product').'%');
        }
        if(I('get.product_son')){
            $where['sort_id'] = I('get.product_son');
        }
        if(I('get.sex')){
            $where['sex'] = I('get.sex');
        }
        if(I('get.level')){
            $where['level'] = I('get.level');
        }
        if(I('get.region')){
            $where['region'] = I('get.region');
        }
        if(I('get.nation')){
            $where['nation'] = I('get.nation');
        }
        $this->searchArray(I('get.'));
        $this->_lists($where);
        $this->display();
    }

    // 处理搜索条件数据
    private function searchArray($get) {
        // 各筛选条件url处理
        // 一级分类
        $url['product_all'] = $get;
        unset($url['product_all']['product']);
        unset($url['product_all']['product_son']);
        $url['product_search'] = $get;
        unset($url['product_search']['product']);
        // 二级分类
        $url['son_all'] = $get;
        unset($url['son_all']['product_son']);
        $url['son_search'] = $get;
        unset($url['son_search']['product_son']);
        // 性别
        $url['sex_all'] = $get;
        unset($url['sex_all']['sex']);
        $url['sex_search'] = $get;
        unset($url['sex_search']['sex']);
        // 级别
        $url['level_all'] = $get;
        unset($url['level_all']['level']);
        $url['level_search'] = $get;
        unset($url['level_search']['level']);
        // 区域
        $url['region_all'] = $get;
        unset($url['region_all']['region']);
        $url['region_search'] = $get;
        unset($url['region_search']['region']);
        // 民族
        $url['nation_all'] = $get;
        unset($url['nation_all']['nation']);
        $url['nation_search'] = $get;
        unset($url['nation_search']['nation']);
        $this->assign('search_url',$url);
        return $url;
    }

    // 传承人详情
    public function detail(){
        $id = I('get.id',0,'intval');
        if(!$id) {
            $this->error('参数错误');
        }
        $productList = $this->successor_produce_model->getAllList($id);
        $info = $this->successor_model->getInfo($id);
        $this->assign($info);
        $this->assign('productList',$productList);
        $this->display();
    }

    /**
     * 地方非遗列表处理方法,根据不同条件显示不同的列表
     * @param array $where 查询条件
     */
    private function _lists($where=array()){
        $where['is_del'] = 0;

        $this->successor_model
            ->where($where);

        $count = $this->successor_model->count();

        $page = $this->pages($count, 9);

        $posts = $this->successor_model
            ->where($where)
            ->limit($page->firstRow , $page->listRows)
            ->order("ctime DESC")
            ->select();
        $this->assign("page", $page->show('new'));
        $this->assign("posts",$posts);
    }
}