ProductController.php 5.5 KB
<?php
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;

class ProductController 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 product(){

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

    $cpid = Db::name('portal_category_post') -> where('category_id',12) -> find();
    $cpdata = Db::name('portal_post') -> where('id',$cpid['post_id']) -> find();
    $cpdata['post_content'] = cmf_replace_content_file_url(htmlspecialchars_decode($cpdata['post_content']));
    $this -> assign('category',$cpdata['id']);
    $this -> assign('zuixin',$cpdata);

/*    $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'];
       }
    }

  $zuixin = Db::name('portal_post') -> where('id','in',$arr3) -> where('delete_time',0) -> order('create_time desc') -> limit(1) ->  select();
  $zzz = $zuixin[0];

  $zzz['post_content'] = cmf_replace_content_file_url(htmlspecialchars_decode($zzz['post_content']));
  $this -> assign('zuixin',$zzz);

  //将最新文章的说明文献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);*/




    return $this -> fetch();

  }

  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;



  }


  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 wenzhang(){

    $id = input('post.id');
    $data = Db::name('portal_category_post') -> where('category_id',$id) -> select();
    foreach ($data as $key => $value) {
      $wzs = Db::name('portal_post') -> where('id',$value['post_id']) -> where('delete_time',0)  -> find();
      if($wzs != null){
          $arr[] = $wzs;
      }

    }

    return json_encode($arr);

  }*/

  //查询单个文章
  public function danwz(){

    $id = input('post.id');
    $shuju = Db::name('portal_category_post') -> where('category_id',$id) ->find();

    $data = Db::name('portal_post') -> where('id',$shuju['post_id']) -> find();
    $data['post_content'] = cmf_replace_content_file_url(htmlspecialchars_decode($data['post_content']));

    return json_encode($data);

  }

  //详情页
  public function details(){

    $id = input('get.id');
    $data = Db::name('portal_post') -> where('id',$id) -> find();
    $data['post_content'] = cmf_replace_content_file_url(htmlspecialchars_decode($data['post_content']));
    $this -> assign('data',$data);

    $cid = Db::name('portal_category_post') -> where('post_id',$id) -> find();
    $shuju = Db::name('portal_category') -> where('id',$cid['category_id']) -> find();
    $this -> assign('shuju',$shuju);

    $pshuju = Db::name('portal_category') -> where('id',$shuju['parent_id']) -> find();
    $this -> assign('pshuju',$pshuju);

    return $this -> fetch();

  }

  //coa 说明 文献
  public function commp(){

    $id = $this -> request -> param();
    $data = Db::name('docu_coa') -> where('id',$id['id']) -> find();
    $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
    $this -> assign('data',$data);
    return $this -> fetch();

  }

  public function commps(){


    $id = input('post.id');

    $data = Db::name('docu_coa') -> where('post_id',$id) -> select();
    foreach ($data as $key => $value) {
      $value['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($value['content']));
    }


    return json_encode($data);

  }


  //显示产品中心
  public function chanpins(){

    $data = Db::name('portal_category_post') -> where('category_id',12) -> find();
    $shuju = Db::name('portal_post') -> where('id',$data['post_id']) -> find();
    $shuju['post_content'] = cmf_replace_content_file_url(htmlspecialchars_decode($shuju['post_content']));
    return json_encode($shuju);


  }


  public function erji(){


    $id = input('post.id');
    $data = Db::name('portal_category_post') -> where('category_id',$id) -> find();
    $shuju = Db::name('portal_post') -> where('id',$data['post_id']) -> find();
    $shuju['post_content'] = cmf_replace_content_file_url(htmlspecialchars_decode($shuju['post_content']));
    return json_encode($shuju);


  }





}





 ?>