<?php
namespace app\admin\controller;
use think\App;
use think\facade\Session;
use think\facade\View;
use think\facade\Request;
 
 
//use think\Controller;
//use \think\Session;
use \think\Cache;
use \think\Db;

class mysql extends Base{

    public function index(){

		return View::fetch();

    }

    public function back(){
		$tdata=Request::param();
		
         
        $type =$tdata['type'];//获取操作类型
        $name =$tdata['name'];//获取需要操作文件的名称
		
        $backup = new \backup\Backupsql(\think\facade\Config::get("database.connections.mysql"));
				
        switch ($type) {
            //备份
            case "backup":
                $info = $backup->backup();
				$log_name='备份';			
                break;
            //下载
            case "dowonload":
                $info = $backup->downloadFile($name);
				$log_name='下载';			
                break;
            //还原
            case "restore":
                $info = $backup->restore($name);
				$log_name='恢复';			
                break;
            //删除
            case "del":
                $info = $backup->delfilename($name);
				$log_name='删除';			
                break;
        }
		
		//添加日志
		$log=\app\admin\model\Log::insert('操作数据库:'.$log_name.'');

		$data =['type' =>2,'info'=>$info,'msg' =>'操作成功'];
		return json($data);
    }


    public function list_data(){
        $backup = new \backup\Backupsql(\think\facade\Config::get("database.connections.mysql"));
        $lists = $backup->get_filelist();

		$data['code']=0;
		$data['count']=count($lists);
		$data['data']=$lists;
		return json($data);
    }

}