diff --git a/app/admin/controller/Database.php b/app/admin/controller/Database.php new file mode 100644 index 0000000..aa3e70d --- /dev/null +++ b/app/admin/controller/Database.php @@ -0,0 +1,102 @@ +hostname = Config::get('database.connections.mysql.hostname'); + $this->hostport = Config::get('database.connections.mysql.hostport'); + $this->database = Config::get('database.connections.mysql.database'); + $this->username = Config::get('database.connections.mysql.username'); + $this->password = Config::get('database.connections.mysql.password'); + } + + public function index() + { + if(Request::isAjax()){ + $backName = Files::getDirName('../data'); + + $res['count'] = count($backName); + if($res['count']){ + $res['code'] = 0; + $res['msg'] = ''; + $res['data'] = []; + foreach($backName as $k=>$v){ + $res['data'][] = ['id' => $k, + 'time' => $v, + 'name' => $v, + ]; + } + + } else { + return json(['code'=>-1,'msg'=>'还没有数据']); + } + return json($res); + + } + + return View::fetch(); + } + + public function backup() + { + //halt(app()->getRootPath()); + //自行判断文件夹 + $backupdir = '../data'; + if (isset($_POST['backdir']) && $_POST['backdir'] != '') { + $backupdir = $_POST['backdir']; + } else { + $backupdir = app()->getRootPath() .'data/'. date('Ymdhis'); + //halt($backupdir); + } + + if (!is_dir($backupdir)) { + mkdir($backupdir, 0777, true); + } + + $backup = BackupFactory::instance('mysql', "$this->hostname:$this->hostport", $this->database, $this->username, $this->password); + $result = $backup->setbackdir($backupdir) + ->setvolsize(0.2) + ->setonlystructure(false) //设置是否只备份目录结构 + ->settablelist() //设置要备份的表, 默认全部表 + ->setstructuretable() + ->ajaxbackup($_POST); + + echo json_encode($result); + } + + + //下载 + public function down() + { + $id = input('id'); + var_dump($id); + } + + //删除备份文件夹 + public function delete() + { + $name = input('name'); + //var_dump($name); + $dir = app()->getRootPath() .'data/'.$name; + + $res = Files::delDir($dir); + + if($res){ + return json(['code'=>0,'msg'=>'删除成功']); + } else { + return json(['code'=>-1,'msg'=>'删除失败']); + } + } + +} diff --git a/app/admin/middleware.php b/app/admin/middleware.php index bdf6ca9..9ad00c9 100644 --- a/app/admin/middleware.php +++ b/app/admin/middleware.php @@ -3,4 +3,5 @@ return [ app\middleware\Auth::class, //'logedcheck' => \app\middleware\logedCheck::class, + app\middleware\AdminLoginCookie::class, ]; \ No newline at end of file diff --git a/app/admin/model/Admin.php b/app/admin/model/Admin.php index 98c103e..bf0892e 100644 --- a/app/admin/model/Admin.php +++ b/app/admin/model/Admin.php @@ -5,6 +5,9 @@ namespace app\admin\model; use think\Model; use think\facade\Db; use think\facade\Session; +use app\oil\model\Station; +use think\facade\Cookie; +use think\facade\Config; use think\model\concern\SoftDelete; class Admin extends Model @@ -21,6 +24,11 @@ class Admin extends Model return $this->belongsTo('AuthGroup','auth_group_id','id'); } */ + //管理员关联站点 + public function station() + { + return $this->belongsTo(Station::class); + } //远程一对多管理员关联角色 public function adminGroup() @@ -30,12 +38,12 @@ class Admin extends Model //管理员关联角色分配表 public function authGroupAccess() { - return $this->hasMany('AuthGroupAccess','uid','id'); + return $this->hasMany(AuthGroupAccess::class,'uid'); } //登陆校验 public function login($data) - { + { //查询用户 $admin = Db::name('admin')->where('username',$data['username'])->where('delete_time',0)->find(); @@ -51,13 +59,20 @@ class Admin extends Model //将用户数据写入Session Session::set('admin_id',$admin['id']); Session::set('admin_name',$admin['username']); + + if(isset($data['remember'])){ + $salt = Config::get('taoler.salt'); + //加密auth存入cookie + $auth = md5($admin['username'].$salt).":".$admin['id']; + Cookie::set('adminAuth',$auth,604800); + } Db::name('admin')->where('id',$admin['id'])->update( [ 'last_login_time' => time(), 'last_login_ip' => request()->ip(), ] - ); + ); //用户名密码正确返回1 return 1; diff --git a/app/admin/view/database/index.html b/app/admin/view/database/index.html new file mode 100644 index 0000000..5f19b49 --- /dev/null +++ b/app/admin/view/database/index.html @@ -0,0 +1,218 @@ +{extend name="public:base" /} + +{block name="body"} +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+
+ +{/block} + +{block name="js"} + +{/block} diff --git a/app/admin/view/login/login.html b/app/admin/view/login/login.html index f7ed4b8..b90d1fa 100644 --- a/app/admin/view/login/login.html +++ b/app/admin/view/login/login.html @@ -1,14 +1,14 @@ {extend name="public/base" /} -{block name="title"}登入 - TaoLer{/block} +{block name="title"}登入 - TaoilSys加油站管理系统{/block} {block name="css"}{/block} {block name="body"}