diff --git a/app/Common/function.php b/app/Common/function.php index a025759..13f9610 100644 --- a/app/Common/function.php +++ b/app/Common/function.php @@ -622,8 +622,19 @@ function imgmatch($url) function get_category($modelname, $parent_id=0, $pad=0) { $arr = array(); + + $temp = \DB::table($modelname)->where('pid', $parent_id); + if(get_table_columns($modelname, 'listorder')) + { + $temp = $temp->orderBy('listorder', 'asc'); + } + else + { + $temp = $temp->orderBy('id', 'asc'); + } + + $temp = $temp->get(); - $temp = \DB::table($modelname)->where('pid', $parent_id)->orderBy('id', 'asc')->get(); $cats = object_to_array($temp); if($cats) @@ -1032,6 +1043,26 @@ function success_jump($msg='', $url='', $time=1) } } +//获取表所有字段 +function get_table_columns($table, $field='') +{ + $res = \Illuminate\Support\Facades\Schema::getColumnListing($table); + + if($field != '') + { + //判断字段是否在表里面 + if(in_array($field, $res)) + { + return true; + } + else + { + return false; + } + } + + return $res; +} diff --git a/app/Http/Controllers/Admin/CommonController.php b/app/Http/Controllers/Admin/CommonController.php index 08fb1e6..6ffd75f 100644 --- a/app/Http/Controllers/Admin/CommonController.php +++ b/app/Http/Controllers/Admin/CommonController.php @@ -12,6 +12,7 @@ class CommonController extends Controller { parent::__construct(); + //判断是否登录 if(isset($_SESSION['admin_user_info'])) { $this->user_info = $_SESSION['admin_user_info']; @@ -20,6 +21,27 @@ class CommonController extends Controller { header("Location:".route('page404')); exit(); + } + + //判断是否拥有权限 + if($_SESSION['admin_user_info']['role_id'] <> 1) + { + $uncheck = array('admin_jump','admin','admin_index_upconfig','admin_index_upcache','admin_welcome'); + + if(in_array(\Route::currentRouteName(), $uncheck)) + { + + } + else + { + $menu_id = DB::table('menu')->where('action', \Route::currentRouteName())->value('id'); + $check = DB::table('access')->where(['role_id' => $_SESSION['admin_user_info']['role_id'], 'menu_id' => $menu_id])->first(); + + if(!$check) + { + error_jump('你没有权限访问,请联系管理员!', route('admin')); + } + } } } diff --git a/app/Http/Controllers/Admin/LoginController.php b/app/Http/Controllers/Admin/LoginController.php index 16a4d1d..0e4744d 100644 --- a/app/Http/Controllers/Admin/LoginController.php +++ b/app/Http/Controllers/Admin/LoginController.php @@ -42,7 +42,7 @@ class LoginController extends BaseController if($User) { $admin_user_info = $User->toArray(); - $admin_user_info['rolename'] = $User->userrole->rolename; + $admin_user_info['rolename'] = $User->userrole->name; $_SESSION['admin_user_info'] = $admin_user_info; diff --git a/app/Http/Model/Menu.php b/app/Http/Model/Menu.php index 15e3547..c1fb7c4 100644 --- a/app/Http/Model/Menu.php +++ b/app/Http/Model/Menu.php @@ -9,24 +9,6 @@ class Menu extends Model public $timestamps = false; protected $guarded = []; //$guarded包含你不想被赋值的字段数组。 - /** - * 文件上传 - * @param $field - * @return string - */ - public function uploadImg($field) - { - if (Request::hasFile($field)) { - $pic = Request::file($field); - if ($pic->isValid()) { - $newName = md5(rand(1, 1000) . $pic->getClientOriginalName()) . "." . $pic->getClientOriginalExtension(); - $pic->move('uploads', $newName); - return $newName; - } - } - return ''; - } - //获取后台管理员所具有权限的菜单列表 public static function getPermissionsMenu($role_id, $pid=0, $pad=0) { diff --git a/public/css/admin.css b/public/css/admin.css index bd688f3..fded5e0 100644 --- a/public/css/admin.css +++ b/public/css/admin.css @@ -1,7 +1,7 @@ .mauto{margin-left:auto;margin-right:auto;} .blog-masthead{background-color:#01aef0;} -.blog-nav-item{position:relative;display:inline-block;padding:15px 20px;font-weight:500;color:#fff;font-size:16px;} +.blog-nav-item{position:relative;display:inline-block;padding:12px 20px;font-weight:500;color:#fff;font-size:16px;} .blog-nav-item:hover,.blog-nav-item:focus{background-color:#00a9e9;color:#fff;text-decoration:none;} .blog-nav .active{background-color:#00a9e9;color:#fff;} .blog-nav .active:after{position:absolute;bottom:0;left:50%;width:0;height:0;margin-left:-5px;vertical-align:middle;content:" ";border-right:5px solid transparent;border-bottom:5px solid;border-left:5px solid transparent;} diff --git a/resources/views/admin/index/index.blade.php b/resources/views/admin/index/index.blade.php index 56c26ac..952a982 100644 --- a/resources/views/admin/index/index.blade.php +++ b/resources/views/admin/index/index.blade.php @@ -2,7 +2,7 @@ -
+ diff --git a/resources/views/admin/menu/add.blade.php b/resources/views/admin/menu/add.blade.php index 4192035..7aab469 100644 --- a/resources/views/admin/menu/add.blade.php +++ b/resources/views/admin/menu/add.blade.php @@ -35,7 +35,7 @@