<?php
namespace app\admin\controller;
use think\App;
use think\facade\Session;
use think\facade\Request;

class common extends Base{
	
    public function is_edit(){
		IS_AJAX(Request::isAjax());
		$info=\app\admin\model\Common::state_edit();
		$data =['ok' =>'1','msg' =>'修改成功'];
		return json($data);
    }
	
	//单个真删除
    public function delete_id(){
		IS_AJAX(Request::isAjax());
		$info=\app\admin\model\Common::delete_id();
		
		if($info==2){
		$data =['ok' =>'2','msg' =>'请先删除下级栏目和该栏目下的内容'];
		return json($data);
		}
		
		$tdata=Request::param();
		$log_content='信息';
		if($tdata['table']=='cate'){
			$log_content='栏目';
		}
		if($tdata['table']=='admin'){
			$log_content='管理员';
		}
		if($tdata['table']=='log'){
			$log_content='日志';
		}
		//添加日志
		$log=\app\admin\model\Log::insert('删除'.$log_content.':数据ID='.$tdata['id'].'');
		
		$data =['ok' =>'1','msg' =>'已删除'];
		return json($data);
    }

	//article假删除
    public function article_delete(){
		IS_AJAX(Request::isAjax());
		$tdata=Request::param();
		
		$tdata['is_delete']=0;
		$info=\app\admin\model\Article::update($tdata);

		//添加日志
		$log=\app\admin\model\Log::insert('删除文章:数据ID='.$tdata['id'].'');

		$data =['ok' =>'1','msg' =>'已删除'];
		return json($data);
    }

	//article批量假删除
    public function list_delete(){
		IS_AJAX(Request::isAjax());
		$info=\app\admin\model\Common::list_delete();

		//添加日志
		$tdata=Request::param();
		$log=\app\admin\model\Log::insert('批量删除文章:共'.count($tdata['id']).'条');

		$data =['ok' =>'1','msg' =>'已删除'];
		return json($data);
    }

	//批量删除
    public function list_delete_true(){
		IS_AJAX(Request::isAjax());
		$info=\app\admin\model\Common::list_delete_true();

		//添加日志
		$tdata=Request::param();
		$log_content='信息';
		if($tdata['table']=='log'){
			$log_content='日志';
		}
		$log=\app\admin\model\Log::insert('批量删除'.$log_content.':共'.count($tdata['id']).'条');

		$data =['ok' =>'1','msg' =>'已删除'];
		return json($data);
    }

	//article批量恢复
    public function list_back(){
		IS_AJAX(Request::isAjax());
		$info=\app\admin\model\Common::list_back();
		$data =['ok' =>'1','msg' =>'已恢复'];
		return json($data);
    }
	
	//article单个恢复
    public function back_id(){
		IS_AJAX(Request::isAjax());
		$tdata=Request::param();
		$tdata['is_delete']=1;
		$info=\app\admin\model\Article::update($tdata);
		$data =['ok' =>'1','msg' =>'已恢复'];
		return json($data);
    }

	//全局公用排序-按钮模式
    public function is_sort(){
		IS_AJAX(Request::isAjax());
		$type=\app\admin\model\Common::is_sort();
		$data =['type' =>$type,'msg' =>'成功'];
		return json($data);
    }

	//全局公用排序-input
    public function sort_all(){
		IS_AJAX(Request::isAjax());
		$type=\app\admin\model\Common::sort_all();
		$data =['type' =>$type,'msg' =>'成功'];
		return json($data);
    }

	//判断自动每页合适条数:form模块的翻页
    public function limit_session(){
		IS_AJAX(Request::isAjax());
		$tdata=Request::param();
		Session::set('limit',$tdata['limit']);
		$data =['type' =>$tdata,'msg' =>'ok'];
		return json($data);
	}

	//后台栏目关闭判断所有子栏目
    public function cate_open(){
		IS_AJAX(Request::isAjax());
		$tdata=Request::param();
		$id_array=get_id_array($tdata['id'],1);
		$data =['id_array' =>$id_array,'msg' =>'ok'];
		
		return json($data);
	}

    
}
