<?php namespace app\admin\controller; use think\Db; use think\Validate; use think\Controller; use think\facade\Session; use app\admin\model\OrderModel; class Order extends Controller { public function initialize() { $event = controller('login','controller'); $event->check(); } //用戶登錄 public function index() { if($this->request->isAjax()){ $account = $this->request->param('account'); $password = $this->request->param('password'); $admin = Db::table('admin')->where(['account'=>$account, 'password'=>$password])->find(); if($admin['id']){ Session::set('admin',$admin); //判斷是否應該跳轉到上次url if(!empty(Session::get('redirect_url'))){ $url = Session::get('redirect_url'); Session::delete('redirect_url'); }else{ $url = url('index/index'); } exit( json_encode(['check'=>1, 'msg'=>'登錄成功!', 'url'=>$url]) ); }else{ exit( json_encode(['check'=>0, 'msg'=>'賬號或密碼錯誤']) ); } } if(is_numeric(Session::get('admin.id'))){ $this->redirect('index/index'); } return $this->fetch(); } public function check()//檢查登錄 { if(!is_numeric(Session::get('admin.id'))){ if($this->request->isAjax()){ exit( json_encode(['check'=>2, 'url'=>url('login/index')]) ); }else{ redirect()->remember(); $this->redirect('login/index'); } } } public function out() { Session::clear(); $this->redirect('index/index'); } }