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

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

class TableField extends Model{
	
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
	
    public static function table_list(){
		$table=Db::getTables();
        return $table;
	}

	//插入表
    public static function id_auto(){
		$max_id=Db::name('cate_type')->order('id desc')->limit(1)->select();
		$max_id=$max_id[0]['id']+1;
		$sql = "alter table tq_cate_type AUTO_INCREMENT=".$max_id."";
		Db::query($sql);
	}

	//插入表
    public static function table_add($table){
		$sql = "CREATE TABLE ".$table."( "."fid INT NOT NULL AUTO_INCREMENT, "."aid int(11) NOT NULL, "."PRIMARY KEY ( fid )); ";
		$add=Db::query($sql);
        return $add;
	}

	//删除表
    public static function table_delete($id,$table){
		$table="tq_article_".$table;
		$sql = "DROP TABLE ".$table.";";
		$add=Db::query($sql);	
        return 1;
	}

	//插入字段
    public static function field_add(){
		$tdata=Request::param();
		$num=$tdata['field_num']?:0;
		$sql="alter table ".$tdata['pid']." add ".$tdata['field_name']." ".$tdata['field_type']."(".$num.") NULL";
		$add=Db::query($sql);
        return $tdata;
	}

	//删除字段
    public static function field_delete(){
		$tdata=Request::param();
		$sql="alter table ".$tdata['pid']." drop column ".$tdata['name']."";
		$add=Db::query($sql);
        return 1;
	}

}