ListController.php 5.0 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <bronet@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use app\portal\model\PortalCategoryModel;
use think\Db;

class ListController extends HomeBaseController
{

  public function _initialize(){

    parent::_initialize();
    $data = Db::name('slide_item') -> where('slide_id',3) -> find();
    $this -> assign('logo',$data);

    $shuju = Db::name('nav_menu') -> select();

    $data2 = $this -> daohang($shuju);

    $this -> assign('data2',$data2);

  }

  public function daohang($data,$pid=0){

    $arr = [];
    foreach ($data as $key => $value) {
       if($value['parent_id'] == $pid){
          $value['son'] = $this -> daohang($data,$value['id']);
          $arr[] = $value;

       }
    }
    return $arr;


  }



    public function index()
    {
        $id                  = $this->request->param('id', 0, 'intval');
        $portalCategoryModel = new PortalCategoryModel();

        $category = $portalCategoryModel->where('id', $id)->where('status', 1)->find()->toArray();

        $this->assign('category', $category);

        $path = explode('-', $category['path']);



        //产品介绍
        if($path[1] == 12){

/*          $jdata[] = Db::name('portal_category') -> where('id',$path[2]) -> find();

          $jdata[0]['son'] = Db::name('portal_category') -> where('parent_id',$path[2]) -> select();

          $this -> assign('jdata',$jdata);

          $data = Db::name('portal_category') -> select();

          $shuju2 = $this -> wuxianx($data);


            foreach ($shuju2 as $key => $value) {
              $arr[] = $value['id'];
            }

            foreach ($arr as $key => $value) {
              $arr1[] = Db::name('portal_category_post') -> where('category_id',$value) -> select();
            }



            foreach ($arr1 as $key => $value) {
               foreach ($value as $k => $va) {
                 $arr3[] = $va['post_id'];
               }
            }*/

            $data = Db::name('portal_category') -> select();
            $shuju = $this -> wuxian($data);

            $this -> assign('jdata',$shuju);



            if(count($path) == 4){

              //将最新文章的说明文献coa显示

              $cos_data = Db::name('docu_coa') -> where('post_id',$category['id']) -> select();
              $this -> assign('cos_data',$cos_data);

              //显示文章
              $post_data = Db::name('portal_category_post') -> where('category_id',$category['id']) -> find();
              $wh_data = Db::name('portal_post') -> where('id',$post_data['post_id']) -> find();
              $wh_data['post_content'] = cmf_replace_content_file_url(htmlspecialchars_decode($wh_data['post_content']));
              $this -> assign('zuixin',$wh_data);
              $this -> assign('category',$category['id']);

            }else{

              $id = Db::name('portal_category_post') -> where('category_id',$path[2]) -> find();
              $wz_data = Db::name('portal_post') -> where('id',$id['post_id']) -> find();
              $this -> assign('zuixin',$wz_data);

              //将最新文章的说明文献coa显示
              $post_data = Db::name('portal_category_post') -> where('post_id',$zzz['id']) -> find();
              $cos_data = Db::name('docu_coa') -> where('post_id',$post_data['category_id']) -> select();
              $this -> assign('cos_data',$cos_data);

            }


        }

        //新闻分类
        if($path[2] == 16){

           $this -> redirect('New/newlist');

        }

        //管理团队
        if($path[2] == 23 || $path[2] == 24){

           $this->redirect('New/guanli',['id'=>$category['id']]);

        }

        //支持 预留
        if($path[1] == 25 || $path[1] == 18){

          $this -> redirect('Support/index',['id'=>$path[2],'pid'=>$path[1]]);

        }


        $listTpl = empty($category['list_tpl']) ? 'list' : $category['list_tpl'];

        return $this->fetch('/' . $listTpl);
    }



    public function wuxianx($data,$pid=12){

      static $arr=[];
      foreach ($data as $key => $value) {
        if($value['parent_id'] == $pid){
            $arr[] = $value;
            $this -> wuxianx($data,$value['id']);
        }
      }
      return $arr;

    }



    public function wuxian($data,$pid=12){

        $arr = [];
        foreach ($data as $key => $value) {
           if($value['parent_id'] == $pid){
              $value['son'] = $this -> daohang($data,$value['id']);
              $arr[] = $value;

           }
        }
        return $arr;



    }





}