<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
use app\xmziqiangzheadmin\model\Menu;
class Base extends Controller
{
  public function __construct(){
    parent::__construct();
    $id=input('id');
    $cate = Db::name('category')->order('listorder')->find($id);

    $pages = Db::name('category')->field('a.id,a.catname,a.modelid,w.title,w.keywords,w.description,w.content,w.thumb')->alias('a')->join('pages w','a.id = w.catid','RIGHT')->find($id);

     

     $products = Db::name('category')->field('a.id,a.catname,a.modelid,w.title,w.keywords,w.productdesc,w.product')->alias('a')->join('product w','a.id = w.catid','RIGHT')->select($id);


     $pageres=db('pages')->field('id')->where('catid=1')->find();

     $this->assign('pageres',$pageres);
     $this->assign('products',$products);
     $this->assign('pages',$pages);
     $this->assign('cate',$cate);
     $site['wxewm']=db('system')->where(array('enname'=>'wxewm'))->value('value');
     $site['zfb']=db('system')->where(array('enname'=>'zfb'))->value('value');
    $site['zhmc']=db('system')->where(array('enname'=>'zhmc'))->value('value');
    $site['sitename']=db('system')->where(array('enname'=>'sitename'))->value('value');
    $site['tongji']=db('system')->where(array('enname'=>'tongji'))->value('value');
    $site['wappic']=db('system')->where(array('enname'=>'wappic'))->value('value');
    $site['logo']=db('system')->where(array('enname'=>'logo'))->value('value');
    $site['seo_title']=db('system')->where(array('enname'=>'seo_title'))->value('value');
    $site['seo_keywords']=db('system')->where(array('enname'=>'seo_keywords'))->value('value');
    $site['seo_description']=db('system')->where(array('enname'=>'seo_description'))->value('value');
    $site['lianxitel']=db('system')->where(array('enname'=>'lianxitel'))->value('value');
    $site['tel']=db('system')->where(array('enname'=>'tel'))->value('value');
    $site['gsphone']=db('system')->where(array('enname'=>'gsphone'))->value('value');
    $site['mailbox']=db('system')->where(array('enname'=>'mailbox'))->value('value');
    $site['address']=db('system')->where(array('enname'=>'address'))->value('value');
    $site['url']=db('system')->where(array('enname'=>'url'))->value('value');
    $site['copy']=db('system')->where(array('enname'=>'copy'))->value('value');
    $site['icp']=db('system')->where(array('enname'=>'icp'))->value('value');
    $site['fax']=db('system')->where(array('enname'=>'fax'))->value('value');
    $site['tongji']=db('system')->where(array('enname'=>'tongji'))->value('value');
    $site['cpkf']=db('config')->where(array('varname'=>'cpkf'))->value('value');
    $site['erweima']=db('system')->where(array('enname'=>'erweima'))->value('value');
    $site['qq1']=db('config')->where(array('varname'=>'qq1'))->value('value');
    $site['qq2']=db('config')->where(array('varname'=>'qq2'))->value('value');
    $site['qq3']=db('config')->where(array('varname'=>'qq3'))->value('value');
    $site['ww1']=db('config')->where(array('varname'=>'ww1'))->value('value');
    $site['ww2']=db('config')->where(array('varname'=>'ww2'))->value('value');
    $site['ww3']=db('config')->where(array('varname'=>'ww3'))->value('value');

        $catemenu = Db::name('category')->where('parentid',0)->order('listorder')->select();

        foreach ($catemenu as $key => $value) {
                  $sonmenu = Db::name('category')->where('parentid',$catemenu[$key]['id'])->select();

                  if($sonmenu){
                     foreach ($sonmenu as $keys => $values) {
                          $catemenu[$key]['son'][$keys]['name']=$sonmenu[$keys]['catname'];
                          $catemenu[$key]['son'][$keys]['id']=$sonmenu[$keys]['id'];

                     }
                  }
        }
        $catemenus = Db::name('category')->field('id','parentid')->select();
        
    $this->assign('catemenus', $catemenus);
    $this->assign('catemenu', $catemenu);
    $this->photo();
    // $this->test();
    $this->link();
    $this->partner();
    $this->assign(['site'=>$site,]);

}
  
  public function photo(){
    $pahotoimg=db('advertisement')->field('id,advename,advepic,advedesc,advewz,sort,adveurl')->order('sort desc')->select();
   $pahotoimgs['advepic']=str_replace("\\","/",$pahotoimg);
   for($i=0;$i<count($pahotoimgs['advepic']);$i++){
   $pahotoimgs['advepic'][$i]['advepic']=str_replace("\\","/",$pahotoimgs['advepic'][$i]['advepic']);

   }
   $newadress=$pahotoimg[0]['advepic'];
   $nradress=$pahotoimg[5]['advepic'];
   $jiesadress=$pahotoimg[1]['advepic'];
   // var_dump($jiesadress);
   // die;
   $nradress=str_replace("\\","/",$nradress);
   $newadress=str_replace("\\","/",$newadress);
   $this->assign('jiesadress',$jiesadress);
   $this->assign('nradress',$nradress);
   $this->assign('newadress',$newadress);
  
   $this->assign('pahotoimg', $pahotoimgs['advepic']);
  }
  public function link(){
    $linkres=db('link')->field('id,linkname,linkpic,linkurl')->select();
    $this->assign('linkres',$linkres);
  }

  public function partner(){
    $partres=db('partner')->field('id,paname,papic,paurl')->select();
    $this->assign('partres',$partres);
  }

  
   
  
}
