<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021 http://115cms.com.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 作者@梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Index extends Controller
{
    //首页
    public function index()
    {
        hook('phpindexindex');
        return view();
    }
    //分类
    public function cate()
    {
        hook('phpindexcate');
        if (input('alias')) {
            $c = Db::name('cate')->where(array('alias' => input('alias')))->find();
            $this->assign('c', $c);
        } 
        // 始终获取顶级的id
        if ($c['tid']==0) {
            $id=$c['id'];
            $name=$c['name'];
        } else {
            $id=$c['tid'];
            $name=fun_sc_p('cate', array('id' => $c['tid']), 'name');
        }
        $this->assign('id', $id);
        $this->assign('name', $name);
        return $this->fetch('/index:'.dingyi(guoji($c['alias']),'cate'));
    }
    // 详情页面
    public function html()
    {
        hook('phpindexhtml');
        $t = Db::name('html')->where(array('id' => input('id'), 'open' => 1))->find();
        $this->assign('t', $t);
        $cate = Db::name('cate')->where(array('id' => $t['tid']))->find();
        $this->assign('cate', $cate);
        $fufei=0;
        // 判断是否需要付费
        if($t['jifen']!=0){
            $fufei=1;
            //判断是否付费
            if(fun_st('point_note',array('title'=>'付费阅读html','tid'=>$t['id']))!=0){
                $fufei=0;
            }
        }
        $this->assign('fufei', $fufei);
        if (empty($t['id'])) {
            return $this->error('页面不存在','/');
        }
        Db::name('html')->where('id', input('id'))->setInc('view', 1);
        return $this->fetch('/index:'.dingyi(guoji($cate['alias'].'html'),'html'));
    }
    // 搜索
    public function soso()
    {
        hook('phpindexsoso');
        return view();
    }
    //单页
    public function dan()
    {
        hook('phpindexdan');
        $dan = Db::name('dan')->where(array('alias' => input('alias'), 'open' => 1))->find();
        $this->assign('dan', $dan);
        if (!$dan['alias']) {
            return $this->error('页面不存在');
        }
        return $this->fetch('/index:'.$dan['muban']);
    }
    //单页2
    public function dans($alias)
    {
        hook('phpindexdans');
        return $this->fetch('/index:'.$alias);
    }
}