<?php

namespace app\controller;

use think\Controller;

use think\Db;

class Index extends Controller

{

    public function index()
    { 





	$user=db('news');

 $rs3=$user->limit(0,9)->order('h desc')->select();

 $rs6=$user->limit(0,9)->order('Id desc')->select();

$config=db('config')->where('Id',1)->find();

$clist=db('class')->where("zt=1")->order('pid,Id desc')->select();

require_once("./api/php.php");

if (file_exists("cache/index.html")){

$fileTime =time()-filemtime("cache/index.html");

$ftime=floor($fileTime/60);

$cc=0;

}else{

$cc=1;

}
 

 


//echo $str;


$file = './cc.txt'; //先读取文件 


 $cbody = file($file); //file（）函数作用是返回一行数组，txt里有三行数据，因此一行被识别为一个数组，三行被识别为三个数组



//print_r($cbody);


if (file_exists("i_key.html")){



$fileTime =time()-filemtime("i_key.html");

$ftime=floor($fileTime/60);


$cc=0;


}else{



$cc=1;

} 


if ($ftime<$config['key_time']  && $cc==0 ){ 


$ss = file_get_contents('i_key.html');



}else{

$zs=count($cbody);


$ss=rand(0,$zs-$config['keys3']);


$fp = fopen('i_key.html','w+'); 

flock($fp,LOCK_EX);//独占锁定,为防止同一时间多个用户更新这个缓存文件

fwrite($fp,$ss);

flock($fp,LOCK_UN);//释放锁定


fclose($fp);

}

 $this->assign('ss',$ss);

$this->assign('cbody',$cbody);

$cid=db('class')->where("nindex=1 and zt=1")->order('pid,id desc')->select();

$this->assign('cid',$cid);

$this->assign('rs3',$rs3);

$this->assign('rs6',$rs6);

//$this->assign('vip',$str['data']['list']);

$this->assign('cc3',$cc3);

$this->assign('cc',$cc);



//$str=iconv('GB2312', 'UTF-8',$str);



//echo $str;



$this->assign('p',$p);


$this->assign('clist',$clist);

$this->assign('config',$config);



  return view();



    }



}



