StoreAuth.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace mall\middleware;
  10. use Closure;
  11. use mall\basic\Users;
  12. use think\facade\Db;
  13. use think\Request;
  14. use think\Response;
  15. use mall\library\tools\jwt\Token;
  16. class StoreAuth {
  17. /**
  18. * @param Request $request
  19. * @param Closure $next
  20. * @return Response
  21. */
  22. public function handle(Request $request, Closure $next){
  23. try{
  24. $token = Token::check();
  25. $result = Token::parse($token,"id");
  26. if(!is_array($result)){
  27. throw new \Exception("您还未登录,请先登录",401);
  28. }
  29. Users::info($result["value"]);
  30. $row = Db::name("store_users")->where(["user_id"=>$result["value"],"status"=>0])->find();
  31. if(empty($row)){
  32. throw new \Exception("您无权限访问该页面",865);
  33. }
  34. }catch(\Exception $ex){
  35. return json(["info"=>$ex->getMessage(),"status"=>"-1001"]);
  36. }
  37. return $next($request);
  38. }
  39. }