Login.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Http\Middleware\Manager;
  3. use App\Facades\Servers\Encrypts\AccessToken;
  4. use Closure;
  5. use Illuminate\Http\Request;
  6. class Login
  7. {
  8. // 无需验证的路径
  9. protected $except = [
  10. 'manager/process/sub_notice',
  11. 'manager/login/index',
  12. 'manager/login/mobile',
  13. 'manager/login/email',
  14. 'manager/login/send_code',
  15. 'manager/login/mobile_code',
  16. 'manager/citys/list',
  17. 'manager/login/wechat',
  18. 'manager/citys/list_zoning',
  19. 'manager/statistics/product_surveillance/push_data_notice',
  20. 'manager/process/low_price_goods/data_cleaning',
  21. 'manager/process/Collect_data/low_price_product_collect_data',
  22. 'manager/process/Collect_data/update_collect_data'
  23. ];
  24. //默认配置
  25. protected $_config = [
  26. 'auth_on' => true, // 认证开关
  27. 'auth_type' => 1, // 认证方式,1为实时认证;2为登录认证。
  28. 'auth_group' => 'auth_group', // 用户组数据表名
  29. 'auth_group_access' => 'auth_group_access', // 用户-用户组关系表
  30. 'auth_rule' => 'auth_rule' // 权限规则表
  31. ];
  32. /**
  33. * $prefix表前缀
  34. */
  35. public function __construct()
  36. {
  37. // 判断配置
  38. if (config('AUTH_CONFIG')) {
  39. //可设置配置项 AUTH_CONFIG, 此配置项为数组。
  40. $this->_config = array_merge($this->_config, config('AUTH_CONFIG'));
  41. }
  42. }
  43. /**
  44. * Handle an incoming request.
  45. *
  46. * @param \Illuminate\Http\Request $request
  47. * @param \Closure $next
  48. * @return mixed
  49. */
  50. public function handle(Request $request, Closure $next)
  51. {
  52. // 当前路径
  53. $path = ltrim($request->getPathInfo(), '/');
  54. // 判断是否需要验证登录
  55. if (!in_array($path, $this->except)) {
  56. // 获取登录结果
  57. $token = (string) $request->input('access_token_manager', '');
  58. // 解码
  59. $userInfo = AccessToken::decode($token);
  60. // 判断登录时效
  61. if (isset($userInfo['error'])) return json_send(['code' => 'no_login', 'msg' => '请您登录', 'data' => $userInfo['error']]);
  62. if ($userInfo['type'] != 'manager' || $userInfo['expire'] < time()) return json_send(['code' => 'no_login', 'msg' => '请您登录', 'data' => '登录失效']);
  63. // 获取用户信息
  64. if($userInfo['is_admin'] == 0){
  65. $EmployeeModel = new \App\Models\Manager\Personnel\Employee();
  66. $Employee = $EmployeeModel->where('id', $userInfo['uid'])->first();
  67. if (!$Employee) return json_send(['code' => 'no_login', 'msg' => '记录不存在','data'=>'']);
  68. if ($Employee->status == 1) return json_send(['code' => 'no_login', 'msg' => '账号已被禁用','data'=>'']);
  69. }
  70. // 是否是超管
  71. $userInfo['is_super'] = is_super($userInfo['uid'],$userInfo['is_admin'], 'manager') ? 1 : 0;
  72. // 追加入
  73. $request['access_token'] = $userInfo;
  74. }
  75. // 返回下一个闭包
  76. return $next($request);
  77. }
  78. }