<?php
namespace app\wap\controller;
use think\Controller;
use think\Db;
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);

     $pageres=Db::name('pages')->field('id,catid,title,keywords,tags,description,thumb,inputtime,content,url')->where("catid=1")->order('id desc')->limit('1')->select();

     $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);
     $this->assign('pageres',$pageres);
     $this->assign('products',$products);
     $this->assign('pages',$pages);
     $this->assign('cate',$cate);
    $site['weixin']=db('system')->where(array('enname'=>'weixin'))->value('value');
    $site['sitename']=db('system')->where(array('enname'=>'sitename'))->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['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('isend',0)->order('id')->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'];
                     }
                  }
        }

    $this->assign('catemenu', $catemenu);
    $this->photo();

    $this->assign(['site'=>$site,]);

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

   $this->assign('pahotoimg', $pahotoimg);
  }

  
   
  
}
