Przeglądaj źródła

不需要权限验证

胖虎 3 lat temu
rodzic
commit
33df1928e0

+ 0 - 181
app/Http/Controllers/AdminApi/RoleController.php

@@ -1,181 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\AdminApi;
-
-use App\Models\SysModels\Menu;
-use App\Models\UserModels\Role;
-use App\Models\UserModels\User;
-use App\Http\Controllers\AdminController;
-use App\Servers\Common\MenuServer;
-use App\Servers\Common\RedisDataServer;
-
-class RoleController extends AdminController
-{
-
-    /**
-     * 后台账号列表
-     * @return \Illuminate\Http\JsonResponse
-     */
-    function getList(){
-        $status = request()->input('status', 0);//是否通过 1启用 2停用
-        $search = request()->input('search', '');//搜索的内容
-        $start = request()->input('start', '');//获取开始时间
-        $end = request()->input('end', '');//获取结束时间
-
-        //获取店铺角色列表
-        $where = [['is_del',0]];
-        if(in_array($status,[1,2])) $where[] = ['status','=',$status];
-
-        if ($search) $where[] = ['name', 'like', "%$search%"];
-        if ($start) $where[] = ['created_at', '>=', $start . ' 00:00:00'];
-        if ($end) $where[] = ['created_at', '<=', $end . ' 23:59:59'];
-
-        $list = Role::where($where)
-            ->select(['id','name','status','created_at'])
-            ->orderBy('created_at','desc')
-            ->paginate(10);
-        foreach ($list as $value){
-            $value['count'] = User::where('role_id',$value['id'])->where('is_del',0)->count();
-        }
-        return $this->apiResponseSuccess('获取信息成功', [
-            'list' => $list->items(),
-            'total' => $list->total(),
-            'limit' => 10
-        ]);
-    }
-
-    /**
-     * 新增&编辑店铺角色
-     * @return \Illuminate\Http\JsonResponse
-     */
-    function saveRole(){
-        $id = request()->input('id','');//记录id
-        $name = request()->input('name','');//名称
-        $status = request()->input('status',1);//状态1启用 2停用
-        $permission_ids = request()->input('ids','');//权限节点id
-
-        if (empty($name))  return $this->apiResponseError( '角色名称必填');
-        if (empty($permission_ids))  return $this->apiResponseError( '请选择权限节点');
-        if(!in_array($status,[1,2])) return $this->apiResponseError( '状态错误');
-
-        if(is_array($permission_ids)){
-            $permission_ids = implode(',',$permission_ids);
-        }
-        $data = compact('name','status','permission_ids');
-        if(empty($id)){
-
-            $count = Role::where('name', '=', $name)->where('is_del',0)->count();
-            if ($count > 0 ) {
-                return $this->apiResponseError( '该角色已存在');
-            }
-
-            $res = Role::create($data);
-        }else{
-            if (empty($id))  return $this->apiResponseError( '缺少必要参数');
-
-            $info = Role::where('id',$id)->first();
-            if(!$info) return $this->apiResponseError( '记录不存在');
-
-            $count = Role::where('name', '=', $name)->where('id', '<>', $id)->where('is_del',0)->count();
-            if ($count > 0 ) {
-                return $this->apiResponseError( '该角色已存在');
-            }
-            $res = $info->update($data);
-            //更新该角色redis节点信息
-            RedisDataServer::creatServer()->delData('gw_role_ids_' . $id);
-        }
-        if ($res) {
-            return $this->apiResponseSuccess('成功');
-        } else {
-            return $this->apiResponseError('失败');
-        }
-    }
-
-    /**
-     * 获取记录详情
-     * @return \Illuminate\Http\JsonResponse
-     */
-    function getInfo()
-    {
-        $id = request()->input('id', '');//获取需要查询的记录id
-        if (empty($id)) return $this->apiResponseError('缺少必要参数');
-
-        //查询数据
-        $where = [['id', $id], ['is_del',0]];
-        $info = Role::where($where)->select(['id','name','status'])->first();
-
-        if (empty($info)) return $this->apiResponseError('没有找到该记录');
-        return $this->apiResponseSuccess('获取成功', $info);
-    }
-
-    /**
-     * 获取后台菜单
-     * @return \Illuminate\Http\JsonResponse
-     */
-    function getMenuList(){
-        $role_id = request()->input('role_id','');
-
-        $list = MenuServer::creatServer()->getMenuList($role_id);
-
-        return $this->apiResponseSuccess('获取列表成功', [
-            'items' => $list,
-        ]);
-    }
-
-    /**
-     * 获取导航栏目
-     * @return \Illuminate\Http\JsonResponse
-     */
-    function getSideMenu(){
-        $role_id = $this->getRoleId();//获取登录物流公司id
-        //获取该角色的权限节点
-        $permission_ids =Role::where('id', $role_id)->value('permission_ids');
-        $url_ids = explode(',', $permission_ids);
-
-        //获取导航栏数据
-
-        $data = Menu::where([['status',1], ['is_del',0]])
-            ->where(function ($q) use ($role_id,$url_ids){
-                if($role_id){
-                    $q->whereIn('id',$url_ids);
-                }
-            })
-            ->where(function ($q){
-
-                $q->orWhere('level',1);
-                $q->orWhere('level',2);
-            })
-            ->orderBy('id','asc')
-            ->pluck('id')
-            ->toArray();
-
-        return $this->apiResponseSuccess('获取信息成功', $data);
-    }
-
-    /**
-     * 删除(批量)角色
-     * @return \Illuminate\Http\JsonResponse
-     */
-    function destroys(){
-        $ids = request()->input('ids','');//获取需要删除的id
-        if(empty($ids)) return $this->apiResponseError('请选择需要删除的数据');
-        //数据条件
-        if(!is_array($ids)){
-            $ids = array_filter(explode(',', $ids));
-        }
-        foreach ($ids as $value){
-            //检查每一个角色下面是否有使用
-            $where = [['is_del',0], ['role_id',$value]];
-            $count = User::where($where)->count();
-            if($count > 0){
-                return $this->apiResponseError('所选角色还有管理员使用,不能删除');
-            }
-        }
-        $res = Role::whereIn('id',$ids)->update(['is_del' => 1,'status'=>2]);
-        if ($res) {
-            return $this->apiResponseSuccess('删除成功');
-        } else {
-            return $this->apiResponseError('删除失败');
-        }
-    }
-}

+ 2 - 18
app/Http/Controllers/AdminApi/UserController.php

@@ -2,7 +2,6 @@
 
 namespace App\Http\Controllers\AdminApi;
 
-use App\Models\UserModels\Role;
 use App\Models\UserModels\User;
 use App\Http\Controllers\AdminController;
 use App\Servers\Common\CommonServer;
@@ -38,13 +37,6 @@ class UserController extends AdminController
             ->select(['id','name','phone','status','roles_id','created_at'])
             ->paginate(10);
 
-        foreach ($list as $value){
-            if($value['id'] == 1){
-                $value['roles_name'] = '超级管理员';
-            }else{
-                $value['roles_name'] = Role::where('id',$value['roles_id'])->where('is_del',0)->value('name');
-            }
-        }
         return $this->apiResponseSuccess('获取信息成功', [
             'list' => $list->items(),
             'total' => $list->total(),
@@ -67,11 +59,6 @@ class UserController extends AdminController
 
         if (empty($info)) return $this->apiResponseError('没有找到该记录');
 
-        if($info['id'] == 1){
-            $info['roles_name'] = '超级管理员';
-        }else{
-            $info['roles_name'] = Role::where('id',$info['roles_id'])->where('is_del',0)->value('name');
-        }
         return $this->apiResponseSuccess('获取成功', $info);
     }
 
@@ -148,7 +135,7 @@ class UserController extends AdminController
             //获取当前操作用户类型,不是超级管理员不可以编辑超级管理
             $admin_id = request()->admin_user['id'];
             if($admin_id != 1 && $info['id'] == 1){
-                return $this->apiResponseError( '您不可以编辑超级管理员');
+                return $this->apiResponseError( '您不可以编辑该账户');
             }
 
             $update['phone'] = $phone;
@@ -180,7 +167,7 @@ class UserController extends AdminController
             return $this->apiResponseError('没有找到该记录');
         }
         if($info['id'] == 1){
-            return $this->apiResponseError('超级管理员不能关闭');
+            return $this->apiResponseError('该账户不能关闭');
         }
 
         $res = $info->update(['status'=>$status]);
@@ -235,9 +222,6 @@ class UserController extends AdminController
 
         //数据条件
         if(!is_array($ids)) return $this->apiResponseError('数据格式错误');
-        if(in_array(1,$ids)){
-            return $this->apiResponseError('超级管理员不能删除');
-        }
 
         $res = User::whereIn('id',$ids)->where('id','<>',1)->update(['is_del' => 1,'status'=>2]);
         if ($res) {

+ 0 - 10
app/Http/Middleware/AdminApiAuthMiddleware.php

@@ -3,7 +3,6 @@
 namespace App\Http\Middleware;
 
 use App\Models\UserModels\User;
-use App\Servers\Common\PermissionServer;
 use App\Servers\Common\RedisDataServer;
 use Closure;
 
@@ -64,15 +63,6 @@ class AdminApiAuthMiddleware
                 'data' => []
             ]);
         }
-        //进行路由验证
-        $ret = PermissionServer::verifyAuth($user['roles_id'], $clientRoute);
-        if (empty($ret) && $user['id'] != 1) {
-            return response()->json([
-                'msg' => '暂无权限',
-                'code' => 402,
-                'data' => []
-            ]);
-        }
 
         $request->admin_user = $user;
 

+ 0 - 49
app/Models/UserModels/Role.php

@@ -1,49 +0,0 @@
-<?php
-
-namespace App\Models\UserModels;
-
-use Illuminate\Database\Eloquent\Model;
-use App\Models\Traits\Timestamp;
-
-class Role extends Model
-{
-    use Timestamp;
-
-    /**
-     * 表名。
-     *
-     * @var string
-     */
-    protected $table = 'roles';
-
-    /**
-     * 与表关联的主键。
-     *
-     * @var string
-     */
-    protected $primaryKey = 'id';
-
-    /**
-     * 是否主动维护时间戳
-     *
-     * @var bool
-     */
-    public $timestamps = true;
-
-    /**
-     * 不能被批量赋值的属性
-     *
-     * @var array
-     */
-    protected $guarded = ['id', 'updated_at', 'created_at'];
-
-    /**
-     * 时间格式化
-     * @var string[]
-     */
-    protected $casts = [
-        'created_at' => 'datetime:Y-m-d H:i:s',
-        'updated_at' => 'datetime:Y-m-d H:i:s'
-    ];
-
-}

+ 0 - 43
app/Servers/Common/PermissionServer.php

@@ -1,43 +0,0 @@
-<?php
-
-
-namespace App\Servers\Common;
-
-
-
-use App\Models\SysModels\Menu;
-
-/**
- * 权限验证
- */
-class PermissionServer
-{
-
-    /**
-     * 后台权限检查
-     * @param $role_id
-     * @param $clientRoute
-     * @return bool
-     */
-    public static function verifyAuth($role_id, $clientRoute){
-        //跳过权限认证的路由
-        $url_list = [
-            'common.sts',
-        ];
-        if (in_array($clientRoute, $url_list) || $role_id == 0) {
-            return true;
-        }
-
-        $where = [['url_name',$clientRoute], ['status',1], ['is_del',0]];
-        $client_id = Menu::where($where)->value('id');
-        if (empty($client_id)) {
-            return false;
-        }
-        //获取该角色的权限节点
-        $url_ids = MenuServer::creatServer()->getRole($role_id);
-        if (empty($url_ids) || !in_array($client_id, $url_ids)) {
-            return false;
-        }
-        return true;
-    }
-}