<?php
/*
 *	www.myucms.com
 *  作者：梦雨
 *  @ QQ50361804
*/
namespace app\index\controller;
use think\Controller;
use think\Db;
class Index extends Controller
{
    function _initialize()
    {
        parent::_initialize();
    }
  
   public function index(){

      if (config('web.WEB_INDEX') == 'shop') {
        //分类展示
        $show['show'] = 1;
        $shopcate = Db::name('shopcate');
        $gjfl = $shopcate->where("tid = 0")->where($show)->order('sort desc')->select();
        foreach ($gjfl as $ks => $vc) {
            $gjfl[$ks]['count'] = Db::name('shops')->where('tid', $vc['id'])->count();
        }
        $this->assign('gjfl', $gjfl);
        $gjz = $shopcate->where("tid != 0")->where($show)->order('sort desc')->select();
        foreach ($gjz as $ks => $vc) {
            $gjz[$ks]['count'] = Db::name('shops')->where('tid', $vc['id'])->count();
        }
        $this->assign("gjz", $gjz);
     }
     
       if (config('web.WEB_INDEX') == 'bbs') {
        $show['show'] = 1;
        //分类板块展示
        $category = Db::name('category');
        $gjfl = $category->where("tid = 0")->order('sort desc')->select();
        $gjfls = $category->where("tid != 0")->order('sort desc')->select();
        foreach ($gjfls as $ks => $vc) {
            $gjfls[$ks]['count'] = Db::name('forum')->where('tid', $vc['id'])->count();
        }
        $this->assign('gjfl', $gjfl);
        $this->assign('gjfls', $gjfls);
        //分类数据
        $artbycatelist = Db::name('category')->where($show)->order('sort desc')->select();
        foreach ($artbycatelist as $k => $v) {
            $artbycatelist[$k]['artlists'] = get_articles_by_cid($v['id'], 5);
        }
        $this->assign('artbycatelist', $artbycatelist);
        $forum = Db::name('forum');
        $open['open'] = 1;
        $settop['settop'] = 1;
        $t = input('t');
        if ($t == 'index' || $t == '') {
            //最新
            $gzc = $forum->alias('f')->join('category c', 'c.id=f.tid')->join('member m', 'm.userid=f.uid')->field('f.*,c.id as cid,m.userid,m.userhead,m.username,c.name')->where($open)->order('f.settop desc , f.id desc')->paginate(15);
            $this->assign('gzc', $gzc);
        } elseif ($t == 'news') {
            //最新
            $gzc = $forum->alias('f')->join('category c', 'c.id=f.tid')->join('member m', 'm.userid=f.uid')->field('f.*,c.id as cid,m.userid,m.userhead,m.username,c.name')->where($open)->order('f.id desc')->paginate(15, false, ['query' => request()->param()]);
            $this->assign('gzc', $gzc);
        }
        $c = array('type' => config('web.Cascade'));
        $this->assign('c', $c);
        $this->assign('t', $t);
          }
        print s(); return view();
   }

}