<?php
/*
 +----------------------------------------------------------------------
 | TEMMOKUMVC [ NO BEST , ONLY BETTER ]
 +----------------------------------------------------------------------
 | Copyright (c) 2018~2019 https://www.temmoku.cn All rights reserved.
 +----------------------------------------------------------------------
 | Author: 张宗强 Email:webmaster@temmoku.cn QQ:158726877 516669373 TEL:17895221001 微信:temmokumvc
 +---------------------------------------------------------------------- 
*/
namespace home\controller;
use \temmoku\db;
use \temmoku\controller;
class index extends controller
{

    // 首页方法，测试框架自定义DB查询
    public function index()
    {
		$cache_dir=RUNTIME_PATH."/cache/".MODULE.'/'.DEVICE."/index.txt";
    	if(C('index_cache_time') && is_file($cache_dir) && time()-@filemtime($cache_dir) < C('index_cache_time')*3600){
    		echo get_cache($cache_dir);
    		exit;
    	}
    	//title标签
    	$TITLE=C('WEB_SEO_WEBNAME').'_'.C('WEBNAME');
    	//关键字标签
    	$KEYWORDS=C('WEB_SEO_KEYWORDS');
    	//描述标签
    	$DESCRIPTION=C('WEB_SEO_DESCRIPTION');
    	
    	$this->assign('WEBNAME',$TITLE);
    	$this->assign('KEYWORDS',$KEYWORDS);
    	$this->assign('DESCRIPTION',$DESCRIPTION);
    	//不是pc设备才去获取
		if(DEVICE !='pc'){
			//网站名称,或者是栏目名称
			$this->assign('webname',C('webname'));
			//获取所有一级栏目
			$menu_more_list=db::select('*')->from(jab.'category')->where("upcid=0")->query();
			$this->assign('menu_more_list',$menu_more_list);
			
			//获取最新5张图片内容
			$new_photo=db::select('*')->from(jab.'article')->where("state=1 AND is_pic=1")->limit(5)->orderByDESC(['aid'])->query();
			$this->assign('new_photo',$new_photo);
			//根据一级栏目获取相关内容
			$list=[];
			foreach($menu_more_list as $row){
				$cid=C('home|category_setting.'.$row['cid'])[son] ? C('home|category_setting.'.$row['cid'])[son] : $row['cid'];
				$list[$row['cid']]=db::select('*')->from(jab.'article')->where("state=1 AND cid IN (".$cid.")")->orderByDESC(['aid'])->limit(10)->query();
			}
			$this->assign('list',$list);
		}
        $this->display(tpl('index'));
        if(C('index_cache_time')){
			write_file($cache_dir,ob_get_contents());
		}
    }
}
?>