<?php
namespace app\index\model;
use think\Model;

// 引入框架内置类
use think\facade\Db;
use think\facade\Event;
use think\facade\Session;
use think\facade\Request;

class Details extends Model{
	
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';

	//文章详情
	public static function info($id){
		$info =Db::name('article')->find($id);
		$admin_id=Session::get('admin_id');
		//停用,删除,或不存在
		if(($info['is_effect']!=1 or $info['is_delete']!=1 or empty($info)) and $admin_id==''){
			return 1;
		}else{
			$model_id=tq_value($info['pid'],'model_id','cate');
			$cate_id=tq_value($info['pid'],'id','cate');
			$table=tq_value($model_id,'table','cate_type');
			if($model_id=='' or $cate_id=='' or $table==''){
				return 1;
			}else{
				$info['view']=tq_value($info['pid'],'view_info','cate');
				$info['catename']=tq_value($info['pid'],'catename','cate');
				$table='article_'.$table;
				$infof =Db::name($table)->where('aid',$id)->find();
				return $info+$infof;
			}
		}
	}


	//文章详情//待确认是否有用
	public static function pid($id){
		$info =Db::name('article')->find($id);
		return $info['pid'];
	}

	//增加点击量
	public static function article_ck($id){
		$id=Db::name('article')->where('id',$id)->inc('number',1)->update();
	}


}