<?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 Model extends Controller
{
    //模型首页
    public function index()
    {
        
        
        hook('phpindexindex');
        $c = Db::name('model')->where(array('name' => input('model')))->find();
        $this->assign('c', $c);
        $muban='./app/template/'.muban().'/model/'.dingyi(guoji($c['name'].'_model'),'index').'.html';
        if(!is_file($muban)){
	        exit('模板文件不存在请创建模板 '.$muban);
        }
        return view($muban);
    }
    //分类
    public function cate()
    {
        hook('phpmodelcate');
        if (input('alias')) {
            $c = Db::name('cate_m')->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_m', array('id' => $c['tid']), 'name');
        }
        $this->assign('id', $id);
        $this->assign('name', $name);
        $muban='./app/template/'.muban().'/model/'.dingyi(guoji($c['alias'].'_'.$c['m']),'cate').'.html';
        if(!is_file($muban)){
	        exit('模板文件不存在请创建模板 '.$muban);
        }
        return view($muban);
    }
    // 详情页面
    public function html()
    {
        hook('phpindexhtml');
        $t = Db::name(input('model'))->where(array('id' => input('id'), 'open' => 1))->find();
        $this->assign('t', $t);
        $cate = Db::name('cate_m')->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'=>'付费阅读'.input('model'),'tid'=>$t['id']))!=0){
                $fufei=0;
            }
        }
        $this->assign('fufei', $fufei);
        if (empty($t['id'])) {
            return $this->error('页面不存在','/');
        }
        Db::name(input('model'))->where('id', input('id'))->setInc('view', 1);
        $muban='./app/template/'.muban().'/model/'.dingyi(guoji($cate['alias'].'html_'.$cate['m']),'html').'.html';
        if(!is_file($muban)){
	        exit('模板文件不存在请创建模板 '.$muban);
        }
        return view($muban);
    }
    // 搜索
    public function soso()
    {
        hook('phpmodelsoso');
        return view();
    }
}